Interrupts and I2C Peripherals
- February 4, 2021
- 8 replies
- 4566 views
Hello all! My name is Matt and I am a university student studying EE. For school, I recently designed a board with an STM32405RG MCU and BMI088 IMU. Part of the project is gathering data from the gyroscope and processing it every time step.
My original plan was to use the gyroscope in polling mode as fast as possible, and then use a timer interrupt to send out important data over serial at ~50 Hz. Before implementing this timer interrupt, the code worked perfectly fine and everything seemed ok. However, as soon as I enable the timer interrupt, my code only runs for a few milliseconds before something calls the Error_Handler().
I am unsure why this is happening. My intuition tells me that the interrupt may be interfering with stuff that HAL is doing to talk to the I2C peripheral. If I want to send out data periodically over serial, does this mean that I also must use the gyroscope in interrupt mode, instead of polling mode? Would I need to set interrupt priorities in some specific if I chose to do this?
A high level description of the code is:
while(1)
{
- Read gyroscope data (in polling mode)
- Process gyroscope data
- Update internal state
}
50Hz_Interrupt_Handler()
{
- Read internal state
- Send internal state over serial
}
Please forgive any amateur coding mistakes. As I said, I am a university student doing this for the first time :)
Thank you for any help!
Matt
