mbed OS 5 example application using X-NUCLEO-NFC02A1

Dependencies:   NDefLib X_NUCLEO_NFC02A1

Fork of HelloWorld_NFC02A1 by ST

Committer:
rosarium
Date:
Thu Sep 29 05:48:44 2016 +0000
Revision:
7:699836375630
Parent:
2:6f1b1f7f8d12
Child:
8:9bdd16ebccfb
Bug fix for write message routine and updated the URI message to st.com/st25

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