Both HSPI and VSPI pins pulled down when using single SPI bus. Remaining pins cannot be used as GPIOs.

ericrafaelp
Posts: 2
Joined: Wed Nov 16, 2022 4:55 am

Both HSPI and VSPI pins pulled down when using single SPI bus. Remaining pins cannot be used as GPIOs.

Postby ericrafaelp » Wed Nov 16, 2022 12:58 pm

When using the SPI bus, the library is somehow enabling HSPI and VSPI at the same time, thus pulling down pins for both SPI buses. Those pins cannot be pulled up (therefore taking 8 pins to work instead of 4). I need to use the remaining pins as GPIOs (in this case, as interrupts with pullup configuration). I've tried the same setup without calling the SPI functions and everything works as intended. How can I make sure that only the correct pins are called for SPI? Please note that I'm even using the default pins for VSPI. Thank you!

My environment:
OS version: Windows 10
Arduino IDE version: 1.8.16
MFRC522 Library version: 6599c0f from yoprogramo:master
Arduino device: ESP32
MFRC522 device: RC522

Code:

Code: Select all

#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;
}

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Both HSPI and VSPI pins pulled down when using single SPI bus. Remaining pins cannot be used as GPIOs.

Postby chegewara » Thu Nov 17, 2022 1:48 am

This probably should not have happen and i am suggesting to open issue on github, but in meantime this may be a workaround for you.
After calling initializing SPI you can call for all pins you want to reuse:

Code: Select all

gpio_reset_pin(PIN);

ericrafaelp
Posts: 2
Joined: Wed Nov 16, 2022 4:55 am

Re: Both HSPI and VSPI pins pulled down when using single SPI bus. Remaining pins cannot be used as GPIOs.

Postby ericrafaelp » Fri Nov 18, 2022 1:53 am

Thanks for the tip. But I cannot use that as I'm using the Arduino IDE / core.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: Both HSPI and VSPI pins pulled down when using single SPI bus. Remaining pins cannot be used as GPIOs.

Postby chegewara » Fri Nov 18, 2022 2:48 am

I know you are using arduino, but guess what, arduino is using esp-idf, so this code will just works.

Who is online

Users browsing this forum: No registered users and 69 guests