Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Be able to use diferent SPI bus #571

Closed
wants to merge 4 commits into from

Conversation

yoprogramo
Copy link

Q A
Bug fix? no
New feature? yes
Doc update? no
BC breaks? no
Deprecations? no
Fixed tickets #521 #520

This is the work of @devrim-oguz just resubmitted and tested in another board. In my case I have tested on Lilygo T-Display where it is impossible to use SPI due Display is attached internally and the MISO and MOSI pins are not exposed, so, I try this modification with this values:

SPI1_CLK=25
SPI1_MISO=27
SPI1_MOSI=26
SS_PIN=33
RST_PIN=32

And this code works flawless along with the enclosed display:

SPIClass RFID_SPI(HSPI);
MFRC522 mfrc522(SS_PIN, RST_PIN,RFID_SPI);
RFID_SPI.begin(SPI1_CLK, SPI1_MISO, SPI1_MOSI, SS_PIN);
mfrc522.PCD_Init();	

@Rotzbua
Copy link
Collaborator

Rotzbua commented Sep 11, 2021

Thanks for your pr.

Please notice development status:
https://github.com/miguelbalboa/rfid#development

I created a fork with more customization options:
#522

Best

@Rotzbua Rotzbua closed this Sep 11, 2021
@EricRafaelP
Copy link

EricRafaelP commented Nov 16, 2022

I tried to use this fork without success. I'm able to read cards but the pins on HSPI (I'm using VSPI) that are wired to button interrupts do not work because this library is setting the pin as down. I've tried the exact same code without the begins and it works:

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

```
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants