[En-Nut-Discussion] charon II with I2C
Harald Kipp
harald.kipp at egnite.de
Tue Nov 23 14:32:45 CET 2004
Hi Joel,
As a master you need to do read/write in one go
char wrbuf[8], rdbuf[8];
TwMasterTransact(0x39, wrbuf, 1, rdbuf, 1, 0);
In your code &write is wrong too, because it is declared
as an array and write specifies the pointer to this array.
Btw. better avoid 'write' as a variable name.
Harald
At 13:47 23.11.2004 +0100, you wrote:
>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;
> }
>_______________________________________________
>En-Nut-Discussion mailing list
>En-Nut-Discussion at egnite.de
>http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
More information about the En-Nut-Discussion
mailing list