Is i2c thread safe?
-
- Posts: 82
- Joined: Sun May 11, 2008 2:17 pm
- Location: Los Angeles, CA
- Contact:
Is i2c thread safe?
Anyone know if I can call I2CReadBuf and I2CWriteBuf from multiple tasks safely? I'm guessing no, cause I have a couple tasks doing i2c without mutex protection, and I'm seeing some strange i2c behavior.
Re: Is i2c thread safe?
nope - wrap that i/f with as much duct tape as you can find!
my current project has 10 i2c devices (8 different) and they are
used in a bunch(?) of tasks and it all gets along fine(?) with just
a single semaphore.
my current project has 10 i2c devices (8 different) and they are
used in a bunch(?) of tasks and it all gets along fine(?) with just
a single semaphore.
Re: Is i2c thread safe?
I agree with greenegene, you need to wrap them in a semaphore or critical section.
By the way, some of the Netburner calls use I2C such as the Real Time Clock (assuming you use this) so you need to wrap calls to this too.
I have I2C running in a number of tasks and I use an OSCritEnter and OSCritExit calls to wrap them with no issues. I also do the same with SPI as you will get the same issue here too.
Good luck
Dave...
By the way, some of the Netburner calls use I2C such as the Real Time Clock (assuming you use this) so you need to wrap calls to this too.
I have I2C running in a number of tasks and I use an OSCritEnter and OSCritExit calls to wrap them with no issues. I also do the same with SPI as you will get the same issue here too.
Good luck
Dave...
-
- Posts: 82
- Joined: Sun May 11, 2008 2:17 pm
- Location: Los Angeles, CA
- Contact:
Re: Is i2c thread safe?
Thanks, I just have a couple calls, so the duct-tape ( a.k.a. semaphore wrapping
)worked reasonably well. Good call on the RTC, I had forgotten it's over i2c as well.
