Dear all,
I having a problem with the twi, EEPROM AT24C256. When testing using AT91SAM7S-EK
development board, read and write function work properly, but when I implementing the code
to my board, it seem give me bug. After I check the routine, I found that the write
function keep looping in :
while (!(status & AT91C_TWI_TXCOMP)){
}
What might be the cause for this looping happening, while using AT91SAM7S-EK seem
working fine ?
Any one having the same situation ?
The following is the read byte EEPROM function :
int AT91F_TWI_WriteByte(const AT91PS_TWI pTwi ,int mode, int int_address, char
*data2send, int nb)
{
unsigned int status,counter=0,error=0;
// Set TWI Internal Address Register
if ((mode & AT91C_TWI_IADRSZ) != 0) pTwi->TWI_IADR = int_address;
// Set the TWI Master Mode Register
pTwi->TWI_MMR = mode & ~AT91C_TWI_MREAD;
if(nb <2){
pTwi->TWI_CR = AT91C_TWI_START | AT91C_TWI_MSEN | AT91C_TWI_STOP;
pTwi->TWI_THR = *data2send;
}
else
{
// Set the TWI Master Mode Register
for(counter=0;counter
pTwi->TWI_CR = AT91C_TWI_START | AT91C_TWI_MSEN;
if (counter == (nb - 1)) pTwi->TWI_CR = AT91C_TWI_STOP;
status = pTwi->TWI_SR;
if ((status & ERROR) == ERROR) error++;
while (!(status & AT91C_TWI_TXRDY)){
// AT91F_DBGU_Printk("error1\n\r");
status = pTwi->TWI_SR;
if ((status & ERROR) == ERROR)
{
error++;
// AT91F_DBGU_Printk("error2\n\r");
}
}
pTwi->TWI_THR = *(data2send+counter);
}
}
status = pTwi->TWI_SR;
if ((status & ERROR) == ERROR) error++;
while (!(status & AT91C_TWI_TXCOMP)){
// AT91F_DBGU_Printk("error3\n\r");
status = pTwi->TWI_SR;
if ((status & ERROR) == ERROR) {
error++;
// AT91F_DBGU_Printk("error4\n\r");
}
}
return error;
}
Thanks
fayes
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.

(You need to be a member of AT91SAM -- send a blank email to AT91SAM-subscribe@yahoogroups.com )