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().
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
