Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "emulatetag.h"
- #include "NdefMessage.h"
- #include <avr/wdt.h>
- #include <SPI.h>
- #include <PN532_SPI.h>
- #include "PN532.h"
- //MEGA
- #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
- PN532_SPI pn532spi(SPI, 53);
- //UNO
- #elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
- PN532_SPI pn532spi(SPI, 10);
- #endif
- #define PN532IRQPIN (2)
- PN532 nfc(pn532spi);
- void cardreading();
- void setup() {
- // put your setup code here, to run once:
- //pinMode(PN532IRQPIN, INPUT);
- Serial.begin(115200);
- Serial.println("\nHello!");
- nfc.begin();
- uint32_t versiondata = nfc.getFirmwareVersion();
- if (! versiondata) {
- Serial.print("Didn't find PN53x board");
- while (1); // halt
- }
- // Got ok data, print it out!
- Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
- Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
- Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
- nfc.SAMConfig();
- //pinMode(PN532IRQPIN, INPUT_PULLUP);
- //nfc.setPassiveActivationRetries(0x00);
- attachInterrupt(digitalPinToInterrupt(PN532IRQPIN), cardreading, FALLING);
- //attachInterrupt(0, cardreading, FALLING);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- }
- void cardreading()
- {
- Serial.println("Interrupted");
- uint8_t 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)
- // 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)
- //nfc.inListPassiveTarget();
- success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
- if (success)
- {
- // Display some basic information about the card
- Serial.println("Found an ISO14443A card");
- Serial.print(" UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
- Serial.print(" UID Value: ");
- nfc.PrintHex(uid, uidLength);
- Serial.println("");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement