Xinyuan-LilyGO / LilyGo-EPD47

GNU General Public License v3.0
379 stars 119 forks source link

SPI for MFRC522, Miguel balboa's MFRC522 or MFRC522v2 used #119

Open link-ec opened 2 weeks ago

link-ec commented 2 weeks ago

Hi everyone!. Had a big time making ESP32S3-WROOM-1 labeled, 4.7 Epaper comunicate with a generic MFRC522. Tried with both libraries and some ESP-IDF stuff but totally no response

Following the datasheet of the hardware, the exposed pins (for the raspberry pins) are:

LABEL------SCHEMATICS LABEL -----DATASHEET LABEL-------------------utilities.h MOSI ------------IO10--------------FSPIIO4, SUBSPIHD, SPIIO4----------GPIO_MOSI MISO-------------IO45------------GPIO, "strapping pin" warning --------GPIO_MISO CS----------------IO39 ---------------MTCK, CLK_OUT3--------------------GPIO_CS SCLK-------------IO48------------SPI_CLK_N_DIFF, SUBSPI_CLK_DIFF-----GPIO_SCLK

The base code is the example for DumpVersionToSerial and DumpToSerial, so in loop we have the nice:

void loop() { // Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle. if ( ! mfrc522.PICC_IsNewCardPresent()) { return; }

// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
}

// Dump debug info about the card; PICC_HaltA() is automatically called
//MFRC522Debug::PICC_DumpToSerial(mfrc522, Serial, &(mfrc522.uid));

mfrc522.PICC_DumpToSerial(&(mfrc522.uid)); }

the MFRC522v2 is slight different, was commented the differences. The real headche is to begin correctly the driver and let Miguel Balboa do the trick!

Tried the normal way:

include

include

include

include "utilities.h"

MFRC522 mfrc522(SS_PIN, RST_PIN);

void setup() { Serial.begin(115200); // Initialize serial communications with the PC while (!Serial); // Do nothing mfrc522.PCD_Init(); // Init MFRC522 delay(4); // //MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial); // Show details of PCD - MFRC522 Card Reader details mfrc522.PCD_DumpVersionToSerial(); Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); }

big FAIL Com failure, is the MFRC522 properly?? ecc....

Tried doing a new class(?):

SPIClass vspi(SPI); MFRC522 mfrc522(GPIO_CS, TOUCH_INT); void setup() { Serial.begin(115200); // Initialize serial communications with the PC while (!Serial); // Do vspi.begin(GPIO_SCLK, GPIO_MISO, GPIO_MOSI, GPIO_CS); mfrc522.PCD_Init(); // Init MFRC522 delay(4); // Optional delay. Some board do need more time after init to be ready, see Readme //MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial); // Show details of PCD - MFRC522 Card Reader details mfrc522.PCD_DumpVersionToSerial(); Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks...")); }

The SPIClass vspi(SPI) can change to FSPI (Flash SPI?), HSPI (Hardware SPI), VSPI is something not allowed

The HSPI in SPIClass seems already fixed to NOT work because all pin inputs are at -1

Also tried with MFRC522v2 to put the class(?)

SPIClass vspi(SPI); //const SPISettings spiSettings = SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE0); MFRC522DriverSPI driver = {ss_pin, vspi, spiSettings}; MFRC522 mfrc522{driver}; vspi->begin(GPIO_SCLK, GPIO_MISO, GPIO_MOSI, GPIO_CS);

changing SPIClass vspi(SPI) with HSPI or FSPI

Also, with adding:

include

include

include

include "utilities.h"

include "sdkconfig.h"

include "esp_system.h"

include "driver/spi_slave.h"

include "driver/gpio.h"

include "esp_log.h"

Tried to change SPIClass vspi(SPI) with SPI2_HOST, SPI3_HOST, it compiles but goes to kernel panic or error, in Serial is Firmware Version: x

so i tried the ESP-IDF-soft way with:

spi_bus_config_t buscfg; memset(&buscfg, 0, sizeof(buscfg)); buscfg.mosi_io_num = GPIO_MOSI; buscfg.miso_io_num = GPIO_MISO; buscfg.sclk_io_num = GPIO_SCLK; buscfg.quadwp_io_num = -1; buscfg.quadhd_io_num = -1; buscfg.max_transfer_sz = 4096;

ESP_ERROR_CHECK(spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO));

mfrc522.PCD_Init();     // Init MFRC522
delay(4);               // Optional delay. Some board do need more time after init to be ready, see Readme
//MFRC522Debug::PCD_DumpVersionToSerial(mfrc522, Serial);   // Show details of PCD - MFRC522 Card Reader details

mfrc522.PCD_DumpVersionToSerial(); Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));

It compiles and i get the same fail, Is the MFRC522 properly ecc...? The error now returns to be 0x0 SPI3_HOST changed to SPI2_HOST, with HSPI, FSPI it crashes

Tried to see some signals with my cheap "oscilloscope" with ESP-IDF config and i see the RST_PIN at HIGH (this pin was setted to stay UP in all examples, with some tried to give the control to MFRC522 library but 0x0 error). Also SLCK signal appears to be repeatitive, unfortunately i cannot see the shape or take some measures with the oscilloscope.

....Also tried to change the MFRC522 board (have 5) and power with external 3V (other arduino giving 3V pin and connected the grounds together) with absolutely no success

...Also tried to change MISO with MOSI... Please HELP!