RFID - CRC parameters, how to calculate them?

Hi! I have problems with reading RFID tags.
The code I'm using is this:

int dato=1, inByte;
void setup() {
    // initialize both serial ports:
    Serial.begin(115200);
    Serial1.begin(57600);
    Serial.println("read = 1");
}
void loop() {
    if (Serial.available()) {
        dato = Serial.read();
    }
    switch(dato){
        case '1':
        dato=0;
        Serial.print("pin E= ");

        Serial1.write(0x04);
        Serial1.write(0x00);
        Serial1.write(0x01);
        Serial1.write(??); // What are the data belonging to these fields?
        Serial1.write(??); // What are the data belonging to these fields?
        
        Serial.println(" espera");

        break;
    }
}

void serialEvent1() {
    if (Serial1.available()) {
        inByte = Serial1.read();
        Serial.print(inByte,HEX);
        Serial.print(" ");
    }
}

and returns: 5 0 0 FE 87 73
According to the manual, the problem is in the CRC, how can I fix it?
How to calculate the parameters for the command "MSB-CRC16" and "LSB-CRC16"?

Thanks for your feedback.

Hi! I have problems with reading RFID tags.

You have more than that. You have not explained what Serial and Serial1 are connected to.

If Serial is connected to the PC, and you are sending data to the Arduino from the Serial Monitor, to tell the Arduino to deal with Serial1, you then WRITE to the Serial1 instance, where, presumably, the RFID reader is. What does that have to do with reading RFID tags?

So, you need to clarify what is connected to what.

Hi PaulS, thanks for your interest.
1 - The reader is connected to a arduino mega 2560 on port serial1 (pins 18 y 19).
2 - Through the serial port of the Arduino, RFID module prints the response in the computer.
3 - The RFID module returns a problem with the values ??of "CRC-16LSB" and "CRC-16MSB"
4 - I would like to know how I can calculate or know the "CRC-16LSB" values ??and "CRC-16MSB"?

Thank you for your help.

Attachment the datasheet and the manufacturer's link

MU5110 _eng.pdf (103 KB)

RFID module prints the response in the computer.

No, it doesn't. The RFID module can NOT print data to the computer. It can make data available to the Arduino which can print it to the serial port that the PC is on the other end of.

What are you writing to the RFID reader? Why are you writing to the RFID reader?

Hello Pauls

The module is connected as you say to Arduino and Arduino screen printed on the PC by serial port, as you can see in the code.
When sending commands that are in the manual towards RFID module, it responds the values ??shown in the image, as the manual says there is an error in the CRC values??.
My question is: How can I calculate values ??for CRC-16, which must go in the last 2 bytes of the command of RFID?

Hola paulS

El modulo esta conectado como usted dice a Arduino, y Arduino imprime en la pantalla del PC por puerto serial, como se puede ver en el código.
Al enviar los comandos que están en el manual hacia el modulo RFID, este responde los valores que se muestran en la imagen, según el manual, dice que hay un error en los valores de CRC.
Mi pregunta es: ¿Cómo puedo calcular los valores de CRC-16, que deben ir en los últimos 2bytes del comando del RFID?

MU5110 UHF RFID Reader User’s Manual V1.20.doc (556 KB)

MU5110 _eng.doc (78.5 KB)

Page 6 of the user's manual has exactly the code you need to generate the CRC.

Pete

no funciona y tampoco funciona el polinomio característico que se muestra hay.

does not work and neither does the characteristic polynomial shown there.

Works for me.
You’re doing something wrong. Post your code - in tags.

Pete

int dato=1, inByte;
void setup() {
    // initialize both serial ports:
    Serial.begin(115200);
    Serial1.begin(57600);
    Serial.println("read = 1");
}
void loop() {
    if (Serial.available()) {
        dato = Serial.read();
    }
    switch(dato){
        case '1':
        dato=0;
        Serial.print("pin E= ");

        Serial1.write(0x04);
        Serial1.write(0x00);
        Serial1.write(0x01);
        Serial1.write(??); // What are the data belonging to these fields?
        Serial1.write(??); // What are the data belonging to these fields?
        
        Serial.println(" espera");

        break;
    }
}

void serialEvent1() {
    if (Serial1.available()) {
        inByte = Serial1.read();
        Serial.print(inByte,HEX);
        Serial.print(" ");
    }
}

Hi!, el_supremo
Here's the code I am using. Please can you post the code you are using and how you do work.
Thanks you.

Hola, el_supremo
Este es el código que estoy utilizando. Por favor, puedes publicar el código que usas y como lo haces funcionar.
Gracias.

does not work and neither does the characteristic polynomial shown there.

How do you know that? The code you posted doesn't contain that CRC code from the user's manual.

Pete

hello

I tested this polynomial is in the manual in a ise in matlab code that did not work and I "crc.m"

another code to see if I could find the polynomial with the message that sends back the RFID "intcrc.m"

I attached the code to that revices and I say if there is a problem
I hope your answer thanks

hola

yo probe ese polinomio que esta en el manual en un codigo que ise en matlab y no me funciono "crc.m"

otro codigo para ver si podia encontrar el polinomio con el mensaje que manda de regreso el RFID "intcrc.m"

te adjunto el codigo para que lo revices y me dices si hay algun problema
gracias espero tu respuesta

crc.m (705 Bytes)

intcrc.m (998 Bytes)

Why did you use Matlab at all? Copy the example from page of the manual into your Arduino sketch and use that. It works without modification.

Pete

hello
could you make me an example in arduino I can try here?
thanks

unsigned char rfid[4] = {
  5, 0, 0, 0xFE
};

unsigned char test[3] = {
  4, 0, 1
};

void setup()
{
  uint16_t crc_out;
  Serial.begin(9600);
//  while(!Serial);
//  delay(1000);
  
  // See: http://forum.arduino.cc/index.php?topic=235918.0
  // and see the user's manual in reply #4 for the code to
  // calculate the CRC on page 6
  // pass in the address of the bytes to be processed for a CRC
  // and the the number of bytes. In this case I used the four
  // bytes shown in the example in the thread at the URL above
  // and there are 4 bytes. The code prints the correct CRC (7387)
  crc_out = rfid_crc16(rfid,4);
  
  // NOTE that this prints the result in the order MSByte LSByte
  // but you must send them in the order LSByte and then MSByte
  // This prints the CRC as 0x7387 but you would
  // send it as 0x87 0x73
  Serial.print(crc_out,HEX); //(expecting = 0x7387)
Serial.println(" rfid");
Serial.println("");
  // generates 0x4BDB
  crc_out = rfid_crc16(test,3);
  Serial.print(crc_out,HEX);
Serial.println(" test");
}

void loop()
{
}

// This is exactly the code from page 6
#define PRESET_VALUE 0xFFFF
#define POLYNOMIAL  0x8408
unsigned int rfid_crc16(unsigned char const *pucY, unsigned char ucX)
{
  unsigned char ucI,ucJ;
  unsigned short int  uiCrcValue = PRESET_VALUE;

  for(ucI = 0; ucI < ucX; ucI++) {
    uiCrcValue = uiCrcValue ^ *(pucY + ucI);
    for(ucJ = 0; ucJ < 8; ucJ++) {
      if(uiCrcValue & 0x0001) {
        uiCrcValue = (uiCrcValue >> 1) ^ POLYNOMIAL;
      } 
      else {
        uiCrcValue = (uiCrcValue >> 1);
      }
    }
  }
  return uiCrcValue;
}

The first test uses the data from the example that you have circled in RFID.jpg which you attached to your first post. The data are the four bytes 5, 0, 0, 0xFE and the example shows the CRC as 87 73. The program prints 7387 becuase it prints the MSB (73) first whereas you must send the LSByte first to the RFID device.

The second test uses the data from the code in your first post: 4, 0, 1 and the result shows that the CRC is 0x4BDB which you would have to send as 0xDB and then 0x4B.

Pete

hello
thank you very much and I run
thanks

Hello, El_Supremo.

I’m having a problem with the same reader.

This is the code I’m implementing

#include <SoftwareSerial.h>

SoftwareSerial antenna(8, 9);

unsigned char data;
const int com_len = 9;
unsigned char command[com_len] = { 0x0a, 0x00, 0x35, 0x01, 0x06, 0x04, 0x00, 0x01, 0x05 };

void setup() { 
  Serial.begin(115200);
  Serial.println("Starting");
  antenna.begin(57600);
  delay(100);
  Serial.println(crc_cal(command,com_len),HEX);
  sendCommand();
}

void sendCommand() {
  Serial.println("Sending...");

  antenna.write(0x0a); //Length
  antenna.write(byte(0x00)); //Address
  antenna.write(0x35); //Command
  antenna.write(0x01); //Active mode
  antenna.write(0x06); //RS232 Output
  antenna.write(0x04); //Memory intentory
  antenna.write(byte(0x00)); //First address
  antenna.write(0x01); //Word number
  antenna.write(byte(0x05)); //Tag time
  antenna.write(0xEB); //CRC-LSB
  antenna.write(0x8F); //CRC-MSB
}

void loop() { 
 while(antenna.available()) {
  data = antenna.read();
  Serial.print(data, HEX);
  Serial.print(" ");
 }

}

But the respond from the reader is not the one I want:
FC FC F8 FE F8 FC F8 F8 F8 FC FF

Also, according to the command I’m sending (Page 35-36) I tried to put the buzzer off to see if the command was right but no good results.

So perhaps I’m missing something I’m not aware of.

Mind helping out?

Thanks

The CRC in your code is correct but I can’t find any documentation of the 0x35 command. The manual in message #4 does not have a 0x35 command and it also doesn’t have pages 35-36. Which manual has those pages?

Pete

Oh, since the CRC code was exactly the same, I assumed that the manual was the same.

This is the one I’m using. This one has the protocol guide for the communication

For more information, the reader is a ZK-RFID102.

http://www.zk-rfid.com/en/product_show.php?id=39&lm=6

Thanks for your time,

Erick

RRU1861 UHF RFID Reader User’s Manual V2.0.doc (889 KB)

The CRC is correct and the message looks valid, so at worst the reader should have returned an error message. The garbled response you’re getting suggests that the reader is not wired correctly.

Pete