cancel
Showing results for 
Search instead for 
Did you mean: 

Using STM32WB55 BLE Heartrate example as start point then adding I2C functionality to read sensor but second I2C exchange (e.g. read) causes code to hang in HW_TS_RTC_Wakeup_Handler().

MMcke.1
Associate

Working on project with BLE interface and need to add I2C interface to read a sensor. Started with BLE Heartrate example (it wakes up ever 1s which I also need to do) and added I2C by using CubeMX to generate the new code.

To start testing I added this code snipit

 BSP_LED_Init(LED2);

 BSP_LED_Init(LED3);

 BSP_LED_On(LED2);

 aTxBuffer[0] = 0x0F; // register I am reading and I2C_ADDRESS -> 0x6A << 1

 I2C_result = HAL_ERROR;

 while(HAL_OK != HAL_I2C_Master_Transmit(&hi2c1, I2C_ADDRESS, (uint8_t*)aTxBuffer, 1, 1000))

 {

  /* Error_Handler() function is called when Timeout error occurs.

    When Acknowledge failure occurs (Slave don't acknowledge it's address)

    Master restarts communication */

  if (HAL_I2C_GetError(&hi2c1) != HAL_I2C_ERROR_AF)

  {

   Error_Handler();

  }

 }

 //HAL_Delay(50);

 BSP_LED_On(LED3);

 while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY) {}

 I2C_result = HAL_I2C_Master_Transmit(&hi2c1, I2C_ADDRESS, (uint8_t*)aTxBuffer, 1, 1000);

 //I2C_result = HAL_I2C_Master_Receive(&hi2c1, I2C_ADDRESS, aRxBuffer, 1, 1000);

 BSP_LED_Off(LED2);

 BSP_LED_Off(LED3);

Tried a few variants as you can see from the commented out bits.

Fault is the the second write HAL_I2C_Master_Transmit never returns - if I hit pause I'm in HW_TS_RTC_Wakeup_Handler() where I get trapped as CurrentRunningTimerID is set to 66 - which is an illegal value.

The I2C interface behaves as expected - I have checked on a logic analyzer and the bit sequence and timing are perfect. The second read (or write) is performed correctly (if it's a read the expected value is read back) - but read or write function not returned.

Unable to single step through the HAL routines for some reason.

Assuming the I2C example works (don't have 2 nucleo boards to try it completely) seems to be something to do with starting with the BLE example and adding I2C.

Can someone help shed any light on what's going on.

Cheers

3 REPLIES 3
MM..1
Chief II

WBx5 is dual core MCU and in examples power management from one core stop second core etc.

You dont show where you place your code , but if example is based on sequencer and BLE do advertising jobs BLE core manage MCU into low power and wake over RTC. This you see in debug.

Remy ISSALYS
ST Employee

Hello,

You can look this post maybe in your case it's the same issue:

https://community.st.com/s/question/0D53W00001K2koYSAR/hwtimerserver-hangs-on-stm32wb-w-ble

Best Regards

MMcke.1
Associate

Thank you for both replies.

The replay from Remy helped in that the solution 1 in the liked question allowed my code to run - but seemed to cause other problems later in the BLE. However indicated it was actually related to RTC.

The comment from MM asked where the code was placed. It was just quick and dirty test code so I placed it in main.c between /* USER CODE BEGIN 2 */ and /* USER CODE END 2 */. This is between MX_RTC_Init() and MX_APPE_Init() - and is not actually where I plan to use it. I moved it to the BLE HRSAPP_Measurement() which gets called once a second after the BLE link is established and notifications enabled. As all of the system code is running at this point everything works as expected.

Thanks for the help guys - would not have figured this out otherwise.