0

Protocol for BM62 Bluetooth Module

I just have a simple question about how the Checksum algorithm works for a particular Bluetooth module (BM62). The picture above has the UART protocol explained, and it explains the checksum rule, but I am having trouble understanding how it actually works, and cannot seem to guess the checksum value as it is given in the example in the picture.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180
Bobo
  • 5
  • 2

1 Answers1

1

The idea seems to be that you need to come up with CHKSUM such that LENH + LENL + OPCODE + PARAM + CHKSUM has 0 in the least significant byte. So, let's do the summation in 8 bits (or modulo 256):

LENH + LENL + OPCODE + PARAM + CHKSUM = 0

CHKSUM = -(LENH + LENL + OPCODE + PARAM)

IOW, CHKSUM = -(0 + 2 + 1 + 0) = -3 = 0xFD. (Remember that all of this was done in 8 bits).

You can verify that CHKSUM satisfies the requirement (you're now doing everything in 16 bits):

0 + 2 + 1 + 0 + 0xFD = 0x100

And that has 0 in the least significant byte. If we did this in 8 bits as well, we'd get 0 instead of 0x100 and that would also be a valid way to check correctness.

Alexey Frunze
  • 61,140
  • 12
  • 83
  • 180