Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions libraries/ModbusSerial/ModbusSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ void ModbusSerial::task() {
_len = 0;
}

#ifndef USE_FLASH_PROGMEM
word ModbusSerial::calcCrc(byte address, byte* pduFrame, byte pduLen) {
byte CRCHi = 0xFF, CRCLo = 0x0FF, Index;

Expand All @@ -202,8 +203,24 @@ word ModbusSerial::calcCrc(byte address, byte* pduFrame, byte pduLen) {

return (CRCHi << 8) | CRCLo;
}
#endif



#ifdef USE_FLASH_PROGMEM
word ModbusSerial::calcCrc(byte address, byte* pduFrame, byte pduLen) {
byte CRCHi = 0xFF, CRCLo = 0x0FF, Index;

Index = CRCHi ^ address;
CRCHi = CRCLo ^ pgm_read_byte(&_auchCRCHi[Index]);
CRCLo = pgm_read_byte(&_auchCRCLo[Index]);

while (pduLen--) {
Index = CRCHi ^ *pduFrame++;
CRCHi = CRCLo ^ pgm_read_byte(&_auchCRCHi[Index]);
CRCLo = pgm_read_byte(&_auchCRCLo[Index]);
}

return (CRCHi << 8) | CRCLo;
}
#endif