From: Kevin Townsend Date: Thu, 16 Feb 2012 09:48:55 +0000 (+0100) Subject: First commit X-Git-Url: http://git.rohieb.name/hackover2013-badge-firmware.git/commitdiff_plain/6c802048ed4a4d343b2696bd0afeae54d33edb7c?ds=sidebyside First commit --- diff --git a/tools/examples/sensors/pn532/MifareUltralight_MemDump/main.c b/tools/examples/sensors/pn532/MifareUltralight_MemDump/main.c new file mode 100644 index 0000000..82797da --- /dev/null +++ b/tools/examples/sensors/pn532/MifareUltralight_MemDump/main.c @@ -0,0 +1,124 @@ +/**************************************************************************/ +/*! + @file main.c + @author K. Townsend (microBuilder.eu) + + @section LICENSE + + Software License Agreement (BSD License) + + Copyright (c) 2010, microBuilder SARL + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + 3. Neither the name of the copyright holders nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ +/**************************************************************************/ +#include + +#include "projectconfig.h" +#include "sysinit.h" + +#include "core/i2c/i2c.h" +#include "drivers/sensors/pn532/pn532.h" +#include "drivers/sensors/pn532/pn532_bus.h" +#include "drivers/sensors/pn532/helpers/pn532_mifare_classic.h" +#include "drivers/sensors/pn532/helpers/pn532_mifare_ultralight.h" + +/**************************************************************************/ +/*! + Main program entry point. After reset, normal code execution will + begin here. + + Note: CFG_INTERFACE is normally enabled by default. If you wish to + enable the blinking LED code in main, you will need to open + projectconfig.h, comment out "#define CFG_INTERFACE" and + rebuild the project. +*/ +/**************************************************************************/ +int main (void) +{ + #ifdef CFG_INTERFACE + //#error "CFG_INTERFACE must be disabled in projectconfig.h for this demo" + #endif + #if !defined CFG_PRINTF_USBCDC + #error "CFG_PRINTF_USBCDC must be enabled in projectconfig.h for this demo" + #endif + + // Configure cpu and mandatory peripherals + systemInit(); + + // Wait a bit for someone to open the USB connection for printf + systickDelay(2000); + + // Initialise the PN532 + pn532Init(); + + pn532_error_t error; + byte_t abtBuffer[8]; + size_t szUIDLen; + + while(1) + { + printf("Please insert a Mifare Ultralight card%s", CFG_PRINTF_NEWLINE); + + // Try to do a memory dump of a Mifare Ultralight card + // First wait for a card to arrive (will wake the PN532 if required) + error = pn532_mifareultralight_WaitForPassiveTarget(abtBuffer, &szUIDLen); + if (error) + { + switch (error) + { + case PN532_ERROR_WRONGCARDTYPE: + printf("Not a Mifare Ultralight card%s", CFG_PRINTF_NEWLINE); + break; + default: + printf("Error establishing passive connection (0x%02x)%s", error, CFG_PRINTF_NEWLINE); + break; + } + } + else + { + // Display the card's UID (normally 7 bytes long) + printf("UID: "); + pn532PrintHex(abtBuffer, szUIDLen); + printf("%s", CFG_PRINTF_NEWLINE); + printf("Page Hex Text%s", CFG_PRINTF_NEWLINE); + printf("---- -------- ----%s", CFG_PRINTF_NEWLINE); + // Dump the memory contents page by page + uint8_t i; + for (i = 0; i < 16; i++) + { + // Try to read the current page + error = pn532_mifareultralight_ReadPage(i, abtBuffer); + if (!error) + { + printf("0x%02x ", i); + pn532PrintHexChar(abtBuffer, 4); + } + } + } + // Wait a bit before trying again + printf("%s", CFG_PRINTF_NEWLINE); + systickDelay(2000); + } +} diff --git a/tools/examples/sensors/pn532/MifareUltralight_MemDump/readme.txt b/tools/examples/sensors/pn532/MifareUltralight_MemDump/readme.txt new file mode 100644 index 0000000..c8ed273 --- /dev/null +++ b/tools/examples/sensors/pn532/MifareUltralight_MemDump/readme.txt @@ -0,0 +1,69 @@ +OVERVIEW +============================================================ +This example will wait for a Mifare Ultralight card to enter +the RF field, and then try to dump the card's contents to +USB CDC. + +HOW TO USE THIS EXAMPLE +============================================================ +1.) Connect the PN532 NFC Breakout Board to UART on the + LPC1343 as follows: + + PN532 LPC1343 + ----- ------- + GND GND + TXD RXD + RXD TXD + 3.3V 3.3V + + Set SEL0 to Off and SEL1 to Off (= UART) + + or via I2C as follows: + + PN532 LPC1343 + ----- ------- + GND GND + SDA SDA + SCL SCL + IRQ 3.2 + 3.3V 3.3V + + Set SEL0 to On and SEL1 to Off (= I2C) + +2.) Configure your terminal software to open the USB COM + port at 115K. + +3.) When the application starts, there is a 5 second delay + (to allow you time to connect via USB CDC), after which + point the device will wait for a single ISO14443A card + (Mifare Classic, etc.) and try to read it's ID. Once a + card is found, the reader will start looking again for a + card after a 1 second delay. + +SAMPLE OUTPUT +============================================================ + +When a Mifare Ultralight card is placed in the field you +should see results similar to the following: + + Please insert a Mifare Ultralight card + UID: 04 7b cb 51 96 22 80 + + Page Hex Text + ---- -------- ---- + 0x00 047bcb3c .{Ë< + 0x01 51962280 Q–"€ + 0x02 6548ff7f eHÿ + 0x03 e1100600 á... + 0x04 031dd101 ..Ñ. + 0x05 19550174 .U.t + 0x06 7461672e tag. + 0x07 62652f6d be/m + 0x08 2f303437 /047 + 0x09 42434235 BCB5 + 0x0a 31393632 1962 + 0x0b 32383050 280P + 0x0c c7badbbb Ǻۻ + 0x0d 3df622c1 =ö"Á + 0x0e 68e88f24 hè$ + 0x0f 00000000 ....