SPI communication with CR95HF on ESP8266
I create a new thread related to this with more detailed information. First of all thanks for the response, I had seen the datasheet of BM019 not the one of CR95HF which is quite more complete. Second the logic analyzer I use is Pulseview it allows me to export the capture data, I attach 2 session data, one for Arduino and the same schedule in esp8266.
My main code is quite similar to the official code of the BM019 sensor for Arduino, I do many other things for processing data but read with the sensor is basically the same. I'm going to focus on the 3 step necessaries to read the tag.
First of all is necessary send a setProtocol command in order to get the NFC ready, this works fine on both boards.
The command I send (but I test with many other commands) is the inventory command, if NFC is in range they read the data. According to the official documentation, sending a command requires 3 steps. First step is sending via SPI a predefined bytes that represents the command in the case of inventory they are the following.
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(0x01); // Inventory Command for ISO/IEC 15693
SPI.transfer(0x00); // mask length for inventory command
digitalWrite(SSPin, HIGH);This part works well on both Arduino and ESP8266. Then is needed a loop polling for data ready, basically is send a 0x03 until MISO 4th bit is set.
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);And the last step is get the response code sending a 0x02, 0x00 and 0x00.
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);In the case of setCommand the response code must be 0 for the inventoy command a good response is 128, in the code I also made Serial.print(RXBuffer[0], HEX); to print the response code.
Now the difference I see in then behaviour of both boards, the difference in the code is only the SSPin and the rest of pin for the SPI protocol that obviously are not the same in Arduino and ESP8266. What I see in the logic analyzer is for arduino in the step 2 makes a bunch of iterations sending 3 until gets an 0x0E and breaks the loop. In the esp8266 only one iteration and gets 0x0E. After that, the step 3 for and inventory command when the sensor is not in range the response code is x87, here is when the things are getting weird.
I can see and x87 as response in the logic analyzer in both boards but when I do the Serial.print(RXBuffer[0], HEX); I see and 0x0E on the esp8266, compare 0x87 with 0x0E in binary are 00001110 and 10000111, it is possible that there are an offset of 1 bit, maybe related with the flank detection of the clock that makes happen this? These maybe explains why only one iteration is made in the polling loop and the setCommands works because the response code is 0.
The frecuency is the same for arduino and esp8266, on Arduino the default speed is 16Mhz and I use SPI_CLOCK_DIV32 so the frecuency is 500Khz and on esp8266 I directly set it with SPI.setFrecuency() (also checked on the logic analyzer)
I can see that on Arduino MISO and MOSI are High by default, unlike the esp8266 but I think that I mustn't bother about these outputs when the SS is High
NOTE: in the logic analyzer inputs are the following
D4: CLK
D5: MISO
D6: MOSI
D7: CS - active low
Thanks in advice
