cancel
Showing results for 
Search instead for 
Did you mean: 

ST25R3914 Read/Write to Tag

APant.2
Associate III

All,

I would like to first begin with saying thank you for your time in attempting to assist me.

I am attempting to read and write from/to a tag; more specifically a Type-2 and Type-4. I have been looking through example code which uses the same library as me and stumbled across the following code, shown in nfcDataExchange.png. I have been using the code to try and read/write from/to a tag, but I haven't had much success.

Google doesn't seem to be useful for this either, since I only stumble across posts explaining the structure of a NFC Data Exchange Frame (NDEF), but from what I know T2T and T4T tags require different payload structures.

So my question is, are there documents available that show how to read/write to a tag and also how to structure the tx buffer depending on the tag type? or is someone willing to explain this to me? or can someone point me in the right direction?

Also, given that the example code I looked at had the code shown in the png, I am assuming this is the correct route to take when reading/writing. Can someone confirm this?

Thanks,

Adan

1 ACCEPTED SOLUTION

Accepted Solutions
APant.2
Associate III

Hi Ulysses,

Thank you for your feedback. Given that I do not have much experience with NFC, all of this is a learning process.

With regard to my original post, I thank you Ulysses for pointing me in the right direction. I am able to read and write to a Type2 tag; although I am having issues with a Type4, but I think it's due to a bad tag.

If anyone else wants to know how to do this follow the steps below:

  1. MUST: Make sure your RFAL library is working correctly. This means it has been implemented and you are able to detect tags with your software.
  2. Download the ST25 embedded NFC library.
  3. Extract the NDEF middleware library and add it to your program. Assuming you don't have it already.
  4. Open the ndef.chm document located in NDEF/doc.
  5. Copy the example program ndef_example_read.c into your code.
  6. Verify you can actually read from a tag. Then try the write example.
  7. Now that the basic functionality has been verified, rework the program to add your own spin to it.

I hope this helps. I do want to finish with saying I am using a ST25R3914 chip. So if someone is using something different, I assume the process will be the same, but I am not 100% sure.

Thanks,

Adan

View solution in original post

12 REPLIES 12
Ulysses HERNIOSUS
ST Employee

Hi Adan,

The RFAL you are using allows to exchange arbitrary frames in the supported technologies. The code snippet you are showing is for that. The command set of different tags is very much different. You are mentioning T2T and T4T. These are names defined by NFC Forum, T2T defines a rather low level interface based on writing single blocks of memory. T4T is based on smart card (iso7816-4) interfaces.

Once these tags are formatted properly our ST25 Embedded NFC lib (https://www.st.com/en/embedded-software/stsw-st25r-lib.html) contains Middlewares supporting to read and write NDEF from it.

Best Regards, Ulysses

APant.2
Associate III

Hi Ulysses,

Thank you for your reply.

Just so I am understanding you correctly, you are saying that the function I am using is correct because it allows me to send variable length payloads. This is useful since I can use a single function to interface with either a T2 or T4 tag. Are you then saying that the middleware within the library you linked can then be used to encode/decode the data that is sent/received?

Thanks,

Adan

Hi Adan,

our so-called ndef middleware does more than just encoding/decoding ndef byte arrays. It knows also all the procedures to read and write T2T, T3T, T4T and T5T. I.e. which functions to use for read and write and finding out the memory size, interpreting the CC (capability container), etc.

The interface to rfal is something like the functions you just showed (+ISODEP in case of T4T).

Best Regards, Ulysses

APant.2
Associate III

Ulysses,

That makes sense. The ndef middleware contains all the routines needed for reading/writing, etc. to any tag. After looking through the source code of the library you linked, two things are confusing me.

  1. The library I am using does not come with the middleware, but it does contain the following files, rfal_t1t.c, rfal_t2t.c, and rfal_t4t.c. I'm assuming these contain interfaces to the middleware? Also, if the files mentioned are different then the middleware, I would have to import it to my current project.
  2. You mention that the functions I showed are interfaces to the rfal, but after looking at the ndef middleware, I'm under the assumption I need to use those functions to read/write from/to a tag instead. Is this correct?

Thanks,

Adan

Hi Adan,

ad 1) correct, rfal_t*t.h are used by the ndef middleware to perform read/write. Following NFC Forum document structure they may more belong into ndef middleware but are also useful if actual ndef tags and content are not a target.

ad 2) Our middleware ndef are calling functions inside rfal_t*t.h. The functions in rfal_t*t.c are calling the API you have shown.

Please also see AN5616: NDEF library.

Best Regards, Ulysses

APant.2
Associate III

Ulysses,

I understand now. I looked through the documentation you've sent, included the NDEF library within my project, and have been able to successfully read from a tag. I will try to write, but I'm going to assume I won't have any issues. 

There was one issue I had and maybe you can guide me through the proper solution. When I tried to read from a Type-2 tag, it kept failing at the ndefPollerNdefDetect function with a return of 5 (ERR_REQUEST). After further debugging, I came to the assumption that it failed because there wasn't a valid NDEF record on the tag. To validate my theory, I downloaded an app on my phone, wrote 'Hello' to the tag, and tried reading it with my program. After this, my program worked without a problem; I could read the data back. So my question is, what is the best route to take when you encounter a tag that doesn't have a valid ndef record. Do I write one with my phone, or can the library handle this.

I did see that the library had this function - ndefPollerTagFormat, so I'm assuming it could.

Thanks,

Adan

Hi Adan,

for formatting tags NFC Forum does not prescribe the procedures. So if using ndefPollerTagFormat() user should provide all relevant information (ndefCapabilityContainer *cc) which need to fit the tag. For some tags (e.g. T5T ) automatics are provided where we implement routines to inquire memory size, etc.

In my opinion you should only format tags which you have clearly identified before (manufacturer + exact model) and where you have a good idea how it should be formatted. On some tags the format procedure is even irreversible (some T2T).

Best Regards, Ulysses

APant.2
Associate III

Hi Ulysses,

Thank you for your feedback. Given that I do not have much experience with NFC, all of this is a learning process.

With regard to my original post, I thank you Ulysses for pointing me in the right direction. I am able to read and write to a Type2 tag; although I am having issues with a Type4, but I think it's due to a bad tag.

If anyone else wants to know how to do this follow the steps below:

  1. MUST: Make sure your RFAL library is working correctly. This means it has been implemented and you are able to detect tags with your software.
  2. Download the ST25 embedded NFC library.
  3. Extract the NDEF middleware library and add it to your program. Assuming you don't have it already.
  4. Open the ndef.chm document located in NDEF/doc.
  5. Copy the example program ndef_example_read.c into your code.
  6. Verify you can actually read from a tag. Then try the write example.
  7. Now that the basic functionality has been verified, rework the program to add your own spin to it.

I hope this helps. I do want to finish with saying I am using a ST25R3914 chip. So if someone is using something different, I assume the process will be the same, but I am not 100% sure.

Thanks,

Adan

om0moo
Associate II

Hi Adan,

Sorry for interrupting this topic, also with the ST25R3911B, how can I read the data recorded in the type 4 NFC tag (specifically, the citizen ID card), I'm using the ST25R3911B NFC board Board, please help me

Thanks,

Khoa