2024-12-01 04:52 AM
Hello;
I'm writing a driver for a tlv493d magnetic encoder using CubeIDE. This encoder has a peculiarity where it pulls the SCL line of an i2c bus low when it has data ready to be read, at which point the MCU needs to initiate an i2c receive transaction to clear the interrupt and read the data.
Obviously we don't want the SCL clock pulses to trigger further interrupts, so I think I need to 'do something' to accommodate that. I'm struggling to understand what that 'something' is for this MCU, and how to configure it in this setup.
So far, I have configured my i2c1 bus using cubeMX, and can successfully initially communicate with the TLV (to configure registers after a reset). Then, I try to reconfigure the pin as GPIO-exti to receive the interrupt, but this seems to 'break' its connection to i2c. And I'm wondering if this - switching the pin's function back and forth between i2c and gpio-exti - is what I should ideally be doing.
My question: is it possible for a pin to be configured to both serve as the SCL line for i2c AND receive interrupts when the line is pulled low? Or am I on the right track with this switching-back-and-forth thing I'm doing?
(I understand that there's another layer here, which is whether I use HAL, LL, or registry writing to achieve this; right now I'm just trying to wrap my head around this apparent dual-functionality this pine is apparently meant to have).
thanks!
2024-12-01 05:24 AM
Simple: Do not switch, do not use HAL for EXTI. Any port line, no matter how it's configured used by peripherals, may still be used by EXTI. So, configure the I2C with HAL, then configure it for EXTI without HAL. I have no idea if LL config will work in this case, maybe yes. Then, before starting I2C transfer, deactivate EXTI interrupt or this line and restore it after I2C xfer is done.