Example application for the X-Nucleo-NFC01A1 Dynamic NFC Tag board.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of HelloWorld_NFC01A1 by
X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board Firmware Package
Introduction
This firmware package includes Components Device Drivers, Board Support Package and example applications for STMicroelectronics X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board based on M24SR.
Example Application
This is just a simple "hello world" style program for the X-NUCLEO-NFC01A1 Dynamic NFC Tag Expansion Board. The program writes a URI link to the M24SR dynamic tag using the synchronous programming model. The URI can then be retrieved from an NFC enabled smartphone/tablet.
A more complex example providing asynchronous access to the tag is also available.
Revision 23:05ef41b77f9b, committed 2017-07-12
- Comitter:
- Davidroid
- Date:
- Wed Jul 12 14:22:42 2017 +0000
- Parent:
- 22:6381693f9d9a
- Child:
- 24:6a1c5b9cfaeb
- Commit message:
- Updated to fit ARM coding style.
Changed in this revision
--- a/NDefLib.lib Tue Jul 11 10:00:16 2017 +0000 +++ b/NDefLib.lib Wed Jul 12 14:22:42 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/NDefLib/#13d84b136a62 +https://developer.mbed.org/teams/ST/code/NDefLib/#31f727872290
--- a/X_NUCLEO_NFC01A1.lib Tue Jul 11 10:00:16 2017 +0000 +++ b/X_NUCLEO_NFC01A1.lib Wed Jul 12 14:22:42 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_NFC01A1/#9fc4f9195d28 +https://developer.mbed.org/teams/ST/code/X_NUCLEO_NFC01A1/#b76765d2cc68
--- a/main.cpp Tue Jul 11 10:00:16 2017 +0000
+++ b/main.cpp Wed Jul 12 14:22:42 2017 +0000
@@ -36,7 +36,6 @@
*/
#include "mbed.h"
-
#include "XNucleoNFC01A1.h"
#include "NDefLib/NDefNfcTag.h"
#include "NDefLib/RecordType/RecordURI.h"
@@ -46,12 +45,12 @@
* Write an NDef message with a Uri record linking the st.com site
* @param nfcNucleo expansion board where write the NDef message
*/
-static void write_url(XNucleoNFC01A1 *nfcNucleo){
+static void write_url(XNucleoNFC01A1 *nfcNucleo) {
//retrieve the NdefLib interface
NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag();
//open the i2c session with the nfc chip
- if(tag.open_session()){
+ if (tag.open_session()) {
printf("Session opened\n\r");
nfcNucleo->get_led1()=1;
@@ -61,23 +60,24 @@
msg.add_record(&rUri);
//write the tag
- if(tag.write(msg)){
+ if (tag.write(msg)) {
printf("Tag written\n\r");
nfcNucleo->get_led2()=1;
- }else{
+ } else {
printf("Error writing \n\r");
}//if-else
//close the i2c session
- if(tag.close_session()){
+ if (tag.close_session()) {
printf("Session closed\n\r");
nfcNucleo->get_led3()=1;
- }else{
+ } else {
printf("Error closing the session\n\r");
}//if-else
- }else
+ } else {
printf("Error opening the session\n\r");
+ }
}
/**
@@ -85,24 +85,24 @@
* the message
* @param nfcNucleo expansion board from where read the message
*/
-static void read_url(XNucleoNFC01A1 *nfcNucleo){
+static void read_url(XNucleoNFC01A1 *nfcNucleo) {
//retrieve the NdefLib interface
NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag();
//open the i2c session with the nfc chip
- if(tag.open_session()){
+ if (tag.open_session()) {
printf("Session opened\n\r");
- nfcNucleo->get_led1()=1;
+ nfcNucleo->get_led1() = 1;
//create the NDef message and record
NDefLib::Message msg;
//read the tag
- if(tag.read(&msg)){
+ if (tag.read(&msg)) {
const uint32_t nRecords = msg.get_N_records();
- printf("Tag read: %d record\n\r",msg.get_N_records());
- for(int i =0 ;i<nRecords ;i++){
- if(msg[i]->get_type()== NDefLib::Record::TYPE_URI){
+ printf("Tag read: %d record\n\r", msg.get_N_records());
+ for (int i =0 ;i<nRecords ;i++) {
+ if (msg[i]->get_type()== NDefLib::Record::TYPE_URI) {
NDefLib::RecordURI *rUri = (NDefLib::RecordURI *)msg[i];
printf("UriType: %x\n\rUriContent: %s\n\r",
rUri->get_uri_id(),
@@ -111,20 +111,21 @@
}//for
//free the read records
NDefLib::Message::remove_and_delete_all_record(msg);
- }else{
+ } else {
printf("Error Reading \n\r");
}//if-else
//close the i2c session
- if(tag.close_session()){
+ if (tag.close_session()) {
printf("Session closed\n\r");
- nfcNucleo->get_led3()=1;
- }else{
+ nfcNucleo->get_led3() = 1;
+ } else {
printf("Error closing the session\n\r");
}//if-else
- }else
+ } else {
printf("Error opening the session\n\r");
+ }
}
static volatile bool buttonPress=false;
@@ -143,9 +144,9 @@
//use default board pinout
I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN);
XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel,NULL,
- XNucleoNFC01A1::DEFAULT_GPO_PIN,XNucleoNFC01A1::DEFAULT_RF_DISABLE_PIN,
- XNucleoNFC01A1::DEFAULT_LED1_PIN,XNucleoNFC01A1::DEFAULT_LED2_PIN,
- XNucleoNFC01A1::DEFAULT_LED3_PIN);
+ XNucleoNFC01A1::DEFAULT_GPO_PIN,XNucleoNFC01A1::DEFAULT_RF_DISABLE_PIN,
+ XNucleoNFC01A1::DEFAULT_LED1_PIN,XNucleoNFC01A1::DEFAULT_LED2_PIN,
+ XNucleoNFC01A1::DEFAULT_LED3_PIN);
printf("System Init done: !\n\r");
@@ -157,7 +158,7 @@
InterruptIn userButton(USER_BUTTON);
userButton.fall(set_button_press);
while(true){
- if(buttonPress){
+ if (buttonPress) {
read_url(nfcNucleo);
buttonPress=false;
}//if
@@ -168,3 +169,6 @@
read_url(nfcNucleo);
#endif
}
+
+
+/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

X-NUCLEO-NFC01A1 Dynamic NFC Tag