0
\$\begingroup\$

I use Twi module of AVR Atmega168 to talk to DS1307.

Twi works on the interrupt mode.

It works fine for a few hours and then stops, hopefully losing Twi interrupts further.

Is there any way to fix/resolve/work around this issue.

Any practical tips would be of great help.

\$\endgroup\$
8
  • \$\begingroup\$ Can you please add the source code? It sounds like it locks up after one unsuccessful transfer. \$\endgroup\$
    – venny
    Commented Sep 9, 2014 at 9:04
  • \$\begingroup\$ @venny, I would add source code later. Can you please elaborate on what you said? \$\endgroup\$
    – Babu James
    Commented Sep 9, 2014 at 9:56
  • \$\begingroup\$ I meant that the software probably can not cope with accidentally corrupted frames and recover after the error is gone. \$\endgroup\$
    – venny
    Commented Sep 9, 2014 at 10:21
  • \$\begingroup\$ @venny: So how can I recover from such things, disable TWI (TWEN=0) and renable? A repeated start does not seem to help. \$\endgroup\$
    – Babu James
    Commented Sep 9, 2014 at 11:03
  • \$\begingroup\$ Disabling TWI will not help, because the slave might be errorneously holding SDA low. You have to manually send clock pulses on SCL until SDA gets high. Then you can do repeated start. \$\endgroup\$
    – venny
    Commented Sep 9, 2014 at 15:14

1 Answer 1

3
\$\begingroup\$

It might already irrelevant for you but it might help others, I was experiencing the same issue, in the datasheet the following is stated:

To recover from a bus error, the TWSTO Flag must set and TWINT must be cleared by writing a logic one to it. This causes the TWI to enter the not addressed Slave mode and to clear the TWSTO Flag (no other bits in TWCR are affected). The SDA and SCL lines are released, and no STOP condition is transmitted.

So I just added the following line of code to my error handling routine (verify TWSR values):

TWCR = (1 << TWINT)|(1 << TWSTO);

And so far it works like a charm.

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.