2024-04-09 04:30 AM
Hello everyone!
I'm asking for your help with the following: I have a board equipped with an STM32L151 processor, with which I use an STM32 ISM330DHCX IMU via I2C. The ODR is set to 52Hz for both the gyroscope and the accelerometer, and I request an accelerometer interrupt on the INT1 pin. In the interrupt handler, I simply set a (volatile) boolean value to true, and in the main loop, I read out the sensor values. Meanwhile, messages arrive via UART at a frequency of 20Hz, to which I respond with a slight delay in milliseconds. Both UART RX and TX are set to DMA mode. In certain cases, the I2C communication fails, and I suspect that this is because while the I2C communication is in progress, a UART (or DMA) interrupt interrupts it. This is visible on the oscilloscope as well: yellow is UART communication (RS485 in this case), pink indicates data retrieval function call in the main loop, and blue is the I2C SDA pin.
What would be the appropriate procedure? Initially, it occurs to me that I should disable the UART interrupt while the I2C communication is taking place, but that doesn't seem like an elegant solution.
P.S. I stopped the UART communication, and the issue has become less frequent, but it has not been resolved...
2024-04-09 04:54 AM
@tykhaytschaar wrote:I suspect that this is because while the I2C communication is in progress, a UART (or DMA) interrupt interrupts it.
:
:
P.S. I stopped the UART communication, and the issue has become less frequent, but it has not been resolved...
So I think that rather suggests that it's not the UART communication which causes the problem?
Looks like there's some other problem that's the root cause, but the UART may exacerbate that?
Maybe you've got some timing somewhere that's marginal, so it occasionally fails - but the added load of handling the UART makes the timing worse and the symptoms appear more often?
2024-04-09 05:31 AM
Thanks for the response!
Indeed, you are correct, I suppose. It's not necessarily a UART problem, but most of the events captured on the scope resemble the picture above. So, I still suspect it's some kind of interrupt-related issue, and UART also generates interrupts... The other interrupt source is a timer interrupt occurring at a frequency of 1kHz, but its handler is nearly as fast as the I2C's. (It checks a boolean value and writes a GPIO pin if needed.) Nevertheless, I still can't figure out the nature of the root problem: why any interrupt with a very fast ISR can cause I2C communication to fail?