View previous topic :: View next topic |
Author |
Message |
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
If an i2c_write() or i2c_read() fails? |
Posted: Mon Dec 26, 2005 3:52 pm |
|
|
If i'm in the middle of a sequence of i2c transactions (i.e. my initial i2c_start() went thru okay, etc.), and all of a sudden, a write() fails to get an ack, then what should I do?
1. issue a stop(), and retry the initial start() all over again from the first stage?
OR
2. Retry the failed write() a couple of times? (Eventually it ought to work?)
I've got an application out in the field where i'm scared that a "frozen" i2c bus will have bigger consequences. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Mon Dec 26, 2005 8:30 pm |
|
|
I had an experience just like Mike had described: once ever so often the I2C transaction would start happily but then fail in the middle. It turned out that I was using the I2C bus both in the main() and in the interrupt. Yes, I know that serial communication in the interrupt is a no-no, but that was 400kbps I2C bus and I was making 1-byte writes to a DAC. Oddly enough, in the beginning the system was wprking just fine, because the main() was de-facto synchronized with the interrupt. But then I had changed something, and I started to get the bug i have described initially. So, the following thing was happening:
(1) main() would successfully initialize the I2C transaction.
(2) interrupt would occur, and it would re-initialize the I2C also successfully.
(3) interrupt would finish the transaction successfully. The bus is now stopped.
(4) after the interrupt main() would try to carry on with its transaction and fail.
Moral (at least for myself): All of the I2C transactions should be either in the main() or in the interrupt of the same priority. |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Mon Dec 26, 2005 9:57 pm |
|
|
Thanks PCM, i'll be reviewing those docs carefully.
And Kender, when you use 400kbps rates, what resistor values do you use?
Thanks,
Mike |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Mon Dec 26, 2005 10:17 pm |
|
|
MikeValencia wrote: | And Kender, when you use 400kbps rates, what resistor values do you use? |
I used 2.2k pullups. I was a +5V system. |
|
|
MikeValencia
Joined: 04 Aug 2004 Posts: 238 Location: Chicago
|
|
Posted: Thu Dec 29, 2005 7:57 am |
|
|
I stumbled across the LTC4304 by Linear Technology, which is an IC that can restore stuck i2c buses if the SDA or SCL is stuck for more than 30ms. It will clock SCL for a maximum of 16 times.
This is very similiar to PCM's first link above on how to reset an i2c bus. Looks like i have to keep an "i2c watchdog timer" to wait for the completion of a write or read, then manually clock SCL at most 9 times if the timer trips. If i'm using hardware i2c (MSSP), then i guess i'll have to disable the mssp temporarily and bitbang the pins. This is a much cheaper method than using the Linear IC. |
|
|
|