0
Dependencies: mbed NDefLib X_NUCLEO_NFC01A1
Dependents: Projekt KPG Program_KPG_2019
main.cpp@14:1b99908360c5, 2016-02-02 (annotated)
- Committer:
- giovannivisentini
- Date:
- Tue Feb 02 16:04:36 2016 +0000
- Revision:
- 14:1b99908360c5
- Parent:
- 11:925a5a491a5c
- Child:
- 17:22e6c00f3a4c
- Child:
- 18:982e7640cfb6
update docs
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
giovannivisentini | 0:151ae20d098f | 1 | /** |
giovannivisentini | 0:151ae20d098f | 2 | ****************************************************************************** |
giovannivisentini | 0:151ae20d098f | 3 | * @file main.cpp |
giovannivisentini | 4:4145a2db3349 | 4 | * @author ST Central Labs |
giovannivisentini | 7:435297dd022d | 5 | * @version V1.0.0 |
giovannivisentini | 4:4145a2db3349 | 6 | * @date 21 Dic 2015 |
giovannivisentini | 6:44204e733f96 | 7 | * @brief This demo writes an ndef message with an url inside. |
giovannivisentini | 0:151ae20d098f | 8 | ****************************************************************************** |
giovannivisentini | 6:44204e733f96 | 9 | * @attention |
giovannivisentini | 0:151ae20d098f | 10 | * |
giovannivisentini | 6:44204e733f96 | 11 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
giovannivisentini | 0:151ae20d098f | 12 | * |
giovannivisentini | 0:151ae20d098f | 13 | * Redistribution and use in source and binary forms, with or without modification, |
giovannivisentini | 0:151ae20d098f | 14 | * are permitted provided that the following conditions are met: |
giovannivisentini | 0:151ae20d098f | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
giovannivisentini | 0:151ae20d098f | 16 | * this list of conditions and the following disclaimer. |
giovannivisentini | 0:151ae20d098f | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
giovannivisentini | 0:151ae20d098f | 18 | * this list of conditions and the following disclaimer in the documentation |
giovannivisentini | 0:151ae20d098f | 19 | * and/or other materials provided with the distribution. |
giovannivisentini | 0:151ae20d098f | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
giovannivisentini | 0:151ae20d098f | 21 | * may be used to endorse or promote products derived from this software |
giovannivisentini | 0:151ae20d098f | 22 | * without specific prior written permission. |
giovannivisentini | 0:151ae20d098f | 23 | * |
giovannivisentini | 0:151ae20d098f | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
giovannivisentini | 0:151ae20d098f | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
giovannivisentini | 0:151ae20d098f | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
giovannivisentini | 0:151ae20d098f | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
giovannivisentini | 0:151ae20d098f | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
giovannivisentini | 0:151ae20d098f | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
giovannivisentini | 0:151ae20d098f | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
giovannivisentini | 0:151ae20d098f | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
giovannivisentini | 0:151ae20d098f | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
giovannivisentini | 0:151ae20d098f | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
giovannivisentini | 0:151ae20d098f | 34 | * |
giovannivisentini | 0:151ae20d098f | 35 | ****************************************************************************** |
giovannivisentini | 0:151ae20d098f | 36 | */ |
giovannivisentini | 11:925a5a491a5c | 37 | |
giovannivisentini | 0:151ae20d098f | 38 | #include "mbed.h" |
giovannivisentini | 0:151ae20d098f | 39 | |
giovannivisentini | 0:151ae20d098f | 40 | #include "X_NUCLEO_NFC01A1.h" |
giovannivisentini | 4:4145a2db3349 | 41 | #include "NDefLib/NDefNfcTag.h" |
giovannivisentini | 0:151ae20d098f | 42 | #include "NDefLib/RecordType/RecordURI.h" |
giovannivisentini | 0:151ae20d098f | 43 | |
giovannivisentini | 0:151ae20d098f | 44 | /** |
giovannivisentini | 6:44204e733f96 | 45 | * Write a Ndef URI message linking to st.com site. |
giovannivisentini | 0:151ae20d098f | 46 | */ |
giovannivisentini | 0:151ae20d098f | 47 | int main(void){ |
giovannivisentini | 0:151ae20d098f | 48 | |
giovannivisentini | 6:44204e733f96 | 49 | //use default board pinout |
giovannivisentini | 0:151ae20d098f | 50 | I2C i2cChannel(X_NUCLEO_NFC01A1::DEFAULT_SDA_PIN,X_NUCLEO_NFC01A1::DEFAULT_SDL_PIN); |
giovannivisentini | 14:1b99908360c5 | 51 | X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,NULL, |
giovannivisentini | 14:1b99908360c5 | 52 | X_NUCLEO_NFC01A1::DEFAULT_GPO_PIN,X_NUCLEO_NFC01A1::DEFAULT_RF_DISABLE_PIN, |
giovannivisentini | 14:1b99908360c5 | 53 | X_NUCLEO_NFC01A1::DEFAULT_LED1_PIN,X_NUCLEO_NFC01A1::DEFAULT_LED2_PIN, |
giovannivisentini | 14:1b99908360c5 | 54 | X_NUCLEO_NFC01A1::DEFAULT_LED3_PIN); |
giovannivisentini | 0:151ae20d098f | 55 | |
giovannivisentini | 6:44204e733f96 | 56 | //retrieve the NdefLib interface |
giovannivisentini | 4:4145a2db3349 | 57 | NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag(); |
giovannivisentini | 7:435297dd022d | 58 | printf("System Init done: !\n\r"); |
giovannivisentini | 6:44204e733f96 | 59 | |
giovannivisentini | 0:151ae20d098f | 60 | //open the i2c session with the nfc chip |
giovannivisentini | 0:151ae20d098f | 61 | if(tag.openSession()){ |
giovannivisentini | 14:1b99908360c5 | 62 | printf("Session opened\n\r"); |
giovannivisentini | 0:151ae20d098f | 63 | nfcNucleo->getLed1()=1; |
giovannivisentini | 0:151ae20d098f | 64 | |
giovannivisentini | 0:151ae20d098f | 65 | //create the NDef message and record |
giovannivisentini | 0:151ae20d098f | 66 | NDefLib::Message msg; |
giovannivisentini | 0:151ae20d098f | 67 | NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com"); |
giovannivisentini | 0:151ae20d098f | 68 | msg.addRecord(&rUri); |
giovannivisentini | 0:151ae20d098f | 69 | |
giovannivisentini | 0:151ae20d098f | 70 | //write the tag |
giovannivisentini | 0:151ae20d098f | 71 | if(tag.write(msg)){ |
giovannivisentini | 14:1b99908360c5 | 72 | printf("Tag written\n\r"); |
giovannivisentini | 0:151ae20d098f | 73 | nfcNucleo->getLed2()=1; |
giovannivisentini | 1:eff1b8998438 | 74 | }else{ |
giovannivisentini | 7:435297dd022d | 75 | printf("Error writing \n\r"); |
giovannivisentini | 1:eff1b8998438 | 76 | }//if-else |
giovannivisentini | 0:151ae20d098f | 77 | |
giovannivisentini | 0:151ae20d098f | 78 | //close the i2c session |
giovannivisentini | 1:eff1b8998438 | 79 | if(tag.closeSession()){ |
giovannivisentini | 7:435297dd022d | 80 | printf("Session closed\n\r"); |
giovannivisentini | 1:eff1b8998438 | 81 | nfcNucleo->getLed3()=1; |
giovannivisentini | 1:eff1b8998438 | 82 | }else{ |
giovannivisentini | 14:1b99908360c5 | 83 | printf("Error closing the session\n\r"); |
giovannivisentini | 1:eff1b8998438 | 84 | }//if-else |
giovannivisentini | 1:eff1b8998438 | 85 | |
giovannivisentini | 0:151ae20d098f | 86 | }else |
giovannivisentini | 14:1b99908360c5 | 87 | printf("Error opening the session\n\r"); |
giovannivisentini | 11:925a5a491a5c | 88 | } |