Forum: ARM programming with GCC/GNU tools i2c driver on AT91SAM7S-EK (using FreeRTOS)

von Gabriele B. (g4b0)

Rate this post
0 useful
not useful
Hi all,

I'm trying to use a eeprom with my evaluation board (the one in the
so I added the code from the atmel site (AT91-AN01: Using the Two-wire
interface (TWI) in Master Mode on AT91SAM Microcontrollers) to my
version of FreeRTOS.

In order to make things working, I have added lib_AT91SAM7S256.h to my
project. This header is a set of inline functions useful to initialize
use the processor, without directly use the processor register.

It does compile, but the problem now is that the example code downloaded
from Atmel site stops working during the execution of
AT91F_AT24C_WritePage(). It loop forever just here (into the while):


 /* Send the buffer to the page */
for ( Count=0; Count < NumOfBytes ;Count++ )
____AT91C_BASE_TWI->TWI_THR = *Buffer++;

____/* Wait until TXRDY is high to transmit the next data */
____status = AT91C_BASE_TWI->TWI_SR;
____while (!(status & AT91C_TWI_TXRDY))  <---- it loops here
____status = AT91C_BASE_TWI->TWI_SR;


It seems that AT91C_TWI_TXRDY (or AT91C_BASE_TWI->TWI_SR) never becomes
0, but I can't wonder whi..

Anybody known the solution?

Thanks a lot

von Clifford S. (clifford)

Rate this post
0 useful
not useful
Gabriele Brosulo wrote:
> It seems that AT91C_TWI_TXRDY (or AT91C_BASE_TWI->TWI_SR) never becomes
> 0, but I can't wonder whi..

Actually the while loop continues while the TXRDY bit is zero. It is
waiting for it to become one not zero. (as per flowchart on page 14 of
the app. note). However beyond helping you understand the meaning of the
code it is not possible to say what the problem is from that snippet.
You have called AT91F_TWI_Open() prior to this I presume?


von Marcelo adrian L. (Company: sistemasembebidos.com.ar) (darukur)

Rate this post
0 useful
not useful
If you are interested I developed a few FreeRTOS driver for AT91SAM7 
(I2S, SPI, FAT, etc) if you are interested you can check it at:


Is a spanish spoken forum but the code is fully commented in english




Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.