Is i2c thread safe?

Discussion to talk about software related topics only.
Post Reply
thomastaranowski
Posts: 82
Joined: Sun May 11, 2008 2:17 pm
Location: Los Angeles, CA
Contact:

Is i2c thread safe?

Post by thomastaranowski »

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.
greengene
Posts: 164
Joined: Wed May 14, 2008 11:20 am
Location: Lakeside, CA

Re: Is i2c thread safe?

Post by greengene »

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.
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: Is i2c thread safe?

Post by v8dave »

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...
thomastaranowski
Posts: 82
Joined: Sun May 11, 2008 2:17 pm
Location: Los Angeles, CA
Contact:

Re: Is i2c thread safe?

Post by thomastaranowski »

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.
Post Reply