cancel
Showing results for 
Search instead for 
Did you mean: 

How can we read/write using SPI

ANaud.1
Associate II

Hi,

I don't really understand the datasheet of the ST25R3916 IC chip.

At page 53, they show an exemple of a direct write command. As I understand, we need to send 1-1-C5-C4-C3-C2-C1-C0. When I check table 13 to see the command code that go for bits C5..C0, the hexa is something like C1 = 11000001. There is 8 bits on the command code and on page 53 they only send 6 bits. I am confused...

Same thing to read a register for example. We need to send 0-1- the register address. There is no register that are 6 bits long, so how can I write my SPI package?

Sorry if it is not clear, english is not my first language and I am still learning SPI communication, so it may seems easy, but I still don't get it :(

Thanks for any clarification.

Antoine

20 REPLIES 20

Hi Ben,

This is really helpfull, but is there a place that I can see what each communication is for and what it is doing ? There is a lot of communication going on and its hard to understand each one.

Thanks again,

Antoine

Hi Antoine,

Which tags are you trying to read? The default settings of the chip allow to access NFC-A tags (still analog configs are applied by our software to improve overall performance).

In its simplest incarnation the following should give you some data for an NFC-A tag on the antenna:

  1. POR
  2. Set register 02h -> 0xC8, wait 1ms. (This procedure is not recommended for production as you are outputting a field while starting oscillator which may create EM disturbances).
  3. Wait 5ms
  4. Send Direct command 0xC7 (Transmit WUPA). This will give you after some time 1Ah->0x38 and 1Eh->0x02 (2 bytes of ATQA in FIFO)

Best Regards, Ulysses

Repeating this sequence will only work every other time (due to Tag state machine!). For all other protocols you will need to perform additional changes (operating mode, AM/OOK, filter settings, reciever settings, ......)

Regards, Ulysses

Good morning Ulysses,

Thanks for your answer. I am trying to read an NFC-V tag (type 5) that was given in the ST25R3916 Discovery Kit. Is the procedure you gave me still the same for this type of tag ? What should I change to setup the device to be able to read NFC-V tags ? I didn't know that the default settings of the chip allow to access NFC-A tags. It is probably there why I wasn't able to setup propertly the device.

Thanks for your help,

Antoine

Hi Antoine,

reading NFC-V tags is one of the more complicated topics when using ST25R3911/16. Due to historical reasons the chips don't implement data framing for this protocol. NFC-V needs to be supported by means of using subcarrier stream mode. You will find some discussion here: register-settings-for-st25r3911b-for-iso-15693. Overall I recommend to build on existing code and not do everything on your own (you would need a high level of expertise on low level NFC protocols).

If I read it correctly then also Benjamin in his HydraNFC is relying on RFAL (https://hydrabus.com/hydranfc-shield-v2-specifications).

Best Regards, Ulysses

Hi Ulysses,

Yes I confirm RFAL is used and it even support the latest version (en.STSW-ST25RFAL002 V2.4.0 / 14-Jun-2021)

The firmware support mainly 2 modes (in fact it also support binary mode but I will do not speak about this ones here)

Both modes use RFAL both modes use a VT100 command line interface over USB Serial.

nfc mode:

dnfc mode:

The code is open source and available on github (see https://github.com/hydrabus/hydrafw_hydranfc_shield_v2/tree/master/src/hydranfc_v2) and it support HydraBus (using STM32F405 MCU) + HydraNFC v2 Shield (using ST25R3916)

Regards,

Benjamin

Hi Ulysses,

I tried using an NFC-A type 2 tag, with the code you write, using the WUPA direct command. Everything works fine. Now, I am trying to do it manually and here are the steps I used:

  • Write direct command C1 on the SPI bus.
  • Write to the register 0x02, 0xC8 on the SPI bus.
  • Wait 1s.
  • Write to the register 0x2, 0x08 to define on the register that I want to send 1 byte of data.
  • Write to the register Fifo load (0x80), 0x02.
  • Write the direct command 0xC5 to transmit without CRC check on the SPI bus.

After these commands, the chip should be in receiver mode and read the 0x02 bits I just sent. When I read the main register IRQ, I have the bit set on the oscillator stable (which is normal and ok) and on the end of transmission bit.

After that I read in the FIFO register and there is nothing in this register (0x00), it is like the antenna couldn't read anything from the tag.

What am I doing wrong here ? I followed all the steps..

thanks,

Antoine

Hi Antoine,

I presume you mean register 0x23 in step 4?!

Not sure why you think that a PCD byte of 0x02 (without CRC) would be interpreted and answered by an NFC-A type 2 tag? Also you cannot expect to receive in FIFO the same what you are sending....

In normal NFC-A/ISO14443-A 0x02 is only valid as a PCB on Layer4 (after full activation: WUPA - AC - SELECT - RATS). Even then it will need a CRC.

If you want to manually replicate the WUPA you will need to send a 0x52. And this 0x52 needs to be sent as 7 bits, not as 1 byte.

Best Regards, Ulysses

Good morning Ulysses,

I have done a few checks on my own and understand a lot more. I think I was doing it all wrong... For your question, yes it was a typo, it was 0x23 in step 4, sorry for that.

I am currently using an NFC NTAG213 from NXP. I've read the tag's datasheet and here's what I need to do:

  • Send WUPA
  • Send SELECT1
  • Send SELECT2
  • ...

Just so I understand and do it right, on the datasheet of the NTAG, they told me I need to write the command code 93h 70h (for select1), which is 2 bytes.

I then need to do the following:

  • Write direct command C1 on the SPI bus
  • Write to the register 0x02, 0xC8 on the SPI bus.
  • Wait 1s.
  • Write to the register 0x23, 0x10 to define on the register that I want to send 2 bytes of data.
  • Write to the register Fifo load (0x80), 93h 70h.
  • Write the direct command 0xC4 to transmit with CRC check on the SPI bus.
  • ... and so on for the SELECT2, etc.

Is that a good start ? Sorry for all my misunderstandings, I am a student and currently learning 🙂

Thanks again,

Antoine

Hi Antoine,

yes, about that. However please beware that before being able to send SELECT1, SELECT2 you want perform anticollison to get the UID part -> Sending 93 20 but without CRC, then handling collisions, etc. Otherwise you won't know the UID to send a proper select.

Also what you write as 1s will do, but after field on you need something like 5ms and later on you can shorten it to FDT of ~500us.

Best Regards, Ulysses

Hi Ulysses,

After sending 93h 20h, I try to read the fifo register using 9Fh 00h, but can't see anything. Is that normal? Is the command 93h 20h only resolve the UID by itself? I am confused by this part. And what do you mean by handling collisions?

thanks again for your time and patience,

Antoine