I2C stops working after exactly 1 minute 6 seconds
- December 10, 2021
- 5 replies
- 1912 views
Controller : STM32L031F6P7 custom board.
I2C stops working after exactly 1 minute 6 seconds? I can replicate this every time.
When it stops working, i cannot reset the i2c pheriperal in any way i have found in this forum.
These are attempts i already tried.
static void rtc_reset_i2c_hw(void){
MX_I2C1_Init();
/*
HAL_I2C_DeInit(&hi2c1);
__HAL_RCC_I2C1_FORCE_RESET();
HAL_Delay(5);
__HAL_RCC_I2C1_RELEASE_RESET();
if (HAL_I2C_Init(&hi2c1) != HAL_OK) {
Error_Handler();
}
HAL_Delay(100);
*/
//HAL_DMA_DeInit(pDMArx);
//HAL_DMA_DeInit(pDMAtx);
//HAL_DMA_Init(pDMArx);
//HAL_DMA_Init(pDMAtx);
/*
HAL_I2C_DeInit(&hi2c1);
HAL_I2C_Init(&hi2c1);
hi2c1.Instance->CR1 &= ~I2C_CR1_PE; // clear pheripheral enable
hi2c1.Instance->CR1 &= ~I2C_CR1_PE; // clear pheripheral enable
hi2c1.Instance->CR1 &= ~I2C_CR1_PE; // clear pheripheral enable
HAL_Delay(50);
hi2c1.Instance->CR1 |= I2C_CR1_PE; // enable pheripheral enable
*/
i2c_state = i2c_startRx;
}I have created the project with the absolute minimum pheriperals (IO and I2C), and it keep failing with the HAL library functions.
I use I2C as slave and use a statemachine to organize stuff.
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *I2cHandle)
{
i2c_state = i2c_startRx;
interruptcnt = 0;
}
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *I2cHandle)
{
i2c_state = i2c_RxCmplt;
interruptcnt = 0;
}
void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *I2cHandle)
{
//Error exception callback function
rtc_reset_i2c_hw();
}
void AliveTasks(void){
HAL_StatusTypeDef rel;
switch(i2c_state){
case i2c_startRx:
rel = HAL_I2C_Slave_Receive_IT(&hi2c1, (uint8_t*) i2cbuffer_in,I2C_BUFFER_SIZE);
if (rel != HAL_OK) {
rtc_reset_i2c_hw();
}
tmr_ms_Start(&i2c_tmo, 100);
i2c_state = i2c_waitforRxCmplt;
break;
case i2c_RxCmplt:
tmr_ms_Start(&i2c_tmo, 100);
rtc_process_i2c_cmd();
HAL_I2C_Slave_Transmit_IT(&hi2c1,i2cbuffer_out,I2C_BUFFER_SIZE);
i2c_state = i2c_waitforTxCmplt;
break;
case i2c_waitforRxCmplt:
case i2c_waitforTxCmplt:
if(tmr_ms_Ok(&i2c_tmo)){
faultdetect = 1;
tmr_ms_Start(&i2c_tmo, 100);
rtc_reset_i2c_hw();
}
break;
}
}
This is what i see at the logic analyzer.
Pictures goes from all good -> moment of terror -> continuously terror


What can cause HAL I2C to stop working like this?
How can i do a full reset of HAL I2C ?
Does anyone have a link to non HAL I2C code, or should i write myself? already spend too much time on this issue....
