cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Slave interrupt mode not behaving as expected

RCooke88
Associate II

Hi All,

I need some help with setting up a I2C slave on a STM32L422 chip. I have tried following the example: STM32Cube_FW_L4_V1.18.0/ NUCLEO-L412RB-P/examples/I2C_TwoBoards_ComIT but it doesn't seem to make sense to me. I realize it is not exactly the same as my chip but it should be close.

In my code I setup the I2C parameter settings as default except I've set the address for the slave as = 1. I have checked the NVIC I2C Event Interrupt and the Error Interrupt checkboxes.

In my main.c file I initialize the I2C

MX_I2C1_Init();

And then I have:

/*##-2- Put I2C peripheral in reception process ###########################*/
if(HAL_I2C_Slave_Receive_IT(&I2cHandle, (uint8_t *)aRxBuffer, RXBUFFERSIZE) != HAL_OK)
{
/* Transfer error in reception process */
Error_Handler();
}

The program will hang here. I don't understand why it's hanging here as there has been no

characters sent to the slave yet.

In my stm32l4xxit.c file I use:

 

 

 

 

void I2C1_EV_IRQHandler(void)
{
  HAL_I2C_EV_IRQHandler(&hi2c1);
}
void I2C1_ER_IRQHandler(void)
{
  HAL_I2C_ER_IRQHandler(&hi2c1);
}

 

 

 

Have I messed up the interrupt routine? What should it look like? Ultimately, I want the slave

to receive 24 bytes and let the program know its got the data ready to process.

Thanks,

Richard

2 REPLIES 2
Issamos
Lead II

Hello @RCooke88 

You can use this Wiki and this post to check if your code is well structured or not. 

Best regards.

II

Foued_KH
ST Employee

Hello @RCooke88 , 

I suggest you use an oscilloscope to check SDA and SCL behavior.
Try to debug and set breakpoints .

Foued

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.