5 years, 9 months ago.

I2C not working with Function calling by Ticker/Low Power Ticker.

Hi,

I have several switch cases each for each sensor associated. I have started 1 second Low POwer Ticker, after each ticking I am going to next consecutive switch case (in idle time, code is running under while(1)). All cases initiating I2C communication to fetch data within 1 second(More than enough). But Problem here is I am not getting any data in this case. So I just removed the Low Power Ticker or Normal Ticker, and just called Switch Case function from while (1) loop forever without ticker, then all data coming perfectly ? why so? is there something associated with ticker/low power ticker that I can't do I2C when function called via tickers?

Regards, Chirag

1 Answer

5 years, 9 months ago.

Hi Chirag,

Since I2C object is not interrupt safe, so the behavior to call it in ISR is undefined.

The better way is to utilize mbed-events to achieve the periodically calling, you can refer here

https://os.mbed.com/blog/entry/Simplify-your-code-with-mbed-events/.

Please feel free to ask me any questions!

- Desmond, team Mbed