Sign in

username:

password:



Not a member?

Search AT91SAM



Search tips

Subscribe to AT91SAM



Ads

Discussion Groups

Discussion Groups | AT91SAM ARM | help for TWI

For users of the Atmel AT91SAM7 and AT91SAM9 ARM CPU chips. Atmel has taken a new direction by combining on chip flash and ram with the ARM CPU on a single die. This provides low cost devices for small systems using the ARM CPU. This group is to exchange information to help users get started and learn how to use the devices.

help for TWI - michael angelo - Feb 15 13:18:40 2008

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 )