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

1 ACCEPTED SOLUTION

Accepted Solutions
Brian TIDAL
ST Employee

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

20 REPLIES 20
ben_hw_sw
Associate II

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

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

ben_hw_sw
Associate II

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

Brian TIDAL
ST Employee

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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

ANaud.1
Associate II

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

ben_hw_sw
Associate II

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

Brian TIDAL
ST Employee

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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