[En-Nut-Discussion] charon II with I2C

Joel Dotreppe joel.dotreppe at infonie.be
Tue Nov 23 13:47:39 CET 2004


hello, 
I am new in the programming of the CHARONII, I test dialogue I2C (PCF857AP).  
I  write without problem, but not to read  with a pointer !?  can somebody explain me? 

 here part of my code, with < dev/twif.h >

 thank you in advance

Joel


static char buff[128];
static u_char BuffRead[8];

../..

void ProcessRequests(FILE * stream)
{
    int got, i;
    char *cp;
 u_char write[8];
     
    TwInit(0x39);
 write[0]=0x80;
 
        for (;;) {
 
        /*
         * Flush output and read a line.
         */
        fflush(stream);
        if (fgets(buff, sizeof(buff), stream) == 0) //lit une ligne venant du stream
            break;
  
        /*
         * Chop off EOL.
         */
        if ((cp = strchr(buff, '\r')) != 0)
            *cp = 0;
        if ((cp = strchr(buff, '\n')) != 0)
            *cp = 0;

        /*
         * Ignore blank lines.
         */
        got = strlen(buff);
        if (got == 0)
            continue;
   
           
  if (strncmp("write PCF8574AP", buff, got) == 0) {
      fputs("write on PCF8574AP ads :0x39 led: 8 on \r\n", stream);
     fputs("send value > ", stream); 
     write[0]=128;
     fprintf(stream,"%d\r\n",write[0]);
     write[0]=255-write[0]; // reverse state
     TwMasterTransact(0x39,&write,1,0,0,500);
     fputs("Slave State after = ", stream);
     TwMasterTransact(0x39,0,0,BuffRead,1,500);
      for( i=0 ; i < 1;i++) fprintf(stream,"%d\r\n",255-TWDR);  //with TWDR is OK ! > value is 128
   continue;
  }
        
  
  if (strncmp("read PCF8574AP ", buff, got) == 0) {
      fputs("test read PCF8574AP  ads : 0x39  \r\n", stream);
      fputs("Read Slave State  = ", stream); 
      for( i=0 ; i < TwMasterTransact(0x39,0,0,BuffRead,8,500) +1;i++) fprintf(stream,"%d\t",255-BuffRead[i]); // !! value is 0 !!
      continue;
        }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.egnite.de/pipermail/en-nut-discussion/attachments/20041123/18eece54/attachment.html>


More information about the En-Nut-Discussion mailing list