cancel
Showing results for 
Search instead for 
Did you mean: 

How to Receive Variable size of data in I2c Slave reveiver mode?

Rohit007
Associate III

I am using STM32 Nucleo-H743ZI2 as a I2C transmitter and Nucleo-G0B1RE as I2C Slave Receiver in interrupt mode, now i am trying to receive Variable size of data i.e. i want to keep Slave receiver size to be Maximum and want to Stop receiving when Transmitter sends Stop condition i.e. i want slave to receive any variable data size without changing actual size of slave. i am trying to use slave sequential receive in interrupt mode but it only reacts to 1 byte at a time. so, please help me solve this issue. 

3 REPLIES 3
TDK
Guru

Please continue your previous thread rather than duplicate posting.

Duplicate:

https://community.st.com/t5/stm32-mcus-products/i2c-slave-not-printing-the-received-data/td-p/625812

 

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

Hii,

In that post i was transmitting one byte at a time, but now i want to transmit multiple byte data in one time.

 

Mike_ST
ST Employee

>> i am trying to use slave sequential receive in interrupt mode but it only reacts to 1 byte at a time.

You have to activate/check/clear the stop condition bit in the I2C_CR1/I2C_ISR/I2C_ICR registers to detect a stop condition.

From what I see, at the end of HAL_I2C_Slave_Receive_IT(),  it is not activated, because I guess the function is relying on the expected number of bytes:

So maybe you want to change "I2C_Enable_IRQ(hi2c, I2C_XFER_RX_IT | I2C_XFER_LISTEN_IT);"

to "I2C_Enable_IRQ(hi2c, I2C_XFER_RX_IT | I2C_XFER_LISTEN_IT| I2C_IT_STOPI);"

And maybe patch the I2C_ITSlaveCplt to avoid setting an error because of the
if (hi2c->XferCount != 0U)
{
/* Set ErrorCode corresponding to a Non-Acknowledge */
hi2c->ErrorCode |= HAL_I2C_ERROR_AF;
}