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.