Problemas com comunicação ESP32 S3 e módulo RC522

Olá pessoal! Estou tentando comunicar, sem sucesso, um ESP32 S3 N16R8 com um módulo RFID RC522. Estou usando esta programação (ela é o auto teste que vem junto com a library)

// ESP32-S3-DevKitC-1 - ESP32_S3 to MFRC522 CheckFirmware test

/*
 * --------------------------------------------------------------------------------------------------------------------
 * Example to test your firmware.
 * --------------------------------------------------------------------------------------------------------------------
 * This is a MFRC522 library example; for further details and other examples see: https://github.com/OSSLibraries/Arduino_MFRC522v2
 * 
 * This example test the firmware of your MFRC522 reader module, only known version can be checked. If the test passed
 * it do not mean that your module is faultless! Some modules have bad or broken antennas or the PICC is broken.
 * 
 * @author Rotzbua
 * @license Released into the public domain.
 * 
 * Typical pin layout used:
 * -----------------------------------------------------------------------------------------
 *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
 *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
 * Signal      Pin          Pin           Pin       Pin        Pin              Pin
 * -----------------------------------------------------------------------------------------
 * SPI SS      SDA(SS)      10            53        D10        10               10
 * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
 * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
 * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
 *
 * Not found? For more see: https://github.com/OSSLibraries/Arduino_MFRC522v2#pin-layout
 */

// ESP32_S3_DevKit_1 connections
// ESP32_S3 SS  pin GPIO 10   to MFRC522 card SS (marked SDA on PCB)
// ESP32_S3 SCK pin GPIO12  to MFRC522 card  SCK
// ESP32_S3 MISO pin GPIO13  to MFRC522 card  MISO
// ESP32_S3 MOSI pin GPIO11  to MFRC522 card  MOSI
// connect ESP32_S3 GND and 3.3V to MFRC522 GND and 3V3

#include <MFRC522v2.h>
#include <MFRC522DriverSPI.h>
//#include <MFRC522DriverI2C.h>
#include <MFRC522DriverPinSimple.h>
#include <MFRC522Debug.h>

MFRC522DriverPinSimple ss_pin(10); // Configurable, see typical pin layout above.

MFRC522DriverSPI driver{ss_pin}; // Create SPI driver.
//MFRC522DriverI2C driver{}; // Create I2C driver.
MFRC522 mfrc522{driver};  // Create MFRC522 instance.

/**
 * Check firmware only once at startup.
 */
void setup() {
  Serial.begin(115200);  // Initialize serial communications with the PC for debugging.
  while (!Serial);     // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4).
  mfrc522.PCD_Init();  // Init MFRC522 board.
  
  Serial.println(F("*****************************"));
  Serial.println(F("MFRC522 Digital self test"));
  Serial.println(F("*****************************"));
  MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial);  // Show version of PCD - MFRC522 Card Reader.
  Serial.println(F("-----------------------------"));
  Serial.println(F("Only known versions supported"));
  Serial.println(F("-----------------------------"));
  Serial.println(F("Performing test..."));
  bool result = mfrc522.PCD_PerformSelfTest(); // Perform the test.
  Serial.println(F("-----------------------------"));
  Serial.print(F("Result: "));
  if (result)
    Serial.println(F("OK"));
  else
    Serial.println(F("DEFECT or UNKNOWN"));
  Serial.println();
}

void loop() {} // nothing to do

Porém está dando erro e o serial está retornando o seguinte:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3818,len:0x109c
load:0x403c9700,len:0x4
load:0x403c9704,len:0xb50
load:0x403cc700,len:0x2fe4
entry 0x403c98ac
*****************************
MFRC522 Digital self test
*****************************
Firmware Version: 0xB2 = FM17522_1
-----------------------------
Only known versions supported
-----------------------------
Performing test...
-----------------------------
Result: DEFECT or UNKNOWN

Até agora já tentei:

  • Refiz a montagem com fios de protoboard e fios menores
  • Testei com outro módulo RC522
  • Testei continuidade entre cada pino, revisando conexão e se a pinagem estava certa

Olá Nicolas!
Pelo código, não dá para ter certeza se todos pinos da SPI estão definidos corretamente.
Observe que a comunicação SPI requer no mínimo quatro pinos: um para clock (SCK), um para chip select(CS)/slave select (SS), um MISO (Master Input Slave Output) para receber os dados e um MOSI (Master Output, Slave Input) para enviar dados.
Além de conectar corretamente, no software você deve informar ao driver SPI quais pinos você vai usar para cada sinal. A biblioteca MFRC522v2 provavelmente tem uma pinagem default.
Em todo caso, tente fazer incluir um SPI.begin() logo após o comando mfrc522.PCD_Init();:


mfrc522.PCD_Init();

// Definição dos Pinos SPI para o ESP32-S3:
static const uint8_t S3_SS = 10;
static const uint8_t S3_SCK = 12;
static const uint8_t S3_MISO = 13;
static const uint8_t S3_MOSI = 11;

// Inicializar pinos da SPI do S3:
spi.begin(S3_SCK, S3_MISO, S3_MOSI, S3_SS);

Isso costuma resolver.
Abraços!

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