cancel
Showing results for 
Search instead for 
Did you mean: 

BMM150 causing problems with the BLE communication

jorgazam
Associate II

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.

6 REPLIES 6
Remy ISSALYS
ST Employee

Hello,

Have you try to use only the BMM150 sensor and look if BLE disconnection happens ? Can you give more information about your clock configuration ? When the disconnection happens, if you wait at least 30 seconds before request a reconnection, do you see event from CPU2 which notice that a disconnection happens ?

Best Regards

jorgazam
Associate II

I verified that using only the BMM150 sensor the disconnection also happens. The main clock of the MCU is set to 64MHz, but in SPI it is prescaled to work at 8 MHz.

After disconnecting from the mobile device, it takes a few seconds (sometimes more than 30) for the MCU to detect it. This event is detected through the Custom_APP_Notification function of the automatically generated custom_app.c file. In the CUSTOM_DISCON_HANDLE_EVT case there is a flag indicating that it has been disconnected to stop taking measurements, but as I said, the disconnect event only occurs a few seconds after it has actually been disconnected from the mobile device.

Remy ISSALYS
ST Employee

Hello,

Can you check if CPU2 is running at 32 MHz ? Can you send your clock configuration (e.g SystemClock_Config function) ?

Best Regards

jorgazam
Associate II

Yes, the clock configuration is set like this:

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 /** Configure LSE Drive Capability

 */

 HAL_PWR_EnableBkUpAccess();

 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);

 /** Configure the main internal regulator output voltage

 */

 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

 /** Initializes the RCC Oscillators according to the specified parameters

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSE

               |RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;

 RCC_OscInitStruct.HSEState = RCC_HSE_ON;

 RCC_OscInitStruct.LSEState = RCC_LSE_ON;

 RCC_OscInitStruct.HSIState = RCC_HSI_ON;

 RCC_OscInitStruct.MSIState = RCC_MSI_ON;

 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;

 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;

 RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;

 RCC_OscInitStruct.PLL.PLLN = 32;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;

 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;

 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure the SYSCLKSource, HCLK, PCLK1 and PCLK2 clocks dividers

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK4|RCC_CLOCKTYPE_HCLK2

               |RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.AHBCLK2Divider = RCC_SYSCLK_DIV2;

 RCC_ClkInitStruct.AHBCLK4Divider = RCC_SYSCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_3) != HAL_OK)

 {

  Error_Handler();

 }

}

I'LL also attach a screenshot so you can see it easily.

Remy ISSALYS
ST Employee

Hello,

You can try to change the LSE drive setting from RCC_LSEDRIVE_LOW to RCC_LSEDRIVE_HIGH. According to the datasheet on STM32WB5MMG there is three sensitive GPIOS, maybe you used one these GPIOs:

0693W00000NpmrlQAB.pngBest Regards

jorgazam
Associate II

Hi,

I realized that the sensitive GPIOs doesn't have the corresponding capacitors thanks to your answer, however, I use these pins only for an external memory that I'm not using at this moment, so I'm not using them for the communication with any of the sensors (BMI or BMM).

On the other hand, I'm going to try to change the LSE drive, what difference does this change make for the clock?