Sign in

username:

password:



Not a member?

Search AT91SAM



Search tips

Subscribe to AT91SAM



Ads

Discussion Groups

Discussion Groups | AT91SAM ARM | Re: 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.

Re: help for TWI - Bill Knight - Feb 13 19:53:49 2008

Michael
Did you turn on the power to the TWI peripheral?
Did you configure the pins for use by the TWI peripheral?
Do you have pull-up resistors on the two TWI pins? 4.7K is a good value.

Regards
-Bill Knight
R O SoftWare
michael angelo wrote:
> 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



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


Re: help for TWI - michael angelo - Feb 14 0:59:50 2008

I found the problem, Need to pull up resistor. I wonder how come its working with the AT91SAM256-EK is working well without pull up. Anyway thanks a lot for the tips

Regards
fayes

Bill Knight wrote:
Michael
Did you turn on the power to the TWI peripheral?
Did you configure the pins for use by the TWI peripheral?
Do you have pull-up resistors on the two TWI pins? 4.7K is a good value.

Regards
-Bill Knight
R O SoftWare

michael angelo wrote:
> 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

---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.


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