2022-10-04 07:28 AM
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
Solved! Go to Solution.
2022-10-07 07:06 AM
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:
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
2022-10-04 08:13 AM
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
2022-10-04 10:18 AM
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
2022-10-04 10:30 AM
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
2022-10-04 10:49 AM
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.
Thanks,
Adan
2022-10-04 11:32 PM
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
2022-10-05 11:47 AM
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
2022-10-06 02:33 AM
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
2022-10-07 07:06 AM
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:
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
2023-07-12 06:35 PM
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