Send NFC messages using NFC Shield V2.0 by SeeedStudio.
The program uses the standard Arduino shields SPI pins:
Signal | Pin |
SCK | D13 |
MISO | D12 |
MOSI | D11 |
CS | D10 |
Note that this shield doesn't use the standard SPI pins, but relies on non-standard 6-pin SPI header located at the shield bottom. To make it work you will have to bridge those pins as shown on the image (the green SPI pins).
Signal | Pin 1 | Pin 2 |
MOSI | D11 | SPI4 |
MISO | D12 | SPI1 |
SCK | D13 | SPI3 |
main.cpp@3:c4590e900bbd, 2015-02-13 (annotated)
- Committer:
- screamer
- Date:
- Fri Feb 13 09:41:09 2015 +0000
- Revision:
- 3:c4590e900bbd
- Parent:
- 2:f0e840a179ff
Update mbed library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
screamer | 2:f0e840a179ff | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
screamer | 2:f0e840a179ff | 2 | * |
screamer | 2:f0e840a179ff | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
screamer | 2:f0e840a179ff | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
screamer | 2:f0e840a179ff | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
screamer | 2:f0e840a179ff | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
screamer | 2:f0e840a179ff | 7 | * Software is furnished to do so, subject to the following conditions: |
screamer | 2:f0e840a179ff | 8 | * |
screamer | 2:f0e840a179ff | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
screamer | 2:f0e840a179ff | 10 | * substantial portions of the Software. |
screamer | 2:f0e840a179ff | 11 | * |
screamer | 2:f0e840a179ff | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
screamer | 2:f0e840a179ff | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
screamer | 2:f0e840a179ff | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
screamer | 2:f0e840a179ff | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
screamer | 2:f0e840a179ff | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
screamer | 2:f0e840a179ff | 17 | */ |
screamer | 2:f0e840a179ff | 18 | |
screamer | 0:e403d7000b50 | 19 | #include "mbed.h" |
screamer | 0:e403d7000b50 | 20 | #include "PN532_SPI.h" |
screamer | 0:e403d7000b50 | 21 | #include "snep.h" |
screamer | 0:e403d7000b50 | 22 | #include "NdefMessage.h" |
screamer | 0:e403d7000b50 | 23 | |
screamer | 0:e403d7000b50 | 24 | Serial pc(USBTX, USBRX); |
screamer | 0:e403d7000b50 | 25 | |
screamer | 0:e403d7000b50 | 26 | uint8_t ndefBuf[128]; |
screamer | 0:e403d7000b50 | 27 | |
screamer | 0:e403d7000b50 | 28 | int main() |
screamer | 0:e403d7000b50 | 29 | { |
screamer | 0:e403d7000b50 | 30 | wait(2); |
screamer | 0:e403d7000b50 | 31 | |
screamer | 0:e403d7000b50 | 32 | pc.printf("Initializing - "); |
screamer | 0:e403d7000b50 | 33 | SPI spi(D11, D12, D13); |
screamer | 0:e403d7000b50 | 34 | PN532_SPI pn532spi(spi, D10); |
screamer | 0:e403d7000b50 | 35 | SNEP nfc(pn532spi); |
screamer | 0:e403d7000b50 | 36 | pc.printf("Done\r\n"); |
screamer | 0:e403d7000b50 | 37 | |
screamer | 0:e403d7000b50 | 38 | while (1) { |
screamer | 0:e403d7000b50 | 39 | pc.printf("Sending message - "); |
screamer | 0:e403d7000b50 | 40 | NdefMessage message = NdefMessage(); |
screamer | 0:e403d7000b50 | 41 | message.addTextRecord("mbed NFC shield"); |
screamer | 0:e403d7000b50 | 42 | message.addUriRecord("http://www.seeedstudio.com"); |
screamer | 0:e403d7000b50 | 43 | int messageSize = message.getEncodedSize(); |
screamer | 0:e403d7000b50 | 44 | if (messageSize > sizeof(ndefBuf)) { |
screamer | 0:e403d7000b50 | 45 | pc.printf("ndefBuf is too small\r\n"); |
screamer | 0:e403d7000b50 | 46 | while (1) { |
screamer | 0:e403d7000b50 | 47 | } |
screamer | 0:e403d7000b50 | 48 | } |
screamer | 0:e403d7000b50 | 49 | message.encode(ndefBuf); |
screamer | 0:e403d7000b50 | 50 | if (0 >= nfc.write(ndefBuf, messageSize)) { |
screamer | 0:e403d7000b50 | 51 | pc.printf("Failed\r\n"); |
screamer | 0:e403d7000b50 | 52 | } else { |
screamer | 0:e403d7000b50 | 53 | pc.printf("Success\r\n"); |
screamer | 0:e403d7000b50 | 54 | } |
screamer | 0:e403d7000b50 | 55 | |
screamer | 0:e403d7000b50 | 56 | wait(3); |
screamer | 0:e403d7000b50 | 57 | } |
screamer | 0:e403d7000b50 | 58 | } |