avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] TWI atmega 16


From: Clemens Buchacher
Subject: Re: [avr-gcc-list] TWI atmega 16
Date: Wed, 9 Jun 2004 12:19:56 +0200
User-agent: Mutt/1.5.6+20040523i

On Tue, Jun 08, 2004 at 01:30:53PM -0700, Alex Norman wrote:
[...]
> but if i try to send
> start, address, data, stop... start, address, data,stop....
> the transmission doesn't work. and the MASTER's TWSR = 0xF1, which I don't see
> in the data sheet.

By ``the transmission doesn't work'' I assume you mean that the first
data byte is transmitted correctly (as by then it's still the same as in
the single-transfer case), but then it hangs.

Are you sure you don't mix up your debug information? A TWSR value of
0xF1 is not really possible if you don't set the prescaler bits. Maybe
it's 0xF8 (No relevant state information available)?

[...]
>               // send stop
>               TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN) | _BV(TWEA);
>               while( !(TWCR & _BV(TWSTO)) );

You probably want:
        while (TWCR & _BV(TWSTO))
                /* nothing */;

The TWSTO bit is _reset_ after writing a logical 1. Thus I think your
code will hang in this loop forever. That would not explain the TWSR
value of 0xF8 though.

If I read the datasheet correctly, you don't need to check that anyways.
You can safely initiate a START condition right away, because the AVR
will still complete the transmission of the STOP condition.

I've seen some code (Procyon AVRlib) which does exactly the same thing
(waiting for the TWSTO flag to be set). Does anybody know more about the
history of the TWSTO flag?

>               //while (!(TWCR & _BV(TWINT)));

You can safely remove the line above, you definitely don't need it.

[...]

Regards,
Clemens


reply via email to

[Prev in Thread] Current Thread [Next in Thread]