I2C or TWI stuck

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi !

I have problem with i2c communication.

At begining of main() I initialize i2c and read RTC DS1337 and my program gets stuck. SCL and SDA are toggling.

Datasheet says (http://datasheets.maximintegrated.com/en/ds/DS1337-DS1337C.pdf):

The I2C interface is accessible whenever VCC is at a valid level. If a microcontroller connected to the DS1337 resets 
while reading from the DS1337 during an I2C read, the two could become unsynchronized. The microcontroller must 
terminate the last byte read with a Not-Acknowledge (NACK) to properly terminate the read. When the microcontroller 
resets, the DS1337 I2C interface may be placed into a known state by toggling SCL until SDA is observed to be at a 
high level. At that point the microcontroller should pull SDA low while SCL is high, generating a START condition.

Not all chips datasheets say what to do if i2c becomes unsynchronized.

What do you guys do in such situations?

Thank you !

Regards !

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd do exactly what your quoted text said.

Edit:

If it runs after first power-on, the quoted text helps.

But if it never communicates, you have some other problem.

0) Do you have pull-ups on SDA and SCL wires to supply voltage? Are they between 2kohms and 10kohms?

1) Do you initialize the TWI GPIO pins in any way before enabling the TWI module? (Note that you should not initialize them as outputs unless you know what you are doing, like trying to re-syncronize at boot).

2) Clock rate calculated correctly? At least below 400kHz?

3) Do you use the correct I2C address? It's 8-bit addresses are 0xD0 for write and 0xD1 for read, or if you insist to use 7-bit addressing without R/W bit, it's 0x68.