Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: NDefLib X_NUCLEO_NFC01A1 mbed
Fork of X-MBED-NFC1 by
SampleSync_writeUrl.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file SampleSync_writeUrl.cpp 00004 * @author ST / Central Labs 00005 * @date 03 Dic 2015 00006 * @brief This demo write an ndef message with an url inside 00007 ****************************************************************************** 00008 * 00009 * COPYRIGHT(c) 2015 STMicroelectronics 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 #include "mbed.h" 00037 00038 #include "XNucleoNFC01A1.h" 00039 #include "NDefLib/NDefNfcTag.h" 00040 #include "NDefLib/RecordType/RecordURI.h" 00041 00042 /** 00043 * Write a Ndef linking the st.com site. 00044 */ 00045 void sampleSync_writeUrl() { 00046 I2C i2cChannel(XNucleoNFC01A1::DEFAULT_SDA_PIN,XNucleoNFC01A1::DEFAULT_SDL_PIN); 00047 XNucleoNFC01A1 *nfcNucleo = XNucleoNFC01A1::instance(i2cChannel); 00048 00049 //retrieve the NdefLib interface 00050 NDefLib::NDefNfcTag& tag = nfcNucleo->get_M24SR().get_NDef_tag(); 00051 printf("System Init done: !\r\n"); 00052 //open the i2c session with the nfc chip 00053 if (tag.open_session()) { 00054 nfcNucleo->get_led1()=1; 00055 00056 //create the NDef message and record 00057 NDefLib::Message msg; 00058 NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com"); 00059 msg.add_record(&rUri); 00060 00061 //write the tag 00062 if (tag.write(msg)) { 00063 printf("Tag written \r\n"); 00064 nfcNucleo->get_led2()=1; 00065 } 00066 00067 00068 //close the i2c session 00069 if (!tag.close_session()) { 00070 printf("Error Closing the session\r\n"); 00071 } else { 00072 nfcNucleo->get_led3()=1; 00073 } 00074 } else { 00075 printf("Error open Session\r\n"); 00076 } 00077 }
Generated on Wed Jul 13 2022 03:11:25 by
1.7.2
