-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Closed
Labels
Type: For referenceCommon questions & problemsCommon questions & problemsType: QuestionOnly questionOnly question
Description
Board
ESP32-Wrover
Device Description
Hardware Configuration
Version
v2.0.14
IDE Name
PlatformIO
Operating System
Windows10
Flash frequency
80
PSRAM enabled
yes
Upload speed
115200
Description
I'm using onReceive callback for Serial1.
Sometimes the packet is truncated and I got the last one or two bytes in the next packet.
No matter the packet timeout it seems.
Sketch
void setup(){
Serial1.begin(MBUS_BAUD, SERIAL_8N1, MBUS_RX, MBUS_TX);
Serial1.setPins(-1, -1, -1, MBUS_RTS);
Serial1.setMode(MODE_RS485_HALF_DUPLEX);
Serial1.setTxBufferSize(RESPONSE_BUFFER_SIZE);
Serial1.setRxBufferSize(RESPONSE_BUFFER_SIZE);
Serial1.setRxTimeout(RX_TIMEOUT);
Serial1.onReceive([this](void) { handleRawPacket(); },true);
Serial1.onReceiveError([this](hardwareSerial_error_t error) { handlePacketError(error); });
}
void handleRawPacket() {
packetByteCount = 0;
while (Serial1.available()) {
respBuffer[packetByteCount] = Serial1.read();
packetByteCount++;
}
#if MODBUS_DEBUG
printf("[Modbus] - Got packet: ");
for (size_t i = 0; i < packetByteCount; i++){
printf("0x%02x ", respBuffer[i]);
}
printf("\n");
vTaskDelay(DEBUG_DELAY_MS);
#endif
gotPacket = true;
}
void handlePacketError(hardwareSerial_error_t error){
// Ignore the UART_BREAK_ERROR because it is expected.
if( error == UART_BREAK_ERROR ){ return; }
#if MODBUS_DEBUG
printf("\n[Modbus] - Packet error code: %d\n", error);
printf("[Modbus] - Packet error description: %s\n", uartErrorStrings[error]);
#endif
}
Debug Message
Just one packet in two ( usually the last two bytes is trucated and comes as a second packet ).
I have tried RX_TIMEOUT from 3 to 20. Does not matter.
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Labels
Type: For referenceCommon questions & problemsCommon questions & problemsType: QuestionOnly questionOnly question