Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: I2C strange behavior
PostPosted: Wed Jan 02, 2008 1:49 pm 
Offline

Joined: Mon Apr 09, 2007 7:46 pm
Posts: 27
Hi,

I was working with the i2c-dev driver in a at91sam9261 board and i found a strange behavior when an error occurs. The i2c-at91 driver (i2c-at91.c) founds the error and it fails leaving the i2c sub system in an useless state.

When i read bytes from some slave it seems that some byte can't be read. I'm not able to find out why this error occurs, yet. The situation is that it leaves the AT91_TWI_RXRDY bit in low state and AT91_TWI_TXCOMP bit in low state too, so the polling function (at91_poll_status()) returns with error and the read functions returns with -ETIMEDOUT but leaves the pins intact so when i try to read another byte it ends with the same error as before (connection timeout). The same occurs with the write function.

My solution was to reinitialize the hardware when the polling function fails:
Code:
static short at91_poll_status(unsigned long bit)
{
        int loop_cntr = 10000;

        do {
                udelay(10);
        } while (!(at91_twi_read(AT91_TWI_SR) & bit) && (--loop_cntr > 0));

        // lines added
        if (!loop_cntr)
                at91_twi_hwinit();
        //

        return (loop_cntr > 0);
}


It's not a polite solution, but it let me read (o write) more bytes after the error.

Have someone had a problem like that using the i2c? Is it a suitable solution?
Please, if anyone has a better solution, just tell me.

Regards,
Diego A. Fons.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: