Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

RE: [AVR-Chat] TWI not working when optimization is on

2013-08-09 by Chuck Hackett

> From: John Samperi
> 
> At 11:50 AM 8/08/2013, you wrote:
> >Have you ever tried your "-Os" optimized code to communicate with a TWI
> >device that was not present and recover?
> 
> If your TWI code doesn't have any time out and locks waiting for a
response
> then it won't matter if the code is optimised or not I guess.
> 
> If the device doesn't respond then the code should give up and return an
error
> code of sort.

Hi John,

When the problem occurs (optimization on, no EEPROM present) what is
(apparently) happening is that the setting of the "Start Condition" fails
... it never even gets to the code that sends the slave address (immediately
after the setting of the Start Condition).

The "Send Start Condition" and "Send Slave Address" are contained in a loop
that counts "NACK" failures.  

If the EEPROM is busy with a write it will NACK (not respond) to the SLA
address.  If the EEPROM is present but busy with a write the loop will
eventually exit the loop successfully when the EEPROM finishes its write
sequence and ACKs the SLA.  

If the EEPROM is not present the loop will exit (after 200 attempts I think
at the moment) with a NACK indication which is taken to mean that the EEPROM
is not there.  I record the EEPROM as being absent and do not attempt to
communicate with it again until the next restart.

> So are you saying that if you turn optimization OFF (the code gets bigger)
the
> TWI still recovers without a device being present and if the optimization
is on
> (any of the 4 levels) then the TWI doesn't recover?

Yes ... when optimization is off and the EEPROM is not present the code
recovers normally (after 200 NACKS) and records the EEPROM as not present
without difficulty.
 
Cheers,

Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.