-
Notifications
You must be signed in to change notification settings - Fork 7.6k
HardwareSerial not returning any read data if UART_BREAK_ERROR triggered #6849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I understand that the BREAK event doesn't prevent the sketch from getting the data. Have you tried to used a library such as https://github.com/reaper7/SDM_Energy_Meter |
That's exactly the library and code I'm using. I have a Saleae logic probe connected and I see both the request going to the SDM and the reply coming back but, as I mentioned, the last byte causes a BREAK as the data line does not go high. The code (from SDM.cpp) then times out as the available() call returns 0. SDM.cpp After several calls the available() returns 120 and the data is available to read. |
If it's of use - I just tried the same code but using SoftwareSerial instead of HardwareSerial, same GPIO pins (RX-26, TX-25) and it functions correctly. Change back to HardwareSerial and it fails. |
Let me try to reproduce this issue with 2 ESP32 (one receiving data and the other one simulating the SDM120M with a break at the end of the packet). I'll post here the findings. |
Would it be possible for you to modify the SDM120M library to add this lines: // assumption that it is using Serial1...
// forces available() to get data when there is no data in UART for more than
// 1 symbol (about 11 bits) in timeout at the current baudrate. Example 11 bits at 9600 is about 1 ms.
Serial1.setRxTimeout(1);
// it needs #include "driver/uart.h"
// this forces a time out even when FIFO FULL with exactly 120 bytes
uart_set_always_rx_timeout(1, true); // 1 is for Serial1, in this case I think that it may help. Other important information: There is fix to it that may solve the issue in the UART IDF driver that we use in the ESP32 Arduino Core 2.0.0+. PR espressif/esp-idf#5959 based in the same issue you have reported espressif/esp-idf#4537 |
Unfortunately it makes no difference. |
I would like to propose a fix for // Necessary include for testing the fix
#include "driver/uart.h"
void setup() {
// for example, start Serial1 - UART1
Serial1.begin(115200);
// right after starting UART1, add this code:
uart_intr_config_t uart_intr = {
.intr_enable_mask = (0x1<<0) | (0x8<<0), // UART_INTR_RXFIFO_FULL | UART_INTR_RXFIFO_TOUT,
.rx_timeout_thresh = 1,
.txfifo_empty_intr_thresh = 10,
.rxfifo_full_thresh = 112,
};
uart_intr_config((uart_port_t) 1, &uart_intr); // One is the UART number for Arduino Serial
} Could you please test it and let me know. |
Hi, I tried out the code but unfortunately still the same. |
We have done a few updates to UART in the new Arduino Core 2.0.5 version.
|
I have created an example for the BREAK event in Serial (at the end and the begining of a data stream) |
Board
ESP32 WROOM-32E
Device Description
Plain module on pcb
Hardware Configuration
GPIO21,22 connected to I2C
Version
v2.0.3
IDE Name
Visual Micro
Operating System
Windows 11
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
921600
Description
I'm trying to read from an SDM120M modbus energy meter. The meter is returning data. The last byte is 00 but after the last bit the data line stays low causing a framing error. This triggers an RX break in the uartEventTask.
No data is then available (serialX.available() returns 0)
Finally after a few calls the UART FIFO fills up and the uart then returns 120 from serialX.available() and provides provides the 120 bytes (presumably as UART_FULL_THRESH_DEFAULT is triggered).
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: