miguelbalboa / rfid

Arduino RFID Library for MFRC522
The Unlicense
2.73k stars 1.42k forks source link

Both HSPI and VSPI pins pulled down. Those pins cannot be used as GPIOs. Even when using a single SPI bus. #588

Closed EricRafaelP closed 1 year ago

EricRafaelP commented 1 year ago

Step 1: Describe your environment

Step 2: Describe the problem

The library is somehow enabling HSPI in addition to VSPI, thus pulling down pins for both SPI buses. Those pins cannot be pulled up (therefore taking 8 pins to work instead of 4).

Expected Results:

Relevant Code:

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

#define SS_PIN 5
#define RST_PIN 32
#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
#define KEYPAD_INT        33

volatile bool green_button_rise = false;
volatile bool red_button_rise = false;

//MFRC522 rfid(RFID_SS, RFID_RST); // Instance of the class
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);
  //SPI.begin(); // Init SPI bus
  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;
}
Rotzbua commented 1 year ago

Wrong repo. Contact code owner @yoprogramo .