Does someone have ever develop a program defining an i2c communication protocol for a 8051 ? It would help me make my AT89C51ED2 communicating with another board via i2c bus. I would be interested if someone have some examples for that. jeab@free.fr Regards,
http://www.keil.com/i2c/
The best (and most) IIC appnotes including the bus specification: http://www.semiconductors.philips.com/buses/i2c/support/index.html Erik
In my case I wrote next: #define SDATA P1_6 #define SCLK P1_7 void i2c_start (void) { SDATA = 1; SCLK = 1; SDATA = 0; delay(1); SCLK = 0; } void i2c_stop (void) { SCLK = 0; SDATA = 0; delay (1); SCLK = 1; delay (1); SDATA = 1; } void i2c_put (unsigned char put_data) { unsigned char i; for (i=0;i<8;i++) { SDATA = ((put_data & 0x80)?1:0); put_data <<=1; SCLK = 1; delay (1); SCLK = 0; } i = SDATA; SCLK = 1; delay (1); SCLK = 0; } unsigned char i2c_get (void) { unsigned char i,input_data; i = SDATA; input_data = 0; for (i=0; i<8; i++) { input_data <<= 1; SCLK = 1; input_data |= SDATA; SCLK = 0; } return input_data; } Read the description as mentioned above and everthing should be OK.