eModbus: E2 - CRC check error

Describe the bug: When trying to read holding registers I get a E2 - CRC check error relatively often. When enabling #define LOG_LEVEL LOG_LEVEL_DEBUG there are no E2 - CRC check error anymore.

Modbus Blocks:

Block: Min: Max: Size:
000 000 030 031
001 041 057 017

Expected behavior: There shouldn’t be any E2 - CRC check error.

Ouput (LOG_LEVEL_DEBUG):

[D] Sent packet: @3FFB264C/6:
  | 0000: 01 03 00 00 00 1F                                 |......          |
[D] 200229| ModbusClientRTU.cpp  [ 198] handleConnection: Request sent.
[D] Raw buffer received: @3FFB2A6C/67:
  | 0000: 01 03 3E 00 60 00 00 00  00 00 00 00 00 00 00 02  |..>.`...........|
  | 0010: 79 00 D6 00 6D 00 01 00  00 01 C8 00 01 00 02 00  |y...m...........|
  | 0020: E2 00 00 02 B9 00 00 0B  D6 27 28 02 79 4C 9F 00  |.........'(.yL..|
  | 0030: 00 00 08 00 50 0F 71 0C  A8 00 01 00 01 00 64 00  |....P.q.......d.|
  | 0040: 01 55 5C                                          |.U\             |
[D] Received packet: @3FFB2CCC/65:
  | 0000: 01 03 3E 00 60 00 00 00  00 00 00 00 00 00 00 02  |..>.`...........|
  | 0010: 79 00 D6 00 6D 00 01 00  00 01 C8 00 01 00 02 00  |y...m...........|
  | 0020: E2 00 00 02 B9 00 00 0B  D6 27 28 02 79 4C 9F 00  |.........'(.yL..|
  | 0030: 00 00 08 00 50 0F 71 0C  A8 00 01 00 01 00 64 00  |....P.q.......d.|
  | 0040: 01                                                |.               |
[D] 200356| ModbusClientRTU.cpp  [ 204] handleConnection: Data response (65 bytes) received.
[D] 200364| ModbusClientRTU.cpp  [ 225] handleConnection: Response generated.
[D] 200371| ModbusClientRTU.cpp  [ 193] handleConnection: Pulled request from queue
[D] Sent packet: @3FFB2604/6:
  | 0000: 01 03 00 29 00 11                                 |...)..          |
[D] 200391| ModbusClientRTU.cpp  [ 198] handleConnection: Request sent.
[D] Raw buffer received: @3FFB2A6C/39:
  | 0000: 01 03 22 00 00 00 00 00  00 00 00 00 00 00 00 00  |..".............|
  | 0010: 00 00 00 EB 34 00 00 55  14 00 00 96 5C 00 53 C5  |....4..U....\.S.|
  | 0020: B8 00 16 06 DA 3F C9                              |.....?.         |
[D] Received packet: @3FFB2604/37:
  | 0000: 01 03 22 00 00 00 00 00  00 00 00 00 00 00 00 00  |..".............|
  | 0010: 00 00 00 EB 34 00 00 55  14 00 00 96 5C 00 53 C5  |....4..U....\.S.|
  | 0020: B8 00 16 06 DA                                    |.....           |
[D] 200475| ModbusClientRTU.cpp  [ 204] handleConnection: Data response (37 bytes) received.
[D] 200483| ModbusClientRTU.cpp  [ 225] handleConnection: Response generated.
[D] 201190| ModbusClientRTU.cpp  [ 126] addRequestM: request for 01/03
[D] 201191| ModbusClientRTU.cpp  [ 175] addToQueue: RC=01
[D] 201191| ModbusClientRTU.cpp  [ 137] addRequestM: RC=00
[D] 201191| ModbusClientRTU.cpp  [ 193] handleConnection: Pulled request from queue
[D] 201196| ModbusClientRTU.cpp  [ 126] addRequestM: request for 01/03
[D] 201209| ModbusClientRTU.cpp  [ 175] addToQueue: RC=01
[D] 201214| ModbusClientRTU.cpp  [ 137] addRequestM: RC=00

Handle RTS method:

void handle_rts(bool toggle_level) {
  if (!w5500_initalized) {
    digitalWrite(RTS_PIN, toggle_level);
  }
}

Additional info:

I already tried to add the crc to my messages beforehand via. addCRC(), the problem seesm to lie in the response tough so that didn’t solve any issues. Additionaly it seems that playing around with delays didn’t really help as well, because E2 - CRC check error are less frequent but they still appear seemingly randomly.

I have also tried to play around with the Modbus interval timeout, but it also didn’t really help in solving the issue. I also seem to get a response everytime so the request itself seems to be fine and it seems to be received on the other side as well.


Is there something I am missing with the CRC16 check or do I need to add something like a delay() etc? Because I really can’t fathom what exactly the problem could be.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 215 (109 by maintainers)

Most upvoted comments

Thanks for your patience and help - the code is now released officially.

If I was concerned I would leave it running regardless. There will be some evidence in the still existing lines on Monday I am sure.

Schönes Wochenende!

One last test, if you are not in a weekend hurry yet: Just below the line you put in last - you may remove it again - is a block that is entered as soon as no more bytes are found:

       // Did we read some?
        if (hadBytes) {
          // Yes, take another turn
          intervalEnd = micros();
          delay(1);

Please have a LOG_N("tick!\n"); just before the delay(1);.

Rats. 😠

This makes it even more difficult. If it was a software fault, one would expect it to happen in regular intervals. With your measurements it is looking more like an intermittent hardware issue.

  • Is your setup on a PCB in a housing already or still on breadboard?
  • Something around it that may induce voltage peaks, electromagnetic fields or such?
  • Where did you connect the LA - directly on the TX/RX pins on the MCU board or somewhere else?
  • Are you doing something in your sketch based on the data you received? Calculate addresses or such?