cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 I2C slave mode needs delays - can this be overcome?

PMath.4
Senior III

I've used https://community.st.com/s/article/how-to-create-an-i2c-slave-device-using-the-stm32cube-library as the example code

and in the example the main program is:

/* USER CODE BEGIN WHILE */
  while (1)
  {
 
           if (Xfer_Complete ==1)
           {
            HAL_Delay(1);
             /*##- Put I2C peripheral in listen mode process ###########################*/
         if(HAL_I2C_EnableListen_IT(&hi2c1) != HAL_OK)
         {
           /* Transfer error in reception process */
           Error_Handler();
         }
           Xfer_Complete =0;
           }
 
    /* USER CODE END WHILE */

Note the delay after processing a message before re-arming the listener.

Unless I respect this delay in the master the transfer fails.

If I remove the delay then I still need a delay in the master between sending a write with a function code and then sending the read for the data.

I also need a delay in the master after the read before I can send a new write.

This is a problem for my application.

In the example the xfer_complete variable is volatile and set in the slave tx and rx complete callbacks so why are delays needed?

Is there any way round this.

The CPU is running at 48MHz and the processing in the callbacks is minimal - probably less than a u-sec

2 REPLIES 2
FBL
ST Employee

Hello @Community member​ ,

Could you please precise the I2CCLK frequency?

You may need to check the errata sheet STM32F030x4/x6/x8/xC device errata - Errata sheet section 2.9.5.

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.

PMath.4
Senior III

It is running at 400KHz. This isn't the issue. The problem is that after a completion callback you cannot immediately re-enable the listener and receive a new command. Presumably this is why the example has the delay but this seems like a workaround for something wrong