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.