STM32 I2C Read Variable Length message from Slave

by AJBotha   Last Updated July 28, 2018 12:25 PM

I have two devices that must communicate over I2C. The master writes some data to the slave, and then it must read back a response from the slave.

Neither the slave nor the master knows the length of the message that should be received. On the Slave this is not a problem, I set the DMA to receive 255 bytes (more than the master will ever write in one message), and then wait for the STOP condition to be raised to signal the end of the transfer.

On the Master I can't figure out how to read a message from the slave without knowing how many bytes should be read. Is there a way to do this? My understanding is that the Master generates the STOP condition, so I can't use that.

I currently just read back one byte from the slave that contains the number of bytes that are to be transferred, and then do another read for that amount of data, but I am looking for a more efficient and faster way.

I am using STM32L433 MCU's and have used the LL-Libraries for the I2C code with DMA to transfer the messages to the peripheral.
Best Regards



Related Questions


STM32 SPI SCLK stops ticking

Updated December 28, 2017 16:25 PM

Addressing registers with I2C STM32F0 HAL libraries

Updated August 15, 2016 08:10 AM

SPI wrong received data

Updated March 02, 2017 23:25 PM