Kaveh
Members
-
Joined
-
Last visited
Reputation Activity
-
Kaveh reacted to BritishRacingGreen in Narada NPFC Tian Power BMS protocolfor sending data , you shift all the bytes thru the checksum below starting from the first 0x7C/0x7E character to the end of payload. You then append the checksum byte as well as an 0x0D character.
uint8_t nerada_485_checksum(uint8_t *buf, uint8_t len)
{
uint8_t b = 0;
uint8_t b2 = 0;
int num = 0;
for (b = 0; b < len; b++)
{
b2 ^= buf[b];
num += buf[b];
}
return (uint8_t)((uint)(b2 ^ num) & 0xFFu);
}
When receiving data , you shift all the bytes thru the checksum starting at the first character up to and excluding the checksum byte and the 0x0D character. You then compare your calculated checksum against the received check sum , and also check that the last character is indeed 0x0D.