Move MFRC522 to dedicated SPI3_HOST bus (SCK16/MOSI17/MISO13/CS26) separate from display SPI2

This commit is contained in:
2026-09-10 07:13:15 +02:00
parent 05d8012c8b
commit 12690657cc
3 changed files with 57 additions and 32 deletions

View File

@@ -11,17 +11,23 @@
#include "hal/gpio_types.h"
#include "driver/spi_master.h"
/* Shared SPI2_HOST (VSPI) bus.
* NOTE: on 7-pin ST7789 modules, the display labels these SDA (MOSI) and
* SCL (SCK) - they tap the SAME shared bus as the MFRC522. */
/* SPI2_HOST (VSPI): dedicated to the ST7789 display.
* On 7-pin ST7789 modules the display labels these SDA (MOSI) and
* SCL (SCK). */
#define HW_SPI_HOST (SPI2_HOST)
#define HW_SPI_SCK_GPIO (GPIO_NUM_18) /* display SCL + MFRC522 SCK */
#define HW_SPI_MOSI_GPIO (GPIO_NUM_23) /* display SDA + MFRC522 MOSI */
#define HW_SPI_MISO_GPIO (GPIO_NUM_19) /* MFRC522 MISO only */
#define HW_SPI_SCK_GPIO (GPIO_NUM_18) /* display SCL */
#define HW_SPI_MOSI_GPIO (GPIO_NUM_23) /* display SDA */
#define HW_SPI_MISO_GPIO (GPIO_NUM_19) /* unused by display; kept for bus */
/* MFRC522 RFID reader */
#define HW_RC522_CS_GPIO (GPIO_NUM_5)
#define HW_RC522_RST_GPIO (GPIO_NUM_22)
/* MFRC522 RFID reader - OWN SPI3_HOST (HSPI) bus, separate from the display.
* Using a independent controller avoids any bus interference between the
* panel and the reader. */
#define HW_RFID_SPI_HOST (SPI3_HOST)
#define HW_RFID_SCK_GPIO (GPIO_NUM_16)
#define HW_RFID_MOSI_GPIO (GPIO_NUM_17)
#define HW_RFID_MISO_GPIO (GPIO_NUM_13)
#define HW_RC522_CS_GPIO (GPIO_NUM_26)
#define HW_RC522_RST_GPIO (GPIO_NUM_22)
/* ST7789 display - 7-pin breakout: CS / DC / RST / SDA / SCL / GND / VCC.
* SDA and SCL share the SPI bus above (SCL=HW_SPI_SCK, SDA=HW_SPI_MOSI). */

View File

@@ -63,10 +63,18 @@ static void on_picc_state_changed(void *arg, esp_event_base_t base, int32_t even
esp_err_t rfid_manager_init(void)
{
/* Dedicated SPI3_HOST (HSPI) bus for the reader - independent controller
* so the display (SPI2_HOST) and the RFID never share bus timing. The
* rc522 driver will call spi_bus_initialize() itself on this host. */
static spi_bus_config_t rfid_bus_cfg = {
.sclk_io_num = HW_RFID_SCK_GPIO,
.mosi_io_num = HW_RFID_MOSI_GPIO,
.miso_io_num = HW_RFID_MISO_GPIO,
};
rc522_spi_config_t driver_config = {
.host_id = HW_SPI_HOST,
/* Bus already owned by spi_bus_manager: attaching as an extra device. */
.bus_config = NULL,
.host_id = HW_RFID_SPI_HOST,
.bus_config = &rfid_bus_cfg,
.dev_config = {
.spics_io_num = HW_RC522_CS_GPIO,
.clock_speed_hz = RC522_SPI_CLK_HZ,