Skip to content

Commit

Permalink
Merge pull request #112 from caternuson/iss45_alt_spi
Browse files Browse the repository at this point in the history
Add alternate SPI and some misc clean up
  • Loading branch information
caternuson authored Mar 1, 2023
2 parents 22e21a3 + 3293c64 commit ac1ed31
Show file tree
Hide file tree
Showing 15 changed files with 206 additions and 275 deletions.
7 changes: 4 additions & 3 deletions Adafruit_PN532.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ Adafruit_PN532::Adafruit_PN532(uint8_t irq, uint8_t reset, TwoWire *theWire)
@brief Instantiates a new PN532 class using hardware SPI.
@param ss SPI chip select pin (CS/SSEL)
@param theSPI pointer to the SPI bus to use
*/
/**************************************************************************/
Adafruit_PN532::Adafruit_PN532(uint8_t ss) {
Adafruit_PN532::Adafruit_PN532(uint8_t ss, SPIClass *theSPI) {
_cs = ss;
spi_dev =
new Adafruit_SPIDevice(ss, 1000000, SPI_BITORDER_LSBFIRST, SPI_MODE0);
spi_dev = new Adafruit_SPIDevice(ss, 1000000, SPI_BITORDER_LSBFIRST,
SPI_MODE0, theSPI);
}

/**************************************************************************/
Expand Down
4 changes: 2 additions & 2 deletions Adafruit_PN532.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@
class Adafruit_PN532 {
public:
Adafruit_PN532(uint8_t clk, uint8_t miso, uint8_t mosi,
uint8_t ss); // Software SPI
Adafruit_PN532(uint8_t ss); // Hardware SPI
uint8_t ss); // Software SPI
Adafruit_PN532(uint8_t ss, SPIClass *theSPI = &SPI); // Hardware SPI
Adafruit_PN532(uint8_t irq, uint8_t reset,
TwoWire *theWire = &Wire); // Hardware I2C
Adafruit_PN532(uint8_t reset, HardwareSerial *theSer); // Hardware UART
Expand Down
46 changes: 6 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,13 @@


This is a library for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
This library works with the Adafruit NFC breakout

* https://www.adafruit.com/products/364

Check out the links above for our tutorials and wiring diagrams
These chips use I2C or SPI to communicate.

Check out the links above for our tutorials and wiring diagrams
These chips use I2C or SPI to communicate.

<!-- START COMPATIBILITY TABLE -->

## Compatibility

MCU | Tested Works | Doesn't Work | Not Tested | Notes
------------------ | :----------: | :----------: | :---------: | -----
Atmega328 @ 16MHz | X | | | SPI &amp; I2C Works
Atmega328 @ 12MHz | X | | | SPI &amp; I2C Works
Atmega32u4 @ 16MHz | X | | | Follow instructions at https://learn.adafruit.com/adafruit-pn532-rfid-nfc/shield-wiring#using-with-the-arduino-leonardo-and-yun to move pin 2.
Atmega32u4 @ 8MHz | X | | | SPI &amp; I2C Works
ESP8266 | | X | | SPI only, I2C clock stretching not supported
ESP32 | X | | | SPI works; I2C works using IRQ and without sharing the I2C bus.
Atmega2560 @ 16MHz | X | | | SPI &amp; I2C Works
ATSAM3X8E | X | | | SPI &amp; I2C Works
ATSAM21D | | X | | SPI only, I2C clock stretching not supported. Use programming port.
ATtiny85 @ 16MHz | | | X |
ATtiny85 @ 8MHz | | | X |
Intel Curie @ 32MHz | | | X |
STM32F2 | | | X |

* ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
* ATmega328 @ 12MHz : Adafruit Pro Trinket 3V
* ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0
* ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro
* ESP8266 : Adafruit Huzzah
* ESP32 : WROOM
* ATmega2560 @ 16MHz : Arduino Mega
* ATSAM3X8E : Arduino Due
* ATSAM21D : Arduino Zero, M0 Pro
* ATtiny85 @ 16MHz : Adafruit Trinket 5V
* ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V

<!-- END COMPATIBILITY TABLE -->
# Dependencies
* [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO)

Expand Down Expand Up @@ -76,11 +42,11 @@ Note that the formatting output by `clang-format` is what the automated formatti
### clang-format resources
* [Binary builds and source available on the LLVM downloads page](https://releases.llvm.org/download.html)
* [Documentation and IDE integration](https://clang.llvm.org/docs/ClangFormat.html)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada & Kevin Townsend for Adafruit Industries.
Written by Limor Fried/Ladyada & Kevin Townsend for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution

Expand Down
27 changes: 12 additions & 15 deletions examples/apduToBlackBerry/apduToBlackBerry.ino
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
/**
Copyright (c) 2011, 2012, 2013 Research In Motion Limited.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -81,16 +81,13 @@ void setup() {
}
}

Serial.print("Found chip PN5");
Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. ");
Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.');
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);

// configure board to read RFID tags
nfc.SAMConfig();

nfc.begin();
}

Expand Down Expand Up @@ -126,7 +123,7 @@ void loop(void) {
// Serial.print(' ');
//}
//Serial.println();
}
}
else {
//Serial.println("Doesn't seem to be a color...");
}
Expand All @@ -137,13 +134,13 @@ void loop(void) {
;
}
delay(10);
}
}
else {
//Serial.println("It's gone...");
break;
}
}
}
}
else {
//Serial.print("Trying again...");
}
Expand Down
37 changes: 17 additions & 20 deletions examples/iso14443a_uid/iso14443a_uid.ino
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/**************************************************************************/
/*!
/*!
@file iso14443a_uid.pde
@author Adafruit Industries
@license BSD (see license.txt)
This example will attempt to connect to an ISO14443A
card or tag and retrieve some basic information about it
that can be used to determine what type of card it is.
that can be used to determine what type of card it is.
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
Expand Down Expand Up @@ -66,40 +66,37 @@ void setup(void) {
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("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);

// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);

// configure board to read RFID tags
nfc.SAMConfig();


Serial.println("Waiting for an ISO14443A card");
}

void loop(void) {
boolean 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)
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

if (success) {
Serial.println("Found a card!");
Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
Serial.print("UID Value: ");
for (uint8_t i=0; i < uidLength; i++)
for (uint8_t i=0; i < uidLength; i++)
{
Serial.print(" 0x");Serial.print(uid[i], HEX);
Serial.print(" 0x");Serial.print(uid[i], HEX);
}
Serial.println("");
// Wait 1 second before continuing
Expand Down
29 changes: 13 additions & 16 deletions examples/iso14443as_target/iso14443as_target.ino
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/**************************************************************************/
/*!
/*!
@file iso14443as_target.pde
@original Adafruit Industries
@modified Salvador Mendoza(@Netxing)
@license BSD (see license.txt)
This example will attempt to mimic an ISO14443A smart card
and retrieve some basic information from a PoS or terminal,
this can be used to establish a communication process.
this can be used to establish a communication process.
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
Expand Down Expand Up @@ -68,20 +68,17 @@ void setup(void) {
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("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);

// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);

// configure board to read RFID tags
nfc.SAMConfig();


Serial.println("As Target... Approach the NFC PN532 Board to a PoS or terminal!");
delay(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ void setup(void) {
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);

// configure board to read RFID tags
nfc.SAMConfig();
}

void loop(void) {
Expand Down
3 changes: 0 additions & 3 deletions examples/mifareclassic_memdump/mifareclassic_memdump.ino
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ void setup(void) {
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

// configure board to read RFID tags
nfc.SAMConfig();

Serial.println("Waiting for an ISO14443A Card ...");
}

Expand Down
Loading

0 comments on commit ac1ed31

Please sign in to comment.