Write data into a defined page of the NFC shared memory

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Write data into a defined page of the NFC shared memory

Jump to solution
809 Views
Nobby
Contributor II

Hello,

I am using an NHS5132 and I want to write a measurement (float type) in a defined page of NFC shared memory. Let's say, directly at the start of the data page (page 4), without any additional information.

I can write information to the NFC shared memory but I cannot choose where it is stored. In the sample code I provide (see attached screenshot), I write to the NFC shared memory the value 1.23.

Then when I read the data using a reader (see attached image). As a result, the value 1.23 is only visible on the 8th and 9th of the NFC shared memory.

During my research I found this thread explaining that it is possible to write directly to a defined page

https://community.nxp.com/t5/NFC/Transmission-of-an-int-with-NDEF-NHS3152/m-p/849113

During the discussion, they said that it is possible to write directly to the target page of the NFC shared memory, by bypassing the NDFT2T module.

In their example, 123456789 was written directly in the 42 th page

NSS_NFC->BUF[42] = 123456789;

The problem is that the full code was not provided in their example. So I ask if it is possible to have the complete code? Or a more detailed description of the procedures?

Thank you in advance for your help.

Nobby

0 Kudos
1 Solution
796 Views
patrickgeens
NXP Apps Support
NXP Apps Support

Hello Nobby,

 

The example was not part of a bigger code block.

Data is interchanged with NFC by writing to and reading from a RAM-like buffer. Words written to this buffer will show up in NFC page reads, NFC page writes update the value in the buffer, which can be read by the ARM.

To write to the NFC memory at the lowest level (so NOT using NDEF messages), you need to:

1) enable the RAM overlay by writing 0 to the NFC CFG register: NSS_NFC->CFG = 0x0;
In this mode an uint32_t buffer, accessible via NSS_NFC->BUF, is mapped to NFC engine..
There is an offset of 4, for instance page 4 at the NFC side corresponds to location 0 in the buffer at the ARM side.

2) write the uint32_t value you want to make accessible via NFC to the overlay buffer: for instance after executing NSS_NFC->BUF[0] = 42; the value 42 will appear when doing an NFC page read of page 4.

3) you can also write a page via NFC, for instance at address P. The data can then be retrieved by the ARM by reading v = NSS_NFC->BUF[P-4];

For multi-page data you probably need some handshake protocol to tell the NFC host when the ARM was written all the data so it can retrieve the message as a whole. When using the NDEF code, this is done by writing an empty block header, then writing all the data behind it, then updating the header with the correct length. The NFC reader only starts reading the full message after the length becomes bigger than 0.

 

Kind regards,

Patrick

 

 

View solution in original post

4 Replies
757 Views
Nobby
Contributor II

Hi Patrick,

Thank you very much for the help.

It works perfectly.

I can write a string or a digital value into a defined page.

I can also write different pages at different a time without overwriting the first information.  

Kind regards

Nobby

0 Kudos
781 Views
Nobby
Contributor II

Hello Patrick,

Thank you for the explanation.

Where can I find the NSS_NFC register? Is it a parameter located inside a source file? 

If it is, where can I find the source file?

Or I have to create a pointer with the name NSS_NFC on the main program?

Thank you.

Kind regards

Nobby

0 Kudos
768 Views
patrickgeens
NXP Apps Support
NXP Apps Support

Hi Nobby,

 

Including "board.h" in you source file(s) does the job.
"board.h" includes "chip.h", where the NSS_NFC handle is defined.

You can also just #include "chip.h"

Example:

#include "board.h"

int main(void)
{
NSS_NFC->CFG = 0; // activate RAM overlay

// your code here


}

Kind regards,

Patrick

0 Kudos
797 Views
patrickgeens
NXP Apps Support
NXP Apps Support

Hello Nobby,

 

The example was not part of a bigger code block.

Data is interchanged with NFC by writing to and reading from a RAM-like buffer. Words written to this buffer will show up in NFC page reads, NFC page writes update the value in the buffer, which can be read by the ARM.

To write to the NFC memory at the lowest level (so NOT using NDEF messages), you need to:

1) enable the RAM overlay by writing 0 to the NFC CFG register: NSS_NFC->CFG = 0x0;
In this mode an uint32_t buffer, accessible via NSS_NFC->BUF, is mapped to NFC engine..
There is an offset of 4, for instance page 4 at the NFC side corresponds to location 0 in the buffer at the ARM side.

2) write the uint32_t value you want to make accessible via NFC to the overlay buffer: for instance after executing NSS_NFC->BUF[0] = 42; the value 42 will appear when doing an NFC page read of page 4.

3) you can also write a page via NFC, for instance at address P. The data can then be retrieved by the ARM by reading v = NSS_NFC->BUF[P-4];

For multi-page data you probably need some handshake protocol to tell the NFC host when the ARM was written all the data so it can retrieve the message as a whole. When using the NDEF code, this is done by writing an empty block header, then writing all the data behind it, then updating the header with the correct length. The NFC reader only starts reading the full message after the length becomes bigger than 0.

 

Kind regards,

Patrick