mbed OS 5 example application using X-NUCLEO-NFC02A1

Dependencies:   NDefLib X_NUCLEO_NFC02A1

Fork of HelloWorld_NFC02A1 by ST

Committer:
rosarium
Date:
Tue Aug 30 09:18:50 2016 +0000
Revision:
1:11ae12d41082
Parent:
0:892175366555
Child:
2:6f1b1f7f8d12
NDefLib middle-ware library ported on HelloWorld_NFC02A1. Now NFC02A1 using the same middle-ware library as NFC01A1.

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
rosarium 1:11ae12d41082 44 #include "NDefLib/NDefNfcTag.h"
rosarium 1:11ae12d41082 45 #include "NDefLib/RecordType/RecordURI.h"
rosarium 0:892175366555 46 /**
rosarium 0:892175366555 47 * Write a Ndef URI message linking to st.com site.
rosarium 0:892175366555 48 */
rosarium 0:892175366555 49 int main(void)
rosarium 0:892175366555 50 {
rosarium 0:892175366555 51
rosarium 0:892175366555 52 /*use default board pinout*/
rosarium 0:892175366555 53 DevI2C i2cChannel(X_NUCLEO_NFC02A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC02A1::DEFAULT_SDL_PIN);
rosarium 0:892175366555 54 X_NUCLEO_NFC02A1 *nfcNucleo = X_NUCLEO_NFC02A1::Instance(i2cChannel,
rosarium 0:892175366555 55 X_NUCLEO_NFC02A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC02A1::DEFAULT_RF_DISABLE_PIN,
rosarium 0:892175366555 56 X_NUCLEO_NFC02A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC02A1::DEFAULT_LED2_PIN,
rosarium 0:892175366555 57 X_NUCLEO_NFC02A1::DEFAULT_LED3_PIN);
rosarium 0:892175366555 58
rosarium 1:11ae12d41082 59 NDefLib::NDefNfcTag& tag =nfcNucleo->getM24LR().getNDefTag();
rosarium 1:11ae12d41082 60 M24LR & mM24LRp = nfcNucleo->getM24LR();
rosarium 1:11ae12d41082 61 // mNDEF_URI.setM24LR(mM24LRp);
rosarium 0:892175366555 62 /* Enable Energy Harvesting */
rosarium 1:11ae12d41082 63 mM24LRp.Enable_EnergyHarvesting();
rosarium 0:892175366555 64
rosarium 0:892175366555 65 printf("System Initialization done: !\n\r");
rosarium 0:892175366555 66
rosarium 1:11ae12d41082 67 //open the i2c session with the nfc chip
rosarium 1:11ae12d41082 68 if(tag.openSession())
rosarium 1:11ae12d41082 69 {
rosarium 1:11ae12d41082 70 printf("Session opened\n\r");
rosarium 1:11ae12d41082 71 nfcNucleo->getLed1()=1;
rosarium 1:11ae12d41082 72
rosarium 1:11ae12d41082 73 //create the NDef message and record
rosarium 1:11ae12d41082 74 NDefLib::Message msg;
rosarium 1:11ae12d41082 75 NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com");
rosarium 1:11ae12d41082 76 msg.addRecord(&rUri);
rosarium 1:11ae12d41082 77
rosarium 1:11ae12d41082 78 //write the tag
rosarium 1:11ae12d41082 79 if(tag.write(msg) == NDEF_OK)
rosarium 1:11ae12d41082 80 {
rosarium 1:11ae12d41082 81 printf("Tag written\n\r");
rosarium 1:11ae12d41082 82 nfcNucleo->getLed2()=1;
rosarium 1:11ae12d41082 83 }
rosarium 1:11ae12d41082 84 else
rosarium 1:11ae12d41082 85 {
rosarium 1:11ae12d41082 86 printf("Error writing \n\r");
rosarium 1:11ae12d41082 87 nfcNucleo->getLed1()=0;
rosarium 1:11ae12d41082 88 }//if-else
rosarium 1:11ae12d41082 89
rosarium 1:11ae12d41082 90 //close the i2c session
rosarium 1:11ae12d41082 91 if(tag.closeSession())
rosarium 1:11ae12d41082 92 {
rosarium 1:11ae12d41082 93 printf("Session closed\n\r");
rosarium 1:11ae12d41082 94 nfcNucleo->getLed3()=1;
rosarium 1:11ae12d41082 95 }
rosarium 1:11ae12d41082 96 else
rosarium 1:11ae12d41082 97 {
rosarium 1:11ae12d41082 98 printf("Error closing the session\n\r");
rosarium 1:11ae12d41082 99 }//if-else
rosarium 1:11ae12d41082 100
rosarium 1:11ae12d41082 101 }
rosarium 1:11ae12d41082 102 else
rosarium 1:11ae12d41082 103 printf("Error opening the session\n\r");
rosarium 0:892175366555 104
rosarium 0:892175366555 105 }
rosarium 0:892175366555 106