6 years, 8 months ago.

Interrupt based I2C communication

Currently, the I2C implementation ( as given in the handbook) for communication between 2 micro controllers is based on polling. i,e, the master can get stuck in a loop if slave function is not ready. In other micro controllers, (such as TiVa by Texas Instruments), I2C is interrupt based. i.e, the slave get auto activated when master wants to communicate. Is there any way to make my FRDM KL46Z I2C work based on interrupts, without using external gpio's?

I am currently building a system with many threads , so a polling based system is not feasible. Also it is found to get stuck at times due to possible synchronisation problems.

2 Answers

6 years, 8 months ago.

I've got the same need, for the Nucleo Board. I would like my Nucleo act as master on one i2c network, and as slave on another one. As master requests can take a while, the best would be for the I2CSlave to interrupt the main program.

How can the I2CSlave interrupt the main program? I can think of only two ways : -> Use a ticker or RtosTimer or something and call the I2CSlave function periodically. But this means, the master has to be in while loop unnecessarily.

-> Use a gpio based hardware interrupt from master to slave and put thr whole I2CSlave in the ISR.

Is there any other way for interrupting the main program? Thanks

posted by green rosh 10 Jan 2015
6 years, 8 months ago.

i2c interrupt function does not appear to be implemented in the Mbed API's. There is something here that may help:


May be easier to hardwire an interrupt to a GPIO pin.

Using Ticker interrupt would slow the your program down and will need constant synchronising in case of drift between master and slave unless they share a common clock source. The other problem with Ticker interrupt is that using printf to a display for instance, this data stream cannot be interrupted so you would need to time the Tickers round this.