Merge branch 'new-travis' into patch-collision

This commit is contained in:
Rotzbua
2016-02-15 17:33:17 +01:00
11 changed files with 239 additions and 53 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
MFRC522.zip

View File

@@ -9,22 +9,30 @@ cache:
- "~/.platformio" - "~/.platformio"
env: env:
- PLATFORMIO_CI_SRC=examples/ChangeUID/ChangeUID.ino # add examples here and define which boards should be tested (only compile test)
- PLATFORMIO_CI_SRC=examples/DumpInfo/DumpInfo.ino - PLATFORMIO_CI_SRC=examples/ChangeUID/ChangeUID.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/firmware_check/firmware_check.ino - PLATFORMIO_CI_SRC=examples/DumpInfo/DumpInfo.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/FixBrickedUID/FixBrickedUID.ino - PLATFORMIO_CI_SRC=examples/firmware_check/firmware_check.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/MifareClassicValueBlock/MifareClassicValueBlock.ino - PLATFORMIO_CI_SRC=examples/FixBrickedUID/FixBrickedUID.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/ReadAndWrite/ReadAndWrite.ino - PLATFORMIO_CI_SRC=examples/MifareClassicValueBlock/MifareClassicValueBlock.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/ReadUidMultiReader/ReadUidMultiReader.ino - PLATFORMIO_CI_SRC=examples/MinimalInterrupt/MinimalInterrupt.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/rfid_default_keys/rfid_default_keys.ino - PLATFORMIO_CI_SRC=examples/ReadAndWrite/ReadAndWrite.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/rfid_write_personal_data/rfid_write_personal_data.ino - PLATFORMIO_CI_SRC=examples/ReadUidMultiReader/ReadUidMultiReader.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/Ntag216_AUTH/Ntag216_AUTH.ino - PLATFORMIO_CI_SRC=examples/rfid_default_keys/rfid_default_keys.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/ReadNUID/ReadNUID.ino - PLATFORMIO_CI_SRC=examples/rfid_write_personal_data/rfid_write_personal_data.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/servo_motor/servo_motor.ino - PLATFORMIO_CI_SRC=examples/Ntag216_AUTH/Ntag216_AUTH.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/RFID-Cloner/RFID-Cloner.ino - PLATFORMIO_CI_SRC=examples/ReadNUID/ReadNUID.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
- PLATFORMIO_CI_SRC=examples/servo_motor/servo_motor.ino TESTBOARD=arduino_avr,teensy
- PLATFORMIO_CI_SRC=examples/RFID-Cloner/RFID-Cloner.ino TESTBOARD=arduino_avr,arduino_arm,teensy,esp
install: install:
- pip install -U platformio - pip install -U platformio
script: script:
- platformio ci --lib=. --board=uno --board=megaatmega1280 --board=teensy31 # short the string comparison
- stringContain() { [ -z "${2##*$1*}" ]; }
# selectable board tests @Rotzbua
- board="arduino_avr"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=uno --board=megaatmega1280; else echo "skip board test of $board"; fi
- board="arduino_arm"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=due --board=zero; else echo "skip board test of $board"; fi
- board="teensy"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=teensy31; else echo "skip board test of $board"; fi
- board="esp"; if stringContain "$board" "$TESTBOARD"; then echo "check board $board"; platformio ci --lib=. --board=d1_mini; else echo "skip board test of $board"; fi

View File

@@ -1301,23 +1301,11 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
) { ) {
MIFARE_Key key; MIFARE_Key key;
// UID // Dump UID, SAK and Type
Serial.print(F("Card UID:")); PICC_DumpDetailsToSerial(uid);
for (byte i = 0; i < uid->size; i++) {
if(uid->uidByte[i] < 0x10)
Serial.print(F(" 0"));
else
Serial.print(F(" "));
Serial.print(uid->uidByte[i], HEX);
}
Serial.println();
// PICC type
PICC_Type piccType = PICC_GetType(uid->sak);
Serial.print(F("PICC type: "));
Serial.println(PICC_GetTypeName(piccType));
// Dump contents // Dump contents
PICC_Type piccType = PICC_GetType(uid->sak);
switch (piccType) { switch (piccType) {
case PICC_TYPE_MIFARE_MINI: case PICC_TYPE_MIFARE_MINI:
case PICC_TYPE_MIFARE_1K: case PICC_TYPE_MIFARE_1K:
@@ -1350,6 +1338,34 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
PICC_HaltA(); // Already done if it was a MIFARE Classic PICC. PICC_HaltA(); // Already done if it was a MIFARE Classic PICC.
} // End PICC_DumpToSerial() } // End PICC_DumpToSerial()
/**
* Dumps card info (UID,SAK,Type) about the selected PICC to Serial.
*/
void MFRC522::PICC_DumpDetailsToSerial(Uid *uid ///< Pointer to Uid struct returned from a successful PICC_Select().
) {
// UID
Serial.print(F("Card UID:"));
for (byte i = 0; i < uid->size; i++) {
if(uid->uidByte[i] < 0x10)
Serial.print(F(" 0"));
else
Serial.print(F(" "));
Serial.print(uid->uidByte[i], HEX);
}
Serial.println();
// SAK
Serial.print(F("Card SAK: "));
if(uid->sak < 0x10)
Serial.print(F("0"));
Serial.println(uid->sak, HEX);
// (suggested) PICC type
PICC_Type piccType = PICC_GetType(uid->sak);
Serial.print(F("PICC type: "));
Serial.println(PICC_GetTypeName(piccType));
} // End PICC_DumpDetailsToSerial()
/** /**
* Dumps memory contents of a MIFARE Classic PICC. * Dumps memory contents of a MIFARE Classic PICC.
* On success the PICC is halted after dumping the data. * On success the PICC is halted after dumping the data.

View File

@@ -381,16 +381,21 @@ public:
StatusCode PCD_MIFARE_Transceive(byte *sendData, byte sendLen, bool acceptTimeout = false); StatusCode PCD_MIFARE_Transceive(byte *sendData, byte sendLen, bool acceptTimeout = false);
// old function used too much memory, now name moved to flash; if you need char, copy from flash to memory // old function used too much memory, now name moved to flash; if you need char, copy from flash to memory
//const char *GetStatusCodeName(byte code); //const char *GetStatusCodeName(byte code);
const __FlashStringHelper *GetStatusCodeName(StatusCode code); static const __FlashStringHelper *GetStatusCodeName(StatusCode code);
PICC_Type PICC_GetType(byte sak); static PICC_Type PICC_GetType(byte sak);
// old function used too much memory, now name moved to flash; if you need char, copy from flash to memory // old function used too much memory, now name moved to flash; if you need char, copy from flash to memory
//const char *PICC_GetTypeName(byte type); //const char *PICC_GetTypeName(byte type);
const __FlashStringHelper *PICC_GetTypeName(PICC_Type type); static const __FlashStringHelper *PICC_GetTypeName(PICC_Type type);
// Support functions for debuging
void PCD_DumpVersionToSerial(); void PCD_DumpVersionToSerial();
void PICC_DumpToSerial(Uid *uid); void PICC_DumpToSerial(Uid *uid);
void PICC_DumpDetailsToSerial(Uid *uid);
void PICC_DumpMifareClassicToSerial(Uid *uid, PICC_Type piccType, MIFARE_Key *key); void PICC_DumpMifareClassicToSerial(Uid *uid, PICC_Type piccType, MIFARE_Key *key);
void PICC_DumpMifareClassicSectorToSerial(Uid *uid, MIFARE_Key *key, byte sector); void PICC_DumpMifareClassicSectorToSerial(Uid *uid, MIFARE_Key *key, byte sector);
void PICC_DumpMifareUltralightToSerial(); void PICC_DumpMifareUltralightToSerial();
// Advanced functions for MIFARE
void MIFARE_SetAccessBits(byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3); void MIFARE_SetAccessBits(byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3);
bool MIFARE_OpenUidBackdoor(bool logErrors); bool MIFARE_OpenUidBackdoor(bool logErrors);
bool MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors); bool MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors);

View File

@@ -13,36 +13,43 @@ Interface (SPI) interface.
Set the UID, write to sector 0, and unbrick Chinese UID changeable MIFARE cards. Set the UID, write to sector 0, and unbrick Chinese UID changeable MIFARE cards.
.. _pin layout: .. _compatible boards:
Compatible boards
----------
This library is compatible to Teensy and ESP8266, but not all examples are available for every board. Also you have to change pins, see `pin layout`_.
.. _pin layout:
Pin Layout Pin Layout
---------- ----------
The following table shows the typical pin layout used: The following table shows the typical pin layout used:
+-----------+----------+-------------------------------------------------------------+--------+ +-----------+----------+---------------------------------------------------------------+--------------------------+
| | PCD | Arduino | Teensy | | | PCD | Arduino | Teensy |
| +----------+-------------+---------+---------+---------------+-----------+--------+ | +----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| | MFRC522 | Uno | Mega | Nano v3 |Leonardo/Micro | Pro Micro | 3.1 | | | MFRC522 | Uno | Mega | Nano v3 |Leonardo / Micro | Pro Micro | 2.0 | ++ 2.0 | 3.1 |
+-----------+----------+-------------+---------+---------+---------------+-----------+--------+ +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| Signal | Pin | Pin | Pin | Pin | Pin | Pin | Pin | | Signal | Pin | Pin | Pin | Pin | Pin | Pin | Pin | Pin | Pin |
+===========+==========+=============+=========+=========+===============+===========+========+ +===========+==========+=============+=========+=========+=================+===========+========+========+========+
| RST/Reset | RST | 9 [1]_ | 5 [1]_ | D9 | RESET/ICSP-5 | RST | 9 | | RST/Reset | RST | 9 [1]_ | 5 [1]_ | D9 | RESET / ICSP-5 | RST | 7 | 4 | 9 |
+-----------+----------+-------------+---------+---------+---------------+-----------+--------+ +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI SS | SDA [3]_ | 10 [2]_ | 53 [2]_ | D10 | 10 | 10 | 10 | | SPI SS | SDA [3]_ | 10 [2]_ | 53 [2]_ | D10 | 10 | 10 | 0 | 20 | 10 |
+-----------+----------+-------------+---------+---------+---------------+-----------+--------+ +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI MOSI | MOSI | 11 / ICSP-4 | 51 | D11 | ICSP-4 | 16 | 11 | | SPI MOSI | MOSI | 11 / ICSP-4 | 51 | D11 | ICSP-4 | 16 | 2 | 22 | 11 |
+-----------+----------+-------------+---------+---------+---------------+-----------+--------+ +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI MISO | MISO | 12 / ICSP-1 | 50 | D12 | ICSP-1 | 14 | 12 | | SPI MISO | MISO | 12 / ICSP-1 | 50 | D12 | ICSP-1 | 14 | 3 | 23 | 12 |
+-----------+----------+-------------+---------+---------+---------------+-----------+--------+ +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
| SPI SCK | SCK | 13 / ICSP-3 | 52 | D13 | ICSP-3 | 15 | 13 | | SPI SCK | SCK | 13 / ICSP-3 | 52 | D13 | ICSP-3 | 15 | 1 | 21 | 13 |
+-----------+----------+-------------+---------+---------+---------------+-----------+--------+ +-----------+----------+-------------+---------+---------+-----------------+-----------+--------+--------+--------+
.. [1] Configurable, typically defined as RST_PIN in sketch/program. .. [1] Configurable, typically defined as RST_PIN in sketch/program.
.. [2] Configurable, typically defined as SS_PIN in sketch/program. .. [2] Configurable, typically defined as SS_PIN in sketch/program.
.. [3] The SDA pin might be labeled SS on some/older MFRC522 boards. .. [3] The SDA pin might be labeled SS on some/older MFRC522 boards.
.. _hardware:
Hardware Hardware
-------- --------
@@ -133,6 +140,7 @@ Troubleshooting
#. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller. #. Hardware may be corrupted, most products are from china and sometimes the quality is really poor. Contact your seller.
#. Newer versions of Mifare cards like DESFire/Ultralight maybe not work according to missing authentification, see `security`_ or different `protocol`_. #. Newer versions of Mifare cards like DESFire/Ultralight maybe not work according to missing authentification, see `security`_ or different `protocol`_.
* **My mobile phone doesn't recognize the MFRC522** or **my MFRC522 can't read data from other MFRC522** * **My mobile phone doesn't recognize the MFRC522** or **my MFRC522 can't read data from other MFRC522**
#. Card simmulation is not supported. #. Card simmulation is not supported.
@@ -146,6 +154,7 @@ Troubleshooting
#. If hardware: buy a more expensive like PN532 (supports NFC and many more, but costs about $15) #. If hardware: buy a more expensive like PN532 (supports NFC and many more, but costs about $15)
.. _license:
License License
------- -------
This is free and unencumbered software released into the public domain. This is free and unencumbered software released into the public domain.

View File

@@ -1,3 +1,8 @@
11 Feb 2016, v1.1.8
- Added examples/MinimalInterrupt/MinimalInterrupt.ino example, Interrupt example @lmmeng
- Added .gitignore file allows the project to be more easily used as a subproject. @BenWiederhake
- Added Added Teensy 2.0 & Tensy++ 2.0 pinouts to README.rst @jkutianski
16 Jan 2016, v1.1.7 16 Jan 2016, v1.1.7
- README.rst Spelling and Grammar Tweak @cuthbertnibbles - README.rst Spelling and Grammar Tweak @cuthbertnibbles
- Added examples/servo_motor/servo_motor.ino example, Arduino RFID Access Control with a Servo Motor @techied - Added examples/servo_motor/servo_motor.ino example, Arduino RFID Access Control with a Servo Motor @techied

View File

@@ -47,7 +47,7 @@ void setup() {
SPI.begin(); // Init SPI bus SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
Serial.println(F("Scan PICC to see UID, type, and data blocks...")); Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
} }
void loop() { void loop() {

View File

@@ -0,0 +1,137 @@
/**
* ----------------------------------------------------------------------------
* This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
* for further details and other examples.
*
* NOTE: The library file MFRC522.h has a lot of useful info. Please read it.
*
* Released into the public domain.
* ----------------------------------------------------------------------------
* Minimal example how to use the interrupts to read the UID of a MIFARE Classic PICC
* (= card/tag).
*
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
* Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS SDA(SS) 10 53 D10 3 10
* IRQ ? ? ? ? 2 10
* SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
*
*/
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 3 // Configurable, see typical pin layout above
#define IRQ_PIN 2
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
MFRC522::MIFARE_Key key;
volatile boolean bNewInt = false;
unsigned char regVal = 0x7F;
void activateRec(MFRC522 mfrc522);
void clearInt(MFRC522 mfrc522);
/**
* Initialize.
*/
void setup() {
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
/* read and printout the MFRC522 version (valid values 0x91 & 0x92)*/
Serial.print("Ver: 0x");
byte readReg = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.println(readReg, HEX);
/* setup the IRQ pin*/
pinMode(IRQ_PIN, INPUT_PULLUP);
/*
* Allow the ... irq to be propagated to the IRQ pin
* For test purposes propagate the IdleIrq and loAlert
*/
regVal = 0xA0; //rx irq
mfrc522.PCD_WriteRegister(mfrc522.ComIEnReg,regVal);
bNewInt = false; //interrupt flag
/*Activate the interrupt*/
attachInterrupt(digitalPinToInterrupt(IRQ_PIN), readCard, FALLING);
Serial.println("End setup");
do{ //clear a spourious interrupt at start
;
}while(!bNewInt);
bNewInt = false;
}
/**
* Main loop.
*/
void loop() {
if(bNewInt){ //new read interrupt
bNewInt = false;
Serial.print("Interrupt. ");
mfrc522.PICC_ReadCardSerial(); //read the tag data
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
Serial.println();
clearInt(mfrc522);
}
// The receiving block needs regular retriggering (tell the tag it should transmit??)
// (mfrc522.PCD_WriteRegister(mfrc522.FIFODataReg,mfrc522.PICC_CMD_REQA);)
activateRec(mfrc522);
delay(100);
} //loop()
/**
* Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
for (byte i = 0; i < bufferSize; i++) {
Serial.print(buffer[i] < 0x10 ? " 0" : " ");
Serial.print(buffer[i], HEX);
}
}
/**
* MFRC522 interrupt serving routine
*/
void readCard(){
bNewInt = true;
}
/*
* The function sending to the MFRC522 the needed commands to activate the reception
*/
void activateRec(MFRC522 mfrc522){
mfrc522.PCD_WriteRegister(mfrc522.FIFODataReg,mfrc522.PICC_CMD_REQA);
mfrc522.PCD_WriteRegister(mfrc522.CommandReg,mfrc522.PCD_Transceive);
mfrc522.PCD_WriteRegister(mfrc522.BitFramingReg, 0x87);
}
/*
* The function to clear the pending interrupt bits after interrupt serving routine
*/
void clearInt(MFRC522 mfrc522){
mfrc522.PCD_WriteRegister(mfrc522.ComIrqReg,0x7F);
}

View File

@@ -64,11 +64,16 @@ PCD_MIFARE_Transceive KEYWORD2
GetStatusCodeName KEYWORD2 GetStatusCodeName KEYWORD2
PICC_GetType KEYWORD2 PICC_GetType KEYWORD2
PICC_GetTypeName KEYWORD2 PICC_GetTypeName KEYWORD2
# Support functions for debuging
PCD_DumpVersionToSerial KEYWORD2 PCD_DumpVersionToSerial KEYWORD2
PICC_DumpToSerial KEYWORD2 PICC_DumpToSerial KEYWORD2
PICC_DumpDetailsToSerial KEYWORD2
PICC_DumpMifareClassicToSerial KEYWORD2 PICC_DumpMifareClassicToSerial KEYWORD2
PICC_DumpMifareClassicSectorToSerial KEYWORD2 PICC_DumpMifareClassicSectorToSerial KEYWORD2
PICC_DumpMifareUltralightToSerial KEYWORD2 PICC_DumpMifareUltralightToSerial KEYWORD2
# Advanced functions for MIFARE
MIFARE_SetAccessBits KEYWORD2 MIFARE_SetAccessBits KEYWORD2
MIFARE_OpenUidBackdoor KEYWORD2 MIFARE_OpenUidBackdoor KEYWORD2
MIFARE_SetUid KEYWORD2 MIFARE_SetUid KEYWORD2

View File

@@ -7,7 +7,7 @@
"type": "git", "type": "git",
"url": "https://github.com/miguelbalboa/rfid.git" "url": "https://github.com/miguelbalboa/rfid.git"
}, },
"version": "1.1.7", "version": "1.1.8",
"exclude": "doc", "exclude": "doc",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": ["atmelavr", "ststm32", "teensy"] "platforms": ["atmelavr", "ststm32", "teensy"]

View File

@@ -1,5 +1,5 @@
name=MFRC522 name=MFRC522
version=1.1.7 version=1.1.8
author=GithubCommunity author=GithubCommunity
maintainer=miguelbalboa maintainer=miguelbalboa
sentence=Arduino RFID Library for MFRC522 (SPI) sentence=Arduino RFID Library for MFRC522 (SPI)