??? 10/09/08 15:44 Read: times |
#158940 - I2C Responding to: ???'s previous message |
You have to understand that your microcontroller also has an I2C address. Although it is not possible in your case, in many cases another device on the bus can become the master and attempt to transmit to your device. The address passed to i2c_init is the address for the microcontroller.
Now, in your simplified situation you don't care what address the microcontroller has, because the EEPROM cannot become a master. So you can pass anything here. But I saw you were attempting to pass the EEPROM address, which is a misunderstanding. I think when you want to read from the EEPROM you need a repeated start condition after the last byte of the address. This is explained in the data sheet for the EEPROM. Read it carefully. My suggestion remains - try to get writes working first. Initialize the I2C module then write a collection of bytes - the I2C address followed by the memory address followed by the data (double check with the data sheet what is required). If you get no errors then the write should have been successful. Verify this with a scope on the bus. Also you need to fix the address you are writing to. 0xA0 cannot possibly be correct because the I2C module shifts the address up one bit to make room for the R/W bit. An I2C address is only seven bits, not eight. The R/W bit is not part of the address. If the address is only seven bits you cannot have the eighth bit in the address byte set. Andy |