![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
0
Dependencies: mbed NDefLib X_NUCLEO_NFC01A1
Dependents: Projekt KPG Program_KPG_2019
main.cpp@11:925a5a491a5c, 2016-01-28 (annotated)
- Committer:
- giovannivisentini
- Date:
- Thu Jan 28 14:01:40 2016 +0000
- Revision:
- 11:925a5a491a5c
- Parent:
- 7:435297dd022d
- Child:
- 14:1b99908360c5
update the library with the async api
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 | 11:925a5a491a5c | 51 | X_NUCLEO_NFC01A1 *nfcNucleo = X_NUCLEO_NFC01A1::Instance(i2cChannel,NULL); |
giovannivisentini | 0:151ae20d098f | 52 | |
giovannivisentini | 6:44204e733f96 | 53 | //retrieve the NdefLib interface |
giovannivisentini | 4:4145a2db3349 | 54 | NDefLib::NDefNfcTag& tag =nfcNucleo->getM24SR().getNDefTag(); |
giovannivisentini | 7:435297dd022d | 55 | printf("System Init done: !\n\r"); |
giovannivisentini | 6:44204e733f96 | 56 | |
giovannivisentini | 0:151ae20d098f | 57 | //open the i2c session with the nfc chip |
giovannivisentini | 0:151ae20d098f | 58 | if(tag.openSession()){ |
giovannivisentini | 7:435297dd022d | 59 | printf("Session open\n\r"); |
giovannivisentini | 0:151ae20d098f | 60 | nfcNucleo->getLed1()=1; |
giovannivisentini | 0:151ae20d098f | 61 | |
giovannivisentini | 0:151ae20d098f | 62 | //create the NDef message and record |
giovannivisentini | 0:151ae20d098f | 63 | NDefLib::Message msg; |
giovannivisentini | 0:151ae20d098f | 64 | NDefLib::RecordURI rUri(NDefLib::RecordURI::HTTP_WWW,"st.com"); |
giovannivisentini | 0:151ae20d098f | 65 | msg.addRecord(&rUri); |
giovannivisentini | 0:151ae20d098f | 66 | |
giovannivisentini | 0:151ae20d098f | 67 | //write the tag |
giovannivisentini | 0:151ae20d098f | 68 | if(tag.write(msg)){ |
giovannivisentini | 7:435297dd022d | 69 | printf("Tag writed \n\r"); |
giovannivisentini | 0:151ae20d098f | 70 | nfcNucleo->getLed2()=1; |
giovannivisentini | 1:eff1b8998438 | 71 | }else{ |
giovannivisentini | 7:435297dd022d | 72 | printf("Error writing \n\r"); |
giovannivisentini | 1:eff1b8998438 | 73 | }//if-else |
giovannivisentini | 0:151ae20d098f | 74 | |
giovannivisentini | 0:151ae20d098f | 75 | //close the i2c session |
giovannivisentini | 1:eff1b8998438 | 76 | if(tag.closeSession()){ |
giovannivisentini | 7:435297dd022d | 77 | printf("Session closed\n\r"); |
giovannivisentini | 1:eff1b8998438 | 78 | nfcNucleo->getLed3()=1; |
giovannivisentini | 1:eff1b8998438 | 79 | }else{ |
giovannivisentini | 7:435297dd022d | 80 | printf("Error Closing the session\n\r"); |
giovannivisentini | 1:eff1b8998438 | 81 | }//if-else |
giovannivisentini | 1:eff1b8998438 | 82 | |
giovannivisentini | 0:151ae20d098f | 83 | }else |
giovannivisentini | 7:435297dd022d | 84 | printf("Error open Session\n\r"); |
giovannivisentini | 11:925a5a491a5c | 85 | } |