Hi everyone,
I'm trying to send a roughly 29 byte Protobuf message over I2C + a 3 byte header between two ESP32s. The I2C master can send the messages fine, however, I'm having trouble using i2c_slave_read_buffer because the bytes are out of order. The first byte of my header is always 0xB, so the buffer output of i2c_slave_read_buffer should start with 0xB, but in reality I get about 1/4 of the previous message, two null bytes, then 3/4 of the full message. I've tried calling i2c_reset_rx_fifo before and after my call to the I2C slave read function, but it doesn't help.
The documentation is vague as to whether or not the FreeRTOS ringbuffer is emptied when the slave receives a new message, but from looking at the source code it doesn't appear to be. Is there a reason for this? Wouldn't it make sense to empty the ringbuffer once a begin bit is detected and make the buffer available for use after an end bit is detected?
My current plan is to create an interrupt which copies the buffer, but it seems inefficient to have two interrupts running at once (my one along with the default one), not to mention the fact that there is no interrupt (as far as I can see) to determine when the slave detects a begin bit. If anyone has any suggestions, that would be greatly appreciated.
Cheers,
Matt.
Issues with i2c_slave_read_buffer
- monkeyonkeyboard
- Posts: 2
- Joined: Tue May 28, 2019 6:18 am
Re: Issues with i2c_slave_read_buffer
In case anyone is looking for a solution, I've mostly resolved the issue by reading the buffer one byte at a time:
If the buffer is out of order, the best solution is to call i2c_reset_rx_fifo() and wait about 10ms.
- uint8_t byte = 0;
- // attempt to read in bytes one by one
- while (true){
- i2c_slave_read_buffer(I2C_NUM_0, &byte, 1, portMAX_DELAY);
- buf[i++] = byte;
- // ... other code, terminate while loop once end byte is received
- }
Re: Issues with i2c_slave_read_buffer
Great.. It will be helpful for others who are using I2C or planning to use into future.
Thanks for your effort with solution as well.
Thanks for your effort with solution as well.
Regards,
Ritesh Prajapati
Ritesh Prajapati
Who is online
Users browsing this forum: Baidu [Spider], Bing [Bot] and 155 guests