I have a project using the RC522 RFID module with my Arduino Uno board and miguelbalboa's rfid library. The example code and every other code I find on the internet work pooling the device in order to know if there is a new card present, but I intend to work with a interrupt-driven approach. I have the proper knowledge to do the hardware/arduino part, but I'm having trouble generating an interrupt in the IRQ pin when the card is present. Have anyone succeded on this?
Edit: Connection: RST -> 8
SS-> 9
MOSI -> 11
MISO -> 12
SCK -> 13
IRQ -> 2
Code:
#include <SPI.h>
#include <MFRC522.h>
#include <String.h>
#define RST_PIN 8
#define SS_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup()
{
Serial.begin(9600); // 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
mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
mfrc522.PCD_WriteRegister(MFRC522::ComIEnReg, 0x7F); //Enable all interrupts
mfrc522.PCD_WriteRegister(MFRC522::DivIEnReg, 0x14);
Serial.println(F("Ready..."));
attachInterrupt(0, isr, RISING);
}
void loop()
{
}
void isr()
{
Serial.println(F("Interrupt"));
mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
}
Result: I only get the "Ready..." on the Serial Monitor, no matter if there is a card present or not.