Pullup (ISRs) not working on ESP32 when using SPI w/ MFRC522 library (RFID)

Hi!

I'm having issues using pins as inputs with internal (or external) pullups when using the SPI / MFRC522 (RFID) library with the ESP32 on the Arduino IDE. I've tried using the exact same code with and without that library and the MFRC522 library is pulling down both HSPI and VSPI pins, therefore preventing me from using the "unused" pins for button interrupts. I'm using only one SPI bus, and using the VPSI as that should be the one selected by default by the library. The puzzling thing here is that even GPIO 16 that has nothing to do with SPI, stops working as an interrupt too.

Here's my code. Again, the RFID part works, but when added, this part stops the pullups (and interrupts) from working. The interrupts work fine when I remove the calls from the MFRC522 library. Any help would be greatly appreciated!

#include <SPI.h>
#include <MFRC522.h>

#define RFID_RST          32
#define SPI_MOSI          23
#define SPI_MISO          19
#define SPI_SCK           18
#define RFID_SS           5

#define GREEN_BTN          13
#define RED_BTN           16

volatile bool green_button_rise = false;
volatile bool red_button_rise = false;
 
SPIClass RFID_SPI(VSPI);
MFRC522 rfid(RFID_SS, RFID_RST,RFID_SPI);
MFRC522::MIFARE_Key key; 

// Init array that will store new NUID 
byte nuidPICC[4];

void setup() { 
  Serial.begin(115200);
  RFID_SPI.begin(SPI_SCK,SPI_MISO,SPI_MOSI,RFID_SS);
  rfid.PCD_Init(); // Init MFRC522 

  for (byte i = 0; i < 6; i++) {
    key.keyByte[i] = 0xFF;
  }

  // ********* PIN SETUP ********* 
  pinMode(GREEN_BTN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(GREEN_BTN), greenButtonISR, FALLING);
  pinMode(RED_BTN, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(RED_BTN), redButtonISR, FALLING);

}
 
void loop() {

  // Look for new cards
  if ( ! rfid.PICC_IsNewCardPresent())
    return;

  // Verify if the NUID has been read
  if ( ! rfid.PICC_ReadCardSerial())
    return;
  
 for (byte i = 0; i < 4; i++) {
      nuidPICC[i] = rfid.uid.uidByte[i];
    }
   
  printHex(rfid.uid.uidByte, rfid.uid.size);
    Serial.println();
   rfid.PICC_HaltA();
  
  rfid.PCD_StopCrypto1();

  if(green_button_rise){
        green_button_rise = false;
        Serial.println("Green button pressed");
      }

   if(red_button_rise){
        red_button_rise = false;
        Serial.println("Red button pressed");
      }
  
}


void printHex(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    Serial.print(buffer[i] < 0x10 ? " 0" : " ");
    Serial.print(buffer[i], HEX);
  }
}


// ********* Interrupts *********
void greenButtonISR() {
  green_button_rise = true;
}

void redButtonISR(){
  red_button_rise = true;
}

Why do you instantiate a new SPI class? If you're actually using the ESP32 (without any additional characters or digits as p.e. ESP32C3) the standard SPI object already is on the VSPI bus. I don't know what the ESP32 OS does if the same hardware is initialized twice.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.