esp-idf: How to read UART bytes in queue after break? (IDFGH-2424)
I’m currently working on a DMX512 library for the ESP32 https://github.com/luksal/ESP32-DMX-RX . DMX512 is a protocol based on RS485 where after a break signal 512 bytes are transmitted.
The main concept is running an infinite loop and call xQueueReceive periodically and then checking the event.type.
When a UART_DATA is received, I’m copying the received data to an array and waiting for the next event. That way I’m getting 120 bytes each event, in total 480 until the break occurs.
How can I receive the last 32 bytes? Because when event.type is UART_BREAK, then calling uart_get_buffered_data_len equals 0 and trying to use uart_read_bytes fails at this point.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 1
- Comments: 57 (27 by maintainers)
There is the other way of handling DMX512 packet using UART. I propose to use MARK before BREAK - MBB time (2Sec > MBB > 0) to detect end of packet without additional changes in UART driver. In most of DMX512 controllers this time is not zero and it allows to use existing hardware UART TOUT feature to detect the end of DMX512 packet. The start of DMX condition is still BREAK. The simplified receiver code would be like :
The log:
I tested my dmx512 receiver and transmitter over RS485 and this approach works just fine. Please let me know if you have any comments.
I added code to watch the even.size that is received when the event is triggered. It always returns event.size = 120.
So here’s how I think the low level driver works (Note I am now using pre release code. The new code has added a hal level and the mod mentioned above is not being used.):
What if you change this https://github.com/espressif/esp-idf/blob/647cb628a11a9ebd6952276fb7e6f354d4e3171d/components/driver/uart.c#L799-L802
To
You should then get data event and break event