avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] I2C controller: INT flag a bit leaves me confused !


From: pladow
Subject: Re: [avr-chat] I2C controller: INT flag a bit leaves me confused !
Date: Mon, 2 Mar 2009 17:22:21 -0800
User-agent: Mutt/1.4.2.2i

On Tue, Mar 03, 2009 at 02:03:41AM +0100, Vincent Trouilliez wrote:
> I could imagine that the write operation to this bit triggers the
> requested action but does not actually set physically the bit to one,
> so when we read it back on the next instruction cycle, we don't
> actually see the "one" that we just wrote.
> 
> I would not mind someone confirming this scenario or telling me
> otherwise if need be, please ! ;-)

I've not used the TWI modules on Atmel parts, but I did take a look at the
datasheet to see if it as you say.  It is not unusual for registers to have
different operations on read and on write.  One example I can think of is
the SPDR register on the SPI interface.  Writing to the SPDR and reading it
back will not necessarily return what you just wrote.

However, my understand of the Mega32 datasheet indicates that the write to
TWINT is necessary only to clear any previous interrupt.  As stated in the
datasheet:

  However, it is important that the TWINT bit is set in the value written.
  Writing a one to the TWINT clears the Flag.  The TWI will not start any
  operation as long as the TWINT bit in the TWCR is set.  Immediately after
  the application has cleared TWINT, the TWI will initiate transmission of
  the START condition.

So, writing TWINT clears the interrupt and allows a start condition to occur.
However, I also note that you probably shouldn't use the TWINT bit to determine
if the TWI transfer is complete without first verifying that the START
condition was successfully transmitted.  Fruther in the datasheet:

  The application software should now examine the value of TWSR, to make sure
  that the START condition was successfully transmitted.

I think it is better to think of the TWINT bit as just that--an interrupt
bit.  Writing a 1 clears the interrupt, thus setting TWINT to 0.  But you
need more information than just TWINT to determine if a transfer occurred.

Pete LaDow
address@hidden




reply via email to

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