Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 6 months ago.
Sharing I2C with Thread and Ticker
I'm working on a project using the mbed-rtos library, and I need to share the I2C bus between a Thread and a Ticker. I've used a Mutex for this before, but since Ticker functions execute in interrupt context, Mutexes are not allowed. Should I use a Semaphore instead? I've always been told Semaphores should not be used to protect shared resources, but to synchronize threads...
1 Answer
10 years, 6 months ago.
I don't know if it would work, but I don't think it is supposed to work like that. The interrupt is supposed to interrupt the running code, not interrupt it and go waiting until another thread is finished.
Option A I see is using the RTOS timer functions, afaik that one should work properly with a mutex. Option B is to use a ticker, but only use that to signal another thread which does the actual I2C functions, again with mutex protection.