2020-01-22 02:08 AM
hi,
I have connected cr95hf with ardunio uno, I am able to receive the response for IDN command correctly ,and set the protocol (ISO/IEC 14443-A) ,but the tag is not detecting, I have attached the code and response logs. I would like to know whats wrong with my code .I have taken the reference code code from the following link
https://community.st.com/s/global-search/cr95hf%20esp8266
I have have changed only protocol,and done the wiring as mentioned in the code
response in serial monitor:
Started
IDN COMMAND-
RESPONSE CODE: 0 LENGTH: 15
DEVICE ID: 4E 46 43 20 46 53 32 4A 41 53 54 34 0
ROM CRC: 2ACE
PROTOCOL SET-
NO TAG IN RANGE - RESPONSE CODE: 87
NO TAG IN RANGE - RESPONSE CODE: 87
NO TAG IN RANGE - RESPONSE CODE: 87
NO TAG IN RANGE - RESPONSE CODE: 87
NO TAG IN RANGE - RESPONSE CODE: 87
NO TAG IN RANGE - RESPONSE CODE: 87
some times Iam getting response as below,
#include <SPI.h>
const int SSPin = 10; // Slave Select pin
const int IRQPin = 2; // Sends wake-up pulse
byte TXBuffer[40]; // transmit buffer
byte RXBuffer[40]; // receive buffer
byte NFCReady = 0; // used to track NFC state
void setup() {
pinMode(IRQPin, OUTPUT);
digitalWrite(IRQPin, HIGH); // Wake up pulse
pinMode(SSPin, OUTPUT);
digitalWrite(SSPin, HIGH);
Serial.begin(9600);
Serial.println("Started");
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV32);
// The CR95HF requires a wakeup pulse on its IRQ_IN pin
// before it will select UART or SPI mode. The IRQ_IN pin
// is also the UART RX pin for DIN on the BM019 board.
delay(10); // send a wake up
digitalWrite(IRQPin, LOW); // pulse to put the
delayMicroseconds(100); // BM019 into SPI
digitalWrite(IRQPin, HIGH); // mode
delay(10);
}
void IDN_Command()
{
byte i = 0;
// step 1 send the command
digitalWrite(SSPin, LOW);
SPI.transfer(0); // SPI control byte to send command to CR95HF
SPI.transfer(1); // IDN command
SPI.transfer(0); // length of data that follows is 0
digitalWrite(SSPin, HIGH);
delay(1);
// step 2, poll for data ready
// data is ready when a read byte
// has bit 3 set (ex: B'0000 1000')
digitalWrite(SSPin, LOW);
while(RXBuffer[0] != 8)
{
RXBuffer[0] = SPI.transfer(0x03); // Write 3 until
RXBuffer[0] = RXBuffer[0] & 0x08; // bit 3 is set
}
digitalWrite(SSPin, HIGH);
delay(1);
// step 3, read the data
digitalWrite(SSPin, LOW);
SPI.transfer(0x02); // SPI control byte for read
RXBuffer[0] = SPI.transfer(0); // response code
RXBuffer[1] = SPI.transfer(0); // length of data
for (i=0;i<RXBuffer[1];i++)
RXBuffer[i+2]=SPI.transfer(0); // data
digitalWrite(SSPin, HIGH);
delay(1);
if ((RXBuffer[0] == 0) & (RXBuffer[1] == 15))
{
Serial.println("IDN COMMAND-"); //
Serial.print("RESPONSE CODE: ");
Serial.print(RXBuffer[0]);
Serial.print(" LENGTH: ");
Serial.println(RXBuffer[1]);
Serial.print("DEVICE ID: ");
for(i=2;i<(RXBuffer[1]);i++)
{
Serial.print(RXBuffer[i],HEX);
Serial.print(" ");
}
Serial.println(" ");
Serial.print("ROM CRC: ");
Serial.print(RXBuffer[RXBuffer[1]],HEX);
Serial.print(RXBuffer[RXBuffer[1]+1],HEX);
Serial.println(" ");
}
else
Serial.println("BAD RESPONSE TO IDN COMMAND!");
Serial.println(" ");
}
void SetProtocol_Command()
{
byte i = 0;
// step 1 send the command
digitalWrite(SSPin, LOW);
SPI.transfer(0x00); // SPI control byte to send command to CR95HF
SPI.transfer(0x02); // Set protocol command
SPI.transfer(0x02); // length of data to follow
SPI.transfer(0x02); // code for ISO/IEC 14443-A
SPI.transfer(0x00); // Wait for SOF, 10% modulation, append CRC
digitalWrite(SSPin, HIGH);
delay(1);
// step 2, poll for data ready
digitalWrite(SSPin, LOW);
while(RXBuffer[0] != 8)
{
RXBuffer[0] = SPI.transfer(0x03); // Write 3 until
RXBuffer[0] = RXBuffer[0] & 0x08; // bit 3 is set
}
digitalWrite(SSPin, HIGH);
delay(1);
// step 3, read the data
digitalWrite(SSPin, LOW);
SPI.transfer(0x02); // SPI control byte for read
RXBuffer[0] = SPI.transfer(0); // response code
RXBuffer[1] = SPI.transfer(0); // length of data
digitalWrite(SSPin, HIGH);
if ((RXBuffer[0] == 0) & (RXBuffer[1] == 0))
{
Serial.println("PROTOCOL SET-"); //
NFCReady = 1; // NFC is ready
}
else
{
Serial.println("BAD RESPONSE TO SET PROTOCOL");
NFCReady = 0; // NFC not ready
}
Serial.println(" ");
}
void Inventory_Command()
{
byte i = 0;
// step 1 send the command
digitalWrite(SSPin, LOW);
SPI.transfer(0x00); // SPI control byte to send command to CR95HF
SPI.transfer(0x04); // Send Receive CR95HF command
SPI.transfer(0x03); // length of data that follows is 0
SPI.transfer(0x26); // request Flags byte
SPI.transfer(0x02); // Inventory Command for ISO/IEC 14443-A
SPI.transfer(0x00); // mask length for inventory command
digitalWrite(SSPin, HIGH);
delay(1);
// step 2, poll for data ready
// data is ready when a read byte
// has bit 3 set (ex: B'0000 1000')
digitalWrite(SSPin, LOW);
while(RXBuffer[0] != 8)
{
RXBuffer[0] = SPI.transfer(0x03); // Write 3 until
RXBuffer[0] = RXBuffer[0] & 0x08; // bit 3 is set
}
digitalWrite(SSPin, HIGH);
delay(1);
// step 3, read the data
digitalWrite(SSPin, LOW);
SPI.transfer(0x02); // SPI control byte for read
RXBuffer[0] = SPI.transfer(0); // response code
RXBuffer[1] = SPI.transfer(0); // length of data
for (i=0;i<RXBuffer[1];i++)
RXBuffer[i+2]=SPI.transfer(0); // data
digitalWrite(SSPin, HIGH);
delay(1);
if (RXBuffer[0] == 128)
{
Serial.println("TAG DETECTED");
Serial.print("UID: ");
for(i=11;i>=4;i--)
{
Serial.print(RXBuffer[i],HEX);
Serial.print(" ");
}
Serial.println(" ");
delay(500);
}
else
{
Serial.print("NO TAG IN RANGE - ");
Serial.print("RESPONSE CODE: ");
Serial.println(RXBuffer[0],HEX);
}
Serial.println(" ");
}
void loop() {
if(NFCReady == 0)
{
IDN_Command(); // reads the CR95HF ID
delay(1000);
SetProtocol_Command(); // ISO 14443-A settings
delay(1000);
}
else
{
Inventory_Command();
delay(1000);
}
}
Started
IDN COMMAND-
RESPONSE CODE: 0 LENGTH: 15
DEVICE ID: 4E 46 43 20 46 53 32 4A 41 53 54 34 0
ROM CRC: 2ACE
BAD RESPONSE TO SET PROTOCOL
Started
Started
Started
BAD RESPONSE TO IDN COMMAND!
BAD RESPONSE TO SET PROTOCOL
Started
Started
Started
Started
Started
Started
Started
Started
Started
BAD RESPONSE TO IDN COMMAND!
BAD RESPONSE TO SET PROTOCOL
BAD RESPONSE TO IDN COMMAND!
BAD RESPONSE TO SET PROTOCOL
BAD RESPONSE TO IDN COMMAND!
PROTOCOL SET-
NO TAG IN RANGE - RESPONSE CODE: 87
NO TAG IN RANGE - RESPONSE CODE: 1C
NO TAG IN RANGE - RESPONSE CODE: 87
NO TAG IN RANGE - RESPONSE CODE: 0
NO TAG IN RANGE - RESPONSE CODE: 18
Solved! Go to Solution.
2020-01-23 06:27 AM
Hi
REQA/WUPA are part of the ISO14443-3 command set.
A complete polling loop example is provided in X-CUBE-NFC3. This includes the NFC-A/ISO14443-A technology detection and anti-collision.
Rgds
BT
2020-01-22 05:20 AM
Hi,
can you describe your HW enviroment e.g. X-NUCLEO-NFC03A1 board connected to Arduino or BM019 board connected to Arduino?
Inventory command is an ISO15693-3 command. ISO14443-A tags do not reply to Inventoty command but to REQA or WUPA commands.
Rgds
BT
2020-01-22 09:20 PM
Hi,
I have a custom board in which we have CR95HF Ic is interfaced with esp32d2wd ic, but I have soldered jumper wires for spi lines (miso mosi,ss,clk) and IRQ_IN, and connected to ardunio board I am able to receive the response to IDN command it means my wiring is correct and spi communication is working fine.can you provide any example code for detecting ISO14443-A tags , as you said that ISO14443-A tags do not reply to Inventoty command but to REQA or WUPA commands,what is REQA or WUPA commands ,can you provide any code with these commands
2020-01-23 06:27 AM
Hi
REQA/WUPA are part of the ISO14443-3 command set.
A complete polling loop example is provided in X-CUBE-NFC3. This includes the NFC-A/ISO14443-A technology detection and anti-collision.
Rgds
BT