Using interrupts with I2CSlave on STM32L4

12 Nov 2018

I'm trying to setup a simple interrupt handler for addressed data received on I2C.

If I use InterruptIn, it seems that it is interrupting on every falling edge of the pullup SDA signal. Is there a way to check if I2C is ready to be read? I'm thinking that way, I can just say in the ISR: if it's not ready to be read, ignore it for now, else call i2cslave.receive().

Is there a better way of handling this?

27 Nov 2018

I2C (master) now supports the transfer() function, which you can pass a callback for when the transfer is complete. It doesn't look like I2CSlave supports any callbacks yet, but I imagine it will come soon. In the meantime, if you absolutely need this functionality you can take a look at what ST's HAL supports. Often these features exist on the uC, but are not supported in mbed. mbed is built using the HAL and the two can be used simultaneously. I haven't looked into it, but I bet there is an I2CSlave interrupt flag that can trigger an ISR when the device is addressed on the I2C bus. Good luck!