Skip to main content
Visitor II
July 28, 2021
Solved

How can we read/write using SPI

  • July 28, 2021
  • 6 replies
  • 5699 views

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

    This topic has been closed for replies.
    Best answer by Brian TIDAL

    Hi Antoine,

    thanks for using ST25R3916 IC.

    For you information, ST provides some firmware packages for the ST3916. This includes an NFC communication stack, full functional examples over SPI and low layer drivers. See The ST25 Embedded NFC library.

    Regarding your initial question, the direct commands values in table 13 of the ST25R3916 datasheet include the heading 11b. This simplifies the reading of logic analyzer traces as we have the direct value of the byte being sent.

    For example, here is the sending of Set default (C1h) command on SPI

    0693W00000D0xD1QAJ.jpgRgds

    BT

    6 replies

    Visitor II
    July 28, 2021

    Hi Antoine,

    If you do not understand how works registers/direct command you can check HydraNFC v2 Shield guide (it use a st25r3916)

    All is explained with example to read/write registers in Space A, Space B or send direct command over spi

    Regards,

    Benjamin

    ANaud.1Author
    Visitor II
    July 28, 2021

    Hi,

    I am sorry, but I do not understand more. I don't understand the syntax he use inside brackets, as it is not like in the ST25R3916 datasheet.

    He use letter like r to read, but don't explain what is r... Is the hexa in the left is the MSB or LSB.. Things like that.

    Thanks for the help,

    Antoine

    Visitor II
    July 28, 2021

    The HydraBus commands for SPI (or any other protocol) are described here

    https://github.com/hydrabus/hydrafw/wiki/HydraFW-SPI-guide#protocol-interaction-syntax-description

    https://github.com/hydrabus/hydrafw/wiki/Bus-interaction-commands

    To summarize

    [ Corresponds to Chip select(CS) enable/active (low=state 0/GND).

    ] Corresponds toChip select(CS) disable (high=state +3.3V).

    The value inside is in hexadecimal when it start with 0x

    ANaud.1Author
    Visitor II
    July 29, 2021

    Hi Ben,

    Thanks for your answer. Now I understand a lot more of the github document you sent me. I think it will help me for advancing on my project.

    Antoine

    Technical Moderator
    July 29, 2021

    Hi Antoine,

    thanks for using ST25R3916 IC.

    For you information, ST provides some firmware packages for the ST3916. This includes an NFC communication stack, full functional examples over SPI and low layer drivers. See The ST25 Embedded NFC library.

    Regarding your initial question, the direct commands values in table 13 of the ST25R3916 datasheet include the heading 11b. This simplifies the reading of logic analyzer traces as we have the direct value of the byte being sent.

    For example, here is the sending of Set default (C1h) command on SPI

    0693W00000D0xD1QAJ.jpgRgds

    BT

    ANaud.1Author
    Visitor II
    July 29, 2021

    Good morning Brian,

    Thanks! That should definitely help me. If we talk about only the read and write command. Do we still send 8 bits when reading/writing in block mode ? Can you show me an example of what a reading and a writing looks like ?

    For example, if I want to write for example in the register 00h. Do I still write 8 bits ? Because I need to write the 00b to say that I am writing, after the 00h address and the 8 bits of the data.

    If I want to read from this register, I only send 01b + the address 00h ?

    thanks again !

    Antoine

    Visitor II
    July 29, 2021

    Hi Antoine,

    If you are interested by full SPI capture of ST25R3916 reading different tags (including init) that I have done with PulseView see all the data here

    https://github.com/sigrokproject/sigrok-dumps/tree/master/nfc/st25r39xx

    You can load them with latest PulseView (as the st25r3916 decoder is officially integrated since few months now)

    Regards,

    Benjamin

    ANaud.1Author
    Visitor II
    July 30, 2021

    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

    Technical Moderator
    July 29, 2021

    Hi Antoine,

    here is an example of reading the IC identity register (3Fh):

    0693W00000D0zm0QAB.jpghere is an example of writing IO configuration register 2 (01b):

    0693W00000D101rQAB.jpg 

    Again, I would recommend to use the firmware provided on st.com. This manages the various SPI accesses and provides a user level API rather than a register based programming.

    Rgds

    BT

    Rgds

    BT

    ANaud.1Author
    Visitor II
    July 30, 2021

    Hi Brian,

    Thanks for your answer, I finally was able to communication with the ST25R3916 using SPI.

    The next step for me is to be able to transmit an information into a tag and read it back.

    In the datasheet of the chip, it say that I need to follow these steps:

    Preparation and execution of a transceive sequence:

    • Execute the direct command Stop all activities
    • Execute the direct command Reset RX gain
    • Configure the timers accordingly
    • Define the number of transmitted bytes in the Number of transmitted bytes register 1 and Number of transmitted bytes register 2
    • Write the bytes to be transmitted in the FIFO (not in the case of direct commands REQA and WUPA)
    • Send one of the commands Transmit with CRC, Transmit without CRC, Transmit REQA or Transmit WUPA
    • When all the data is transmitted an interrupt is sent to inform the microcontroller that the transmission is finished (IRQ due to end of transmission) 

    I did all these steps, but nothing show up in the FIFO register. I don't understand why. I check in the main IRQ register, an I have the bit set on the end of transmission IRQ, which is a good thing, but I still don't have any bits in my FIFO register.

    thanks for any help again,

    Antoine

    Technical Moderator
    August 2, 2021

    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