Compare commits
5 Commits
f28da27aa6
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba72b92f07 | ||
|
|
1ff0b14d2e | ||
|
|
3b760c359a | ||
|
|
c553f4df61 | ||
|
|
8f9c07f84f |
@@ -20,6 +20,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
|
||||
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
|
||||
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
|
||||
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
|
||||
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
* 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
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
* SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
|
||||
* SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15
|
||||
*
|
||||
* More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout
|
||||
*
|
||||
* Hardware required:
|
||||
* Arduino
|
||||
* PCD (Proximity Coupling Device): NXP MFRC522 Contactless Reader IC
|
||||
|
||||
@@ -163,11 +163,13 @@ MFRC522::StatusCode MFRC522::PCD_CalculateCRC( byte *data, ///< In: Pointer to
|
||||
PCD_WriteRegister(FIFODataReg, length, data); // Write data to the FIFO
|
||||
PCD_WriteRegister(CommandReg, PCD_CalcCRC); // Start the calculation
|
||||
|
||||
// Wait for the CRC calculation to complete. Each iteration of the while-loop takes 17.73μs.
|
||||
// TODO check/modify for other architectures than Arduino Uno 16bit
|
||||
// Wait for the CRC calculation to complete. Check for the register to
|
||||
// indicate that the CRC calculation is complete in a loop. If the
|
||||
// calculation is not indicated as complete in ~90ms, then time out
|
||||
// the operation.
|
||||
const uint32_t deadline = millis() + 89;
|
||||
|
||||
// Wait for the CRC calculation to complete. Each iteration of the while-loop takes 17.73us.
|
||||
for (uint16_t i = 5000; i > 0; i--) {
|
||||
do {
|
||||
// DivIrqReg[7..0] bits are: Set2 reserved reserved MfinActIRq reserved CRCIRq reserved reserved
|
||||
byte n = PCD_ReadRegister(DivIrqReg);
|
||||
if (n & 0x04) { // CRCIRq bit set - calculation done
|
||||
@@ -177,8 +179,11 @@ MFRC522::StatusCode MFRC522::PCD_CalculateCRC( byte *data, ///< In: Pointer to
|
||||
result[1] = PCD_ReadRegister(CRCResultRegH);
|
||||
return STATUS_OK;
|
||||
}
|
||||
yield();
|
||||
}
|
||||
// 89ms passed and nothing happend. Communication with the MFRC522 might be down.
|
||||
while (static_cast<uint32_t> (millis()) < deadline);
|
||||
|
||||
// 89ms passed and nothing happened. Communication with the MFRC522 might be down.
|
||||
return STATUS_TIMEOUT;
|
||||
} // End PCD_CalculateCRC()
|
||||
|
||||
@@ -422,6 +427,7 @@ void MFRC522::PCD_SoftPowerUp(){
|
||||
if(!(val & (1<<4))){ // if powerdown bit is 0
|
||||
break;// wake up procedure is finished
|
||||
}
|
||||
yield();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,22 +483,32 @@ MFRC522::StatusCode MFRC522::PCD_CommunicateWithPICC( byte command, ///< The co
|
||||
PCD_SetRegisterBitMask(BitFramingReg, 0x80); // StartSend=1, transmission of data starts
|
||||
}
|
||||
|
||||
// Wait for the command to complete.
|
||||
// In PCD_Init() we set the TAuto flag in TModeReg. This means the timer automatically starts when the PCD stops transmitting.
|
||||
// Each iteration of the do-while-loop takes 17.86μs.
|
||||
// TODO check/modify for other architectures than Arduino Uno 16bit
|
||||
uint16_t i;
|
||||
for (i = 2000; i > 0; i--) {
|
||||
// In PCD_Init() we set the TAuto flag in TModeReg. This means the timer
|
||||
// automatically starts when the PCD stops transmitting.
|
||||
//
|
||||
// Wait here for the command to complete. The bits specified in the
|
||||
// `waitIRq` parameter define what bits constitute a completed command.
|
||||
// When they are set in the ComIrqReg register, then the command is
|
||||
// considered complete. If the command is not indicated as complete in
|
||||
// ~36ms, then consider the command as timed out.
|
||||
const uint32_t deadline = millis() + 36;
|
||||
bool completed = false;
|
||||
|
||||
do {
|
||||
byte n = PCD_ReadRegister(ComIrqReg); // ComIrqReg[7..0] bits are: Set1 TxIRq RxIRq IdleIRq HiAlertIRq LoAlertIRq ErrIRq TimerIRq
|
||||
if (n & waitIRq) { // One of the interrupts that signal success has been set.
|
||||
completed = true;
|
||||
break;
|
||||
}
|
||||
if (n & 0x01) { // Timer interrupt - nothing received in 25ms
|
||||
return STATUS_TIMEOUT;
|
||||
}
|
||||
yield();
|
||||
}
|
||||
// 35.7ms and nothing happend. Communication with the MFRC522 might be down.
|
||||
if (i == 0) {
|
||||
while (static_cast<uint32_t> (millis()) < deadline);
|
||||
|
||||
// 36ms and nothing happened. Communication with the MFRC522 might be down.
|
||||
if (!completed) {
|
||||
return STATUS_TIMEOUT;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user