STM32F030 I2C slave mode needs delays - can this be overcome?
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