cancel
Showing results for 
Search instead for 
Did you mean: 

I2C slave is not working in reading and writing

KrunalChauhan
Associate II

I am using STM32F7508-DK kit and Using I2C as a slave whereas ESP32 is a master, By using HAL_I2C_Slave_Receive_IT and HAL_I2C_Slave_Transmit_IT API I am able to do one way communication either read or write, but in my application I required read and write both in sequence, here I am facing issue.

Below is my set up details:

STM32CubeIDE, Version: 1.3.0

STM32 ST-LINK Utility V4.5.0

STM32 CubeMX, Version5.6.1

Here is my I2C configuration:

hi2c1.Instance = I2C1;

hi2c1.Init.Timing = 0x20404768;

hi2c1.Init.OwnAddress1 = 214;

hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;

hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;

hi2c1.Init.OwnAddress2 = 0;

hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;

hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;

hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;

Looking forward to hear from you.

2 REPLIES 2
TDK
Guru

I don't see a specific technical question here. The I2C needs to read and write at various points, you'll need to implement logic to call HAL_I2C_Slave_Receive_IT and HAL_I2C_Slave_Transmit_IT at those points.

There are I2C examples in the cube repository you can look at for guidance. For example:

https://github.com/STMicroelectronics/STM32CubeF7/blob/08376dce1b404687e4a86b73077f396bccfc9cb5/Projects/STM32F769I-Discovery/Examples/I2C/I2C_TwoBoards_ComPolling/Src/main.c

https://github.com/STMicroelectronics/STM32CubeF7/blob/08376dce1b404687e4a86b73077f396bccfc9cb5/Projects/STM32F769I-Discovery/Examples/I2C/I2C_TwoBoards_ComIT/Src/main.c

I would suggest getting it working with polling mode first, then graduate to interrupt mode.

If you feel a post has answered your question, please click "Accept as Solution".

I have already used polling mode but I am getting more failure in polling mode compare to interrupt mode. and how would I know which function do I call HAL_I2C_Slave_Receive_IT or HAL_I2C_Slave_Transmit_IT because master can ask for any request either read or write. to check this I have read ADDR flag and DIR flag and then I am calling respective function but still it is not working.