YX ZHANG
/
PN532_GPIO
gpio demo
Fork of PN532_ReadUid by
Revision 1:b90509addac2, committed 2017-12-28
- Comitter:
- zhangyx
- Date:
- Thu Dec 28 03:06:15 2017 +0000
- Parent:
- 0:54a12c4b19c2
- Commit message:
- gpio demo
Changed in this revision
LibPN532.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 54a12c4b19c2 -r b90509addac2 LibPN532.lib --- a/LibPN532.lib Tue Sep 13 06:18:59 2016 +0000 +++ b/LibPN532.lib Thu Dec 28 03:06:15 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/dotnfc/code/LibPN532/#b5922b3b3257 +https://os.mbed.com/users/zhangyx/code/LibPN532/#d8e57d5776b3
diff -r 54a12c4b19c2 -r b90509addac2 main.cpp --- a/main.cpp Tue Sep 13 06:18:59 2016 +0000 +++ b/main.cpp Thu Dec 28 03:06:15 2017 +0000 @@ -12,52 +12,19 @@ #include "PN532_SPI.h" #include "PN532_I2C.h" -DigitalOut ledBrd (LED1); // arducleo onboard led - -DigitalOut ledNFC (D9); // status led - -DigitalOut rstNFC (D4); // pn532 chip reset control - -PwmOut buz(PB_1); - Serial pc(SERIAL_TX, SERIAL_RX); // ----------------------------------------- HSU -//HardwareSerial pn532_hsu (PC_10, PC_11); -//PN532_HSU pn532_if (pn532_hsu); - -// ----------------------------------------- SPI -SPI pn532_spi (SPI_MOSI, SPI_MISO, SPI_SCK); -PN532_SPI pn532_if (pn532_spi, SPI_CS); - -// ----------------------------------------- I2C -//I2C pn532_i2c (I2C_SDA, I2C_SCL); -//PN532_I2C pn532_if (pn532_i2c); - - +HardwareSerial pn532_hsu (PC_10, PC_11); +PN532_HSU pn532_if (pn532_hsu); PN532 nfc(pn532_if); /*============================================================================== - * \brief reset the pn532 chip - */ -void reset_chip (void) -{ - rstNFC = 0; - wait_ms (100); - rstNFC = 1; -} - - -/*============================================================================== * \brief init the peripheral */ void setup(void) { - ledBrd = 0; - ledNFC = 0; - reset_chip (); - uint32_t versiondata = 0; pc.baud(115200); pc.printf ("Hello!\n"); @@ -93,62 +60,23 @@ /*============================================================================== - * \brief find a tag - */ -void loop(void) -{ - bool success; - uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID - uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) - - // configure board to read RFID tags - nfc.SAMConfig(); - - // Wait for an ISO14443A type cards (Mifare, etc.). When one is found - // 'uid' will be populated with the UID, and uidLength will indicate - // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) - success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); - - printf ("\n"); - - if (success) { - tone (buz, 800); // turn on the buzzer - ledNFC = 1; // led on - - pc.printf("Found a card!\n"); - - pc.printf("UID Length: %d bytes\n", uidLength); - pc.printf("UID Value: "); - - for (uint8_t i=0; i < uidLength; i++) - pc.printf(" 0x%02X", uid[i]); - - pc.printf("\n"); - - wait_ms (100); - tone (buz, 0); // turn off the buzzer - - // wait until the card is taken away - while (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength, 500)) {} - - ledNFC = 0; // led off - } else { - // PN532 probably timed out waiting for a card - pc.printf("\nTimed out waiting for a card\n"); - ledNFC = 0; - wait_ms (200); - } -} - - -/*============================================================================== * \brief main entry */ int main() { setup(); - while (1) - loop (); + //PN532 GPIO 例子 + //对于P3 + nfc.writeGPIOP3(PN532_GPIO_P30); //把P30设置为1,其余P3设置为0 + nfc.writeGPIOP3(PN532_GPIO_P30|PN532_GPIO_P32); //把P30,P32设置为1,其余P3设置为0 + nfc.writeGPIOP3(0); //把P3全部设置为0 + + //对于P7 + nfc.writeGPIOP7(PN532_GPIO_P70); //把P70设置为1,其余P7设置为0 + nfc.writeGPIOP7(PN532_GPIO_P70|PN532_GPIO_P72); //把P70,P72设置为1,其余P7设置为0 + nfc.writeGPIOP7(0); //把P7全部设置为0 + + while (1); }