From: Kevin Townsend Date: Thu, 16 Feb 2012 09:31:45 +0000 (+0100) Subject: Updated example and readme X-Git-Url: http://git.rohieb.name/hackover2013-badge-firmware.git/commitdiff_plain/b1c6c435b3c01b0f81c77f55b90afd2f3940bbf3 Updated example and readme --- diff --git a/tools/examples/sensors/pn532/ISO14443A_ID/main.c b/tools/examples/sensors/pn532/ISO14443A_ID/main.c index 22f4f0e..511a554 100644 --- a/tools/examples/sensors/pn532/ISO14443A_ID/main.c +++ b/tools/examples/sensors/pn532/ISO14443A_ID/main.c @@ -39,7 +39,7 @@ #include "sysinit.h" #include "drivers/sensors/pn532/pn532.h" -#include "drivers/sensors/pn532/pn532_drvr.h" +#include "drivers/sensors/pn532/pn532_bus.h" /**************************************************************************/ /*! @@ -55,7 +55,7 @@ int main (void) { #ifdef CFG_INTERFACE - #error "CFG_INTERFACE must be disabled in projectconfig.h for this demo" + //#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" @@ -64,17 +64,17 @@ int main (void) // Configure cpu and mandatory peripherals systemInit(); - // Wait 5 second for someone to open the USB connection for printf + // Wait a bit for someone to open the USB connection for printf systickDelay(5000); // Initialise the PN532 pn532Init(); - byte_t response[256]; - size_t responseLen; pn532_error_t error; + byte_t response[64]; + size_t responseLen; - // Setup command to initialise a single ISO14443A target at 106kbps + // Setup command to initialise a single ISO14443A target at 106kbps (Mifare Classic, Ultralight, etc.) byte_t abtCommand[] = { PN532_COMMAND_INLISTPASSIVETARGET, 0x01, PN532_MODULATION_ISO14443A_106KBPS }; while (1) @@ -90,12 +90,20 @@ int main (void) switch(error) { case (PN532_ERROR_NOACK): - // No ACK frame received in UART mode (bus pins not set correctly?) - printf("Ooops ... No ACK frame was received! Are the bus pins sets to UART?%s", CFG_PRINTF_NEWLINE); + case (PN532_ERROR_INVALIDACK): + // No ACK response frame received from the PN532 + printf("Ooops ... No valid ACK frame received!%s", CFG_PRINTF_NEWLINE); break; case (PN532_ERROR_I2C_NACK): - // No ACK bit received to I2C start (bus pins not set correctly?) - printf("Ooops ... No ACK bit received for I2C start! Are the bus pins sets to I2C?%s", CFG_PRINTF_NEWLINE); + // No ACK bit received to I2C start ... not same as PN532 ACK frame (bus pins not set correctly?) + printf("Ooops ... No I2C ACK received! Are the bus select pins sets to I2C?%s", CFG_PRINTF_NEWLINE); + break; + case (PN532_ERROR_READYSTATUSTIMEOUT): + // Timed out waiting for the ready bit to clear ... this can be intentional, though, in the + // case of PN532_COMMAND_INLISTPASSIVETARGET since it will only clear when a card + // enters the magnetic field! Handle with caution because it isn't always an error + // Note: Only valid for I2C and SPI + printf("Timed out waiting for Ready/IRQ%s", CFG_PRINTF_NEWLINE); break; default: printf("Ooops ... something went wrong! [PN532 Error Code: 0x%02X]%s", error, CFG_PRINTF_NEWLINE); @@ -112,6 +120,26 @@ int main (void) systickDelay(25); } while (error == PN532_ERROR_RESPONSEBUFFEREMPTY); + + printf("%s", CFG_PRINTF_NEWLINE); + printf("%-12s: ", "Received"); + pn532PrintHex(response, responseLen); + + // Try to handle some potential frame errors + // Unhandled errors are caught further down + switch (error) + { + case (PN532_ERROR_PREAMBLEMISMATCH): + // Frame should start with 0x00 0x00 0xFF! + printf("Response frame doesn't start with expected preamble (00 00 FF)%s", CFG_PRINTF_NEWLINE); + break; + case (PN532_ERROR_APPLEVELERROR): + printf("Application level error reported by PN532%s", CFG_PRINTF_NEWLINE); + break; + case (PN532_ERROR_LENCHECKSUMMISMATCH): + printf("Frame length check/checksum mismatch%s", CFG_PRINTF_NEWLINE); + break; + } // Print the card details if possible if (!error) @@ -132,7 +160,6 @@ int main (void) -------- ------- ----------------------- --------- 00 04 08 NXP Mifare Classic 1K 4 bytes */ - printf("%s", CFG_PRINTF_NEWLINE); printf("%-12s: %d %s", "Tags Found", response[7], CFG_PRINTF_NEWLINE); printf("%-12s: %02X %02X %s", "SENS_RES", response[9], response[10], CFG_PRINTF_NEWLINE); printf("%-12s: %02X %s", "SEL_RES", response[11], CFG_PRINTF_NEWLINE); diff --git a/tools/examples/sensors/pn532/ISO14443A_ID/readme.txt b/tools/examples/sensors/pn532/ISO14443A_ID/readme.txt index 020a1fd..ece0dda 100644 --- a/tools/examples/sensors/pn532/ISO14443A_ID/readme.txt +++ b/tools/examples/sensors/pn532/ISO14443A_ID/readme.txt @@ -5,7 +5,8 @@ the RF field, and then try to determine the specific card model (SENS_RES and SEL_RES) as well as the card's NFCID. All information will be sent to USBCDC by default, with the -PN532 breakout board connected via UART. +PN532 breakout board connected via either UART or I2C (the +bus can be selected in PN532_bus.h). HOW TO USE THIS EXAMPLE ============================================================ @@ -19,6 +20,20 @@ HOW TO USE THIS EXAMPLE 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. @@ -28,3 +43,47 @@ HOW TO USE THIS EXAMPLE (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 card is placed in the field you should see results +similar to the following (results shown for several +different card types): + + Waiting for an ISO14443A card (Mifare Classic, etc.) + + Received : 00 00 ff 0c f4 d5 4b 01 01 00 04 08 04 9e b3 6e 66 a9 00 + Tags Found : 1 + SENS_RES : 00 04 + SEL_RES : 08 + NFCID : 9e b3 6e 66 + Seems to be a Mifare Classic 1K Card + + Waiting for an ISO14443A card (Mifare Classic, etc.) + + Received : 00 00 ff 0c f4 d5 4b 01 01 00 02 18 04 8a 4c b5 12 23 00 + Tags Found : 1 + SENS_RES : 00 02 + SEL_RES : 18 + NFCID : 8a 4c b5 12 + + Waiting for an ISO14443A card (Mifare Classic, etc.) + + Received : 00 00 ff 0f f1 d5 4b 01 01 00 44 00 07 04 7b cb 51 96 22 80 c0 00 + Tags Found : 1 + SENS_RES : 00 44 + SEL_RES : 00 + NFCID : 04 7b cb 51 96 22 80 + + Waiting for an ISO14443A card (Mifare Classic, etc.) + + Received : 00 00 ff 0c f4 d5 4b 01 01 00 04 08 04 6e 8a e2 b0 44 00 + Tags Found : 1 + SENS_RES : 00 04 + SEL_RES : 08 + NFCID : 6e 8a e2 b0 + Seems to be a Mifare Classic 1K Card + + Waiting for an ISO14443A card (Mifare Classic, etc.) +