Hi, my name is Jorge.
I'm currently working with an STM32WB5MMG, which has Bluetooth LE 5.2 connectivity. In the current version of the project, it's working with two Bosch sensors. The BMI088 with accelerometer and gyroscope, and the BMM150 with a magnetometer.
I've been working with the sensors through SPI communication in the same SPI2 port of the MCU. The operation mode works obtaining data by a data ready interrupt. Each sensor works at a different data acquisition frequency, so it can measure data at different frequencies. The BMM150 sensor has a forced mode that allows to work at higher frequencies, so it's currently configured so it can obtain the measured data from the 3 sensors at 400Hz.
The problems started when I enabled BLE on the MCU. The project works fine for a while, until it suddenly disconnects from the device connected via Bluetooth. The MCU doesn't seem to notice that it has been disconnected for a moment, so if the mobile device requests reconnection, it reconnects. The problem is that the time it takes to disconnect seems to be completely arbitrary, in different tests it seems that it can take between 30 seconds and 40 minutes to have a disconnection.
I've noticed that the problem seems to come from the BMM150. When this sensor is disconnected from the MCU, the BLE communication seems to work fine with only the other sensor. The BMM150 has initialization and data request functions via SPI. If I try to just initialize the sensor, without even requesting data, the BLE disconnection happens anyway.
I've tried different boards and the same problem occurs on all of them. I have also tested with different mobile devices. I have tried to work with timers instead of interrupts, the problem I see is that I have no control over the BLE communication. The only conclusion I reached is that the problem is using the same SPI for both sensors, although through breakpoints I've seen that the operation is sequential, so the interrupts should not be at the same time.
Right now I don't know if it's something completely normal that can happen with BLE, but I'm running out of ideas to try other tests and find where's the problem. Thank you in advance.
As you set sensor ODR to 400 Hz and used data ready interrupt, MCU would receive hardware interrupt every 2.5 ms.
Does Bluetooth communicate frequently? If yes, it is necessary to evaluate the conflict between Bluetooth communication and 2.5 ms sensor hardware interrupt from the time slice.