Complete mbed library/workspace for HelloWorld_NFC02A1

Dependencies:   NDefLib X_NUCLEO_NFC02A1 mbed

Fork of HelloWorld_NFC02A1 by ST Expansion SW Team

X-NUCLEO-NFC02A1 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-NFC02A1 Dynamic NFC Tag Expansion Board based on M24LR.

Example Application

This is just a simple "hello world" style program for the X-NUCLEO-NFC02A1 Dynamic NFC Tag Expansion Board. The program writes a URI link to the M24LR dynamic tag using the synchronous programming model. It then reads back the URI from the tag to display it on terminal. The URI can also be retrieved from an NFC enabled smartphone/tablet.

Committer:
rosarium
Date:
Fri Sep 30 11:46:24 2016 +0000
Revision:
8:9bdd16ebccfb
Parent:
7:699836375630
Child:
9:0bd2f0c13d3d
Read bug fix and some sync of status codes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rosarium 0:892175366555 1 /**
rosarium 0:892175366555 2 ******************************************************************************
rosarium 0:892175366555 3 * @file main.cpp
rosarium 1:11ae12d41082 4 * @author AMG Central Lab
rosarium 0:892175366555 5 * @version V1.0.0
rosarium 1:11ae12d41082 6 * @date 30 Aug 2016
rosarium 0:892175366555 7 * @brief This demo writes an ndef message with an url inside.
rosarium 0:892175366555 8 ******************************************************************************
rosarium 0:892175366555 9 * @attention
rosarium 0:892175366555 10 *
rosarium 1:11ae12d41082 11 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
rosarium 0:892175366555 12 *
rosarium 0:892175366555 13 * Redistribution and use in source and binary forms, with or without modification,
rosarium 0:892175366555 14 * are permitted provided that the following conditions are met:
rosarium 0:892175366555 15 * 1. Redistributions of source code must retain the above copyright notice,
rosarium 0:892175366555 16 * this list of conditions and the following disclaimer.
rosarium 0:892175366555 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
rosarium 0:892175366555 18 * this list of conditions and the following disclaimer in the documentation
rosarium 0:892175366555 19 * and/or other materials provided with the distribution.
rosarium 0:892175366555 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
rosarium 0:892175366555 21 * may be used to endorse or promote products derived from this software
rosarium 0:892175366555 22 * without specific prior written permission.
rosarium 0:892175366555 23 *
rosarium 0:892175366555 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
rosarium 0:892175366555 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
rosarium 0:892175366555 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
rosarium 0:892175366555 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
rosarium 0:892175366555 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
rosarium 0:892175366555 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
rosarium 0:892175366555 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
rosarium 0:892175366555 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
rosarium 0:892175366555 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
rosarium 0:892175366555 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
rosarium 0:892175366555 34 *
rosarium 0:892175366555 35 ******************************************************************************
rosarium 0:892175366555 36 */
rosarium 0:892175366555 37
rosarium 0:892175366555 38 #include "mbed.h"
rosarium 0:892175366555 39
rosarium 0:892175366555 40 #include "X_NUCLEO_NFC02A1.h"
rosarium 0:892175366555 41 #include "DevI2C.h"
rosarium 0:892175366555 42 #include "m24lr.h"
rosarium 1:11ae12d41082 43 #include "NDefLib/NDefNfcTag.h"
rosarium 1:11ae12d41082 44 #include "NDefLib/RecordType/RecordURI.h"
rosarium 8:9bdd16ebccfb 45
rosarium 8:9bdd16ebccfb 46 #if 0
rosarium 8:9bdd16ebccfb 47 /*----------------------------------------------------------------------------*/
rosarium 8:9bdd16ebccfb 48 static volatile bool buttonPress=false; // true when the user press the message
rosarium 8:9bdd16ebccfb 49
rosarium 8:9bdd16ebccfb 50 static void setButtonPress(){
rosarium 8:9bdd16ebccfb 51 buttonPress=true;
rosarium 8:9bdd16ebccfb 52 }//if buttonPress
rosarium 8:9bdd16ebccfb 53
rosarium 8:9bdd16ebccfb 54 static void readAndPrintNfcTag(NDefLib::NDefNfcTag &tag){
rosarium 8:9bdd16ebccfb 55 using namespace NDefLib;
rosarium 8:9bdd16ebccfb 56
rosarium 8:9bdd16ebccfb 57 if(tag.openSession() == true){
rosarium 8:9bdd16ebccfb 58 printf("Open Session\r\n");
rosarium 8:9bdd16ebccfb 59 NDefLib::Message readMsg;
rosarium 8:9bdd16ebccfb 60
rosarium 8:9bdd16ebccfb 61 tag.read(&readMsg);
rosarium 8:9bdd16ebccfb 62 printf("Message Read\r\n");
rosarium 8:9bdd16ebccfb 63
rosarium 8:9bdd16ebccfb 64 if(readMsg.getNRecords()==0){
rosarium 8:9bdd16ebccfb 65 printf("Error Read\r\n");
rosarium 8:9bdd16ebccfb 66 }else{
rosarium 8:9bdd16ebccfb 67 for(uint32_t i=0;i<readMsg.getNRecords();i++){
rosarium 8:9bdd16ebccfb 68 Record *r = readMsg[i];
rosarium 8:9bdd16ebccfb 69 // printRecord(r);
rosarium 8:9bdd16ebccfb 70 //-----
rosarium 8:9bdd16ebccfb 71 RecordURI *const temp = (RecordURI*)r;
rosarium 8:9bdd16ebccfb 72 printf("Read uriId: %d\r\n",temp->getUriId());
rosarium 8:9bdd16ebccfb 73 printf("Read uriType: %s\r\n",temp->getUriType().c_str());
rosarium 8:9bdd16ebccfb 74 printf("Read uriContent: %s\r\n",temp->getContent().c_str());
rosarium 8:9bdd16ebccfb 75 //------
rosarium 8:9bdd16ebccfb 76 delete r;
rosarium 8:9bdd16ebccfb 77 }//for
rosarium 8:9bdd16ebccfb 78 }//if-else
rosarium 8:9bdd16ebccfb 79
rosarium 8:9bdd16ebccfb 80 tag.closeSession();
rosarium 8:9bdd16ebccfb 81 printf("Close session\r\n");
rosarium 8:9bdd16ebccfb 82 }else{
rosarium 8:9bdd16ebccfb 83 printf("Error open read Session\n\r");
rosarium 8:9bdd16ebccfb 84 }
rosarium 8:9bdd16ebccfb 85 }
rosarium 8:9bdd16ebccfb 86 /*----------------------------------------------------------------------------*/
rosarium 8:9bdd16ebccfb 87 #endif
rosarium 8:9bdd16ebccfb 88
rosarium 0:892175366555 89 /**
rosarium 0:892175366555 90 * Write a Ndef URI message linking to st.com site.
rosarium 0:892175366555 91 */
rosarium 8:9bdd16ebccfb 92
rosarium 0:892175366555 93 int main(void)
rosarium 0:892175366555 94 {
rosarium 0:892175366555 95
rosarium 0:892175366555 96 /*use default board pinout*/
rosarium 0:892175366555 97 DevI2C i2cChannel(X_NUCLEO_NFC02A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC02A1::DEFAULT_SDL_PIN);
rosarium 0:892175366555 98 X_NUCLEO_NFC02A1 *nfcNucleo = X_NUCLEO_NFC02A1::Instance(i2cChannel,
rosarium 0:892175366555 99 X_NUCLEO_NFC02A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC02A1::DEFAULT_RF_DISABLE_PIN,
rosarium 0:892175366555 100 X_NUCLEO_NFC02A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC02A1::DEFAULT_LED2_PIN,
rosarium 0:892175366555 101 X_NUCLEO_NFC02A1::DEFAULT_LED3_PIN);
rosarium 0:892175366555 102
rosarium 2:6f1b1f7f8d12 103 NDefLib::NDefNfcTag& tag =nfcNucleo->getM24LR().getNDefTag();
rosarium 2:6f1b1f7f8d12 104 M24LR & mM24LRp = nfcNucleo->getM24LR();
rosarium 2:6f1b1f7f8d12 105
rosarium 0:892175366555 106 /* Enable Energy Harvesting */
rosarium 1:11ae12d41082 107 mM24LRp.Enable_EnergyHarvesting();
rosarium 0:892175366555 108
rosarium 0:892175366555 109 printf("System Initialization done: !\n\r");
rosarium 0:892175366555 110
rosarium 2:6f1b1f7f8d12 111 /*open the i2c session with the nfc chip*/
rosarium 8:9bdd16ebccfb 112 if(tag.openSession() == true)
rosarium 2:6f1b1f7f8d12 113 {
rosarium 2:6f1b1f7f8d12 114 printf("Session opened\n\r");
rosarium 2:6f1b1f7f8d12 115 nfcNucleo->getLed1()=1;
rosarium 2:6f1b1f7f8d12 116
rosarium 2:6f1b1f7f8d12 117 /*create the NDef message and record*/
rosarium 2:6f1b1f7f8d12 118 NDefLib::Message msg;
rosarium 7:699836375630 119 NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com/st25");
rosarium 2:6f1b1f7f8d12 120 msg.addRecord(&rUri);
rosarium 2:6f1b1f7f8d12 121
rosarium 2:6f1b1f7f8d12 122 /*write the tag*/
rosarium 8:9bdd16ebccfb 123 if(tag.write(msg) == true)
rosarium 8:9bdd16ebccfb 124 {
rosarium 2:6f1b1f7f8d12 125 printf("Tag written\n\r");
rosarium 2:6f1b1f7f8d12 126 nfcNucleo->getLed2()=1;
rosarium 8:9bdd16ebccfb 127 }
rosarium 8:9bdd16ebccfb 128 else
rosarium 8:9bdd16ebccfb 129 {
rosarium 2:6f1b1f7f8d12 130 printf("Error writing \n\r");
rosarium 2:6f1b1f7f8d12 131 nfcNucleo->getLed1()=0;
rosarium 2:6f1b1f7f8d12 132 }//if-else
rosarium 2:6f1b1f7f8d12 133
rosarium 2:6f1b1f7f8d12 134 /*close the i2c session*/
rosarium 8:9bdd16ebccfb 135 if(tag.closeSession() == true)
rosarium 1:11ae12d41082 136 {
rosarium 2:6f1b1f7f8d12 137 printf("Session closed\n\r");
rosarium 2:6f1b1f7f8d12 138 nfcNucleo->getLed3()=1;
rosarium 1:11ae12d41082 139 }
rosarium 1:11ae12d41082 140 else
rosarium 2:6f1b1f7f8d12 141 {
rosarium 2:6f1b1f7f8d12 142 printf("Error closing the session\n\r");
rosarium 2:6f1b1f7f8d12 143 }//if-else
rosarium 2:6f1b1f7f8d12 144
rosarium 2:6f1b1f7f8d12 145 }
rosarium 2:6f1b1f7f8d12 146 else
rosarium 2:6f1b1f7f8d12 147 printf("Error opening the session\n\r");
rosarium 8:9bdd16ebccfb 148
rosarium 8:9bdd16ebccfb 149 #if 0
rosarium 8:9bdd16ebccfb 150 /*----------------------------------------------------------------------------*/
rosarium 8:9bdd16ebccfb 151 /* enable the button */
rosarium 8:9bdd16ebccfb 152 InterruptIn mybutton(USER_BUTTON);
rosarium 8:9bdd16ebccfb 153
rosarium 8:9bdd16ebccfb 154 mybutton.fall(setButtonPress);
rosarium 8:9bdd16ebccfb 155
rosarium 8:9bdd16ebccfb 156 /*each second change the led status and see if the user press the button*/
rosarium 8:9bdd16ebccfb 157 while(1)
rosarium 8:9bdd16ebccfb 158 {
rosarium 8:9bdd16ebccfb 159 if(buttonPress)
rosarium 8:9bdd16ebccfb 160 {
rosarium 8:9bdd16ebccfb 161 /*write the read message on console*/
rosarium 8:9bdd16ebccfb 162 readAndPrintNfcTag(tag);
rosarium 8:9bdd16ebccfb 163 buttonPress=false;
rosarium 8:9bdd16ebccfb 164 }
rosarium 8:9bdd16ebccfb 165 }
rosarium 8:9bdd16ebccfb 166 /*----------------------------------------------------------------------------*/
rosarium 8:9bdd16ebccfb 167 #endif
rosarium 8:9bdd16ebccfb 168
rosarium 0:892175366555 169 }
rosarium 0:892175366555 170
rosarium 2:6f1b1f7f8d12 171
rosarium 2:6f1b1f7f8d12 172
rosarium 8:9bdd16ebccfb 173
rosarium 2:6f1b1f7f8d12 174 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/