RFID rs232 serial communication to arduino uno

Hello, everyone.
I'm working with a RFID reader and according to the user's manual, I can connect through a host so I decided to use an Arduino UNO.

So the manual suggests to connect with a 57600bps with one start bit, 8 data bits and 1 stop bit without a parity check bit. In the process, the least significant bit of one byte is transmited first.

The procedure is the Host (Arduino) to send a command and data to the reader, then the reader returns a result status and data to the host after command execution.

Right now, I'm sendig the next command (Picture CommandAndRespond)

So my code looks like this:

#include <AltSoftSerial.h>
#include <SoftwareSerial.h>

#define UInt16 uint16_t

SoftwareSerial antenna(8, 9);

unsigned char data;

char *s = (char *)"040021";

void setup() {
  
  Serial.begin(9600);
  antenna.begin(57600);
  Serial.println("Starting");
  delay(1000);
  Serial.println(ModRTU_CRC(t,strlen(t)),HEX);
  Serial.println(uiCrc16Cal(s,strlen(s)),HEX);
  delay(1000);
  sendCommand();
}

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

  antenna.print(0x04); //Length
  antenna.print("\t");
  antenna.print(0x00); //Address
  antenna.print("\t");
  antenna.print(0x21); //Command
  antenna.print("\t");
  antenna.print(0x25); //CRC-LSB
  antenna.print("\t");
  antenna.print(0x59); //CRC-MSB
  antenna.print("\t");

   delay(15);
  
}


void loop() {

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

}

But the respond I get are indeed, 13 bytes. But not the one I'm looking for:
FF FE FF FF FC FF FE FF FE FF FE FC FF

when I should get:
0D 00 21 00 data data data data data data data 25 53
Ideally.

So I'd like to see if someone could check the code, perhaps I missed something.

If you need more info, feel free to ask me, that includes the whole user's manual with more commands and info for the protocol

Hope you can help, thanks

ErickDLCruz:
If you need more info, feel free to ask me, that includes the whole user's manual with more commands and info for the protocol

You should post such things in your first post so we don't have to waste time and energy asking for it.

char *s = (char *)"040021";

What?

Why not:

char s[] = ['0', '4', '0', '0', '2', '1'];

Also, change

  antenna.print(0x04); //Length
  antenna.print("\t");
  antenna.print(0x00); //Address
  antenna.print("\t");
  antenna.print(0x21); //Command
  antenna.print("\t");
  antenna.print(0x25); //CRC-LSB
  antenna.print("\t");
  antenna.print(0x59); //CRC-MSB
  antenna.print("\t");

to

  antenna.write(0x04); //Length
  antenna.write('\t');
  antenna.write(0x00); //Address
  antenna.write('\t');
  antenna.write(0x21); //Command
  antenna.write('\t');
  antenna.write(0x25); //CRC-LSB
  antenna.write('\t');
  antenna.write(0x59); //CRC-MSB
  antenna.write('\t');

This is because you need to be sending binary, not ASCII chars.

Also, no need to include

#include <AltSoftSerial.h>

if you aren't using it.

Thanks for your time Power_Broker.

I added the protocol info if you want to give it a check.

With all the changes suggested, It won't respond the expected one.

It might be the CRC-16, but not sure. Is there anyway to get the HEX from a CRC16 result? All I found is the process from HEX to CRC

Forgot to mention, the code for the CRC is on another tab, but the code is exactly as the user's manual is:

#define PRESET_VALUE 0xFFFF
#define POLYNOMIAL  0x8408 //8408
unsigned int uiCrc16Cal(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;
}

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