RFID - CRC parameters, how to calculate them?

Hello,
Sorry I made you wait.

Since I couldn't receive any goods from the code earlier, I tried something different, and I found a post from Arduino where explains the RS232 conecction and code. So I remove the library "SoftwareSerial" and replicate this one with some minors changes.

#include <ctype.h>

byte rx = 6;
byte tx = 7;
byte NewVal;
char sx[14];
char nx[14];
int j = 0;
int limit = 0;
unsigned char commConfig[9] = { 0x0a, 0x00, 0x35, 0x01, 0x02, 0x04, 0x00, 0x01, 0x00 };
unsigned char commBaud[4] = { 0x05, 0x00, 0x28, 0x00 };
unsigned char commAdd[4] = { 0x05, 0x00, 0x24, 0xFF };

void setup() {
  Serial.begin(9600);
  //Serial.println(crc_cal(commAdd,4), HEX);
  pinMode(rx, INPUT);
  pinMode(tx, OUTPUT);
  digitalWrite(tx, HIGH);
  delay(2);
  sendInfo();
  //sendConfig();
  //sendBaudRate();
  //sendAddress();
}

void WriteFunc(int data) {
  byte mask;
  digitalWrite(tx, LOW);
  delayMicroseconds(100);
  for (mask = 0x01; mask > 0; mask <<= 1) {
    if (data & mask) {
      digitalWrite(tx, HIGH);
    }
    else {
      digitalWrite(tx, LOW);
    }
    delayMicroseconds(100);
  }
  digitalWrite(tx, HIGH);
  delayMicroseconds(100);
}

int Read2Bin() {
  byte val = 0;
  while (digitalRead(rx)); 
  if (digitalRead(rx) == LOW) {
    delayMicroseconds(50);
    for (int i = 0; i < 8; i++) {
      delayMicroseconds(100);
        val |= digitalRead(rx) << i;
    }
    delayMicroseconds(100);
    return val;
  }
}

void loop() {
  NewVal = Read2Bin();
  sx[j] = NewVal;
  
  if (j == 0) {
    limit = sx[j];
  }
  
  j++;

  if (j >= limit + 1) {
      for (j = 0; j <= limit ; j++) {
         nx[j] = sx[j] & 0xFF;
         Serial.print(nx[j], HEX);
         Serial.print(" ");
      }
      Serial.println("");
      j = 0;
  }
}

And It worked!!!
I got the result expected, still...I'm not really sure why it didn't work with Software Serial.

Now the issue seems that some unnexpected values are getting printed.

The result I printed is:
D 0 21 0 3 3F 9 3 3E 0 1E A FFFFFFC6 FFFFFFAA

The result I expect is:
D 0 21 0 3 3F 9 3 3E 0 1E A C6 AA

So those FFFFFF are messing me up. I dont know where they come from.

1 Like