cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743ZI I2C4 unexpected interruption

Gabriel T
Senior

Hi,

I recently need to use I2C with interrupt mode to lower my CPU usage.

So I did this changes :

I changed the function where I call my transmit

static HAL_StatusTypeDef PGA309_Write_RawData(uint8_t REGISTER,uint8_t LSB_DATA,uint8_t MSB_DATA)
{
	uint16_t i = 0;
	I2C1_TxBuffer[i++]= REGISTER; //First data : Set register address
	I2C1_TxBuffer[i++]= LSB_DATA; //Second data : LSB value
	I2C1_TxBuffer[i++]= MSB_DATA; //Third data : MSB value
	//return HAL_I2C_Master_Transmit(&hi2c4, (uint16_t)PGA309_SLAVE_ID, I2C1_TxBuffer, i, (uint32_t)100);
	return HAL_I2C_Master_Transmit_IT(&hi2c4, (uint16_t)PGA309_SLAVE_ID, I2C1_TxBuffer, i);
}

I added NVIC stuff to HAL_I2C_MspInit()

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{
  GPIO_InitTypeDef GPIO_InitStruct = {0};
  if(hi2c->Instance==I2C4)
  {
  /* USER CODE BEGIN I2C4_MspInit 0 */
 
  /* USER CODE END I2C4_MspInit 0 */
 
    __HAL_RCC_GPIOF_CLK_ENABLE();
    /**I2C4 GPIO Configuration
    PF14     ------> I2C4_SCL
    PF15     ------> I2C4_SDA
    */
    GPIO_InitStruct.Pin = GPIO_PIN_14|GPIO_PIN_15;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
    GPIO_InitStruct.Alternate = GPIO_AF4_I2C4;
    HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
 
    /* Peripheral clock enable */
    __HAL_RCC_I2C4_CLK_ENABLE();
  /* USER CODE BEGIN I2C4_MspInit 1 */
    HAL_NVIC_SetPriority(I2C4_ER_IRQn, 2, 2);
    HAL_NVIC_EnableIRQ(I2C4_ER_IRQn);
    HAL_NVIC_SetPriority(I2C4_EV_IRQn, 2, 2);
    HAL_NVIC_EnableIRQ(I2C4_EV_IRQn);
  /* USER CODE END I2C4_MspInit 1 */
  }
}

But shortly after I call Transmit_IT my CPU ends up stuck here :

/**
 * @brief  This is the code that gets called when the processor receives an 
 *         unexpected interrupt.  This simply enters an infinite loop, preserving
 *         the system state for examination by a debugger.
 * @param  None     
 * @retval None       
*/
    .section  .text.Default_Handler,"ax",%progbits
Default_Handler:
Infinite_Loop:
  b  Infinite_Loop
  .size  Default_Handler, .-Default_Handler

It looks like my I2C peripheral is sending an unexpected interrupt, am I missing some init parameters ?

1 ACCEPTED SOLUTION

Accepted Solutions
Gabriel T
Senior

I added this to my main and it works now

extern void I2C4_EV_IRQHandler()
{
    HAL_I2C_EV_IRQHandler(&hi2c4);
}

View solution in original post

2 REPLIES 2
Gabriel T
Senior

Also, I am only sending the first byte

0693W000007DjSJQA0.png

Gabriel T
Senior

I added this to my main and it works now

extern void I2C4_EV_IRQHandler()
{
    HAL_I2C_EV_IRQHandler(&hi2c4);
}