TMC7300
Loading...
Searching...
No Matches
TMCSerial.h
Go to the documentation of this file.
1#ifndef TMCSERIAL_H
2#define TMCSERIAL_H
3#include <Arduino.h>
4
5#define SYNC_BYTE 0x55
6#define WRITE_BIT 0x80
7
8// from https://github.com/bread-wolf/TMCSerial/blob/cb87877ab4f3c39ed7a5b1ec99cf73eb0f4d5a6c/TMCSerial.cpp#L181C1-L206C2
9uint8_t calcCRC(uint8_t data[], uint8_t dataLength)
10{
11 uint8_t crc, currentByte;
12
13 /* Initialize crc at 0 */
14 crc = 0;
15 for (uint8_t j = 0; j < dataLength; j++) {
16 currentByte = data[j];
17 for (uint8_t k = 0; k < 8; k++) {
18 if ((crc >> 7) ^ (currentByte & 0x01)) {
19 /* Use 0b100000111 as polynomial */
20 crc = (crc << 1) ^ 0x07;
21 } else {
22 crc = (crc << 1);
23 }
24 currentByte >>= 1;
25 }
26 }
27 return crc;
28}
29#endif // TMCSERIAL_H
uint8_t calcCRC(uint8_t data[], uint8_t dataLength)
Definition TMCSerial.h:9