ESP-32 S3 Cannot initialize multiple spi devices (host_id not initialized)
Posted: Tue Nov 14, 2023 5:39 pm
Hi,
When i'm trying to initialize multiple devices, i get the error:
spi_master: spi_master_init_driver(200): host_id not initialized
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x4037d06c
file: "src/board/board_spi.cpp" line 35
func: void NFC_SPI_Init()
expression: ret
Unsure what's wrong in my code, i tried modifying the host values but i still get an error or a black screen / rfid reader not working,
any help might be appreciated:
lgfx setup:
main: The gui init lgvl with the lgfx config
NFC:
When i'm trying to initialize multiple devices, i get the error:
spi_master: spi_master_init_driver(200): host_id not initialized
ESP_ERROR_CHECK failed: esp_err_t 0x103 (ESP_ERR_INVALID_STATE) at 0x4037d06c
file: "src/board/board_spi.cpp" line 35
func: void NFC_SPI_Init()
expression: ret
Unsure what's wrong in my code, i tried modifying the host values but i still get an error or a black screen / rfid reader not working,
any help might be appreciated:
lgfx setup:
- class LGFX : public lgfx::LGFX_Device
- {
- lgfx::Panel_ILI9488 _panel_instance;
- lgfx::Bus_SPI _bus_instance;
- lgfx::Light_PWM _light_instance;
- lgfx::Touch_GT911 _touch_instance;
- public:
- LGFX(void)
- {
- {
- auto cfg = _bus_instance.config();
- cfg.spi_host = SPI2_HOST;
- cfg.spi_mode = 0;
- cfg.freq_write = 40000000;
- cfg.freq_read = 16000000;
- cfg.spi_3wire = true;
- cfg.use_lock = true;
- cfg.dma_channel = SPI2_HOST; /*SPI_DMA_CH_AUTO;*/
- cfg.pin_sclk = 18;
- cfg.pin_mosi = 13;
- cfg.pin_miso = 19;
- cfg.pin_dc = 16;
- _bus_instance.config(cfg);
- _panel_instance.setBus(&_bus_instance);
- }
- {
- auto cfg = _panel_instance.config();
- cfg.pin_cs = 15;
- cfg.pin_rst = -1;
- cfg.pin_busy = -1;
- cfg.panel_width = 320;
- cfg.panel_height = 480;
- cfg.offset_x = 0;
- cfg.offset_y = 0;
- cfg.offset_rotation = 0;
- cfg.dummy_read_pixel = 8;
- cfg.dummy_read_bits = 1;
- cfg.readable = true;
- cfg.invert = false;
- cfg.rgb_order = false;
- cfg.dlen_16bit = false;
- cfg.bus_shared = false;
- _panel_instance.config(cfg);
- }
- {
- auto cfg = _light_instance.config();
- cfg.pin_bl = 21;
- cfg.invert = false;
- cfg.freq = 44100;
- cfg.pwm_channel = 7;
- _light_instance.config(cfg);
- _panel_instance.setLight(&_light_instance);
- }
- {
- auto cfg = _touch_instance.config();
- cfg.pin_scl = GPIO_NUM_35;
- cfg.pin_sda = GPIO_NUM_36;
- cfg.pin_int = GPIO_NUM_37;
- cfg.i2c_addr = 0x5D;
- cfg.i2c_port = I2C_NUM_0;
- cfg.freq = 400000;
- cfg.x_min = 14;
- cfg.x_max = 310;
- cfg.y_min = 5;
- cfg.y_max = 448;
- cfg.offset_rotation = 0;
- cfg.bus_shared = false;
- _touch_instance.config(cfg);
- _panel_instance.setTouch(&_touch_instance);
- }
- setPanel(&_panel_instance);
- }
- };
- void setup() {
- Serial.begin(115200);
- esp_err_t ret = nvs_flash_init();
- if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
- ESP_ERROR_CHECK(nvs_flash_erase());
- ret = nvs_flash_init();
- }
- ESP_ERROR_CHECK(ret);
- xTaskCreatePinnedToCore(gui_task, "gui", 4091*2, NULL, 1, NULL, 1);
- vTaskDelay(200/ portTICK_PERIOD_MS);
- NFC_Init();
- }
- void loop()
- {
- MFRC522_ReadCardSerialNo(card);
- if (card[0] != 0 || card[1] != 0 || card[2] != 0 || card[3] != 0) {
- Serial.println(card[0]);
- Serial.println(card[1]);
- Serial.println(card[2]);
- Serial.println(card[3]);
- }
- vTaskDelay(1000/ portTICK_PERIOD_MS);
- //lv_timer_handler();
- // vTaskDelay(pdMS_TO_TICKS(TASK_SLEEP_PERIOD_MS));
- //unsigned long currentMillis = millis();
- // unsigned long elapsedMillis = currentMillis - StartOfInterval;
- }
- void NFC_Init(void) {
- NFC_GPIO_Init();
- NFC_SPI_Init();
- MFRC522_Init();
- CreateNfcCooldownTimer();
- }
- void NFC_GPIO_Init(void) {
- gpio_pad_select_gpio(NFC_RST_GPIO_PIN);
- gpio_set_direction(NFC_RST_GPIO_PIN, GPIO_MODE_OUTPUT);
- NFC_GPIO_Write(NFC_RST_HIGH);
- }
- void NFC_SPI_Init(void) {
- esp_err_t ret;
- /*spi_bus_config_t spiBusConfig;
- spiBusConfig.miso_io_num = NFC_SPI_MISO_PIN;
- spiBusConfig.mosi_io_num = NFC_SPI_MOSI_PIN;
- spiBusConfig.sclk_io_num = NFC_SPI_SCLK_PIN;
- spiBusConfig.quadwp_io_num = -1,
- spiBusConfig.quadhd_io_num = -1,
- spiBusConfig.max_transfer_sz = 64*8;*/
- spi_device_interface_config_t spiDeviceConfig;
- spiDeviceConfig.clock_speed_hz = SPI_MASTER_FREQ_10M;
- spiDeviceConfig.mode = 0;
- spiDeviceConfig.spics_io_num = NFC_SPI_CS_PIN;
- spiDeviceConfig.queue_size = 7;
- // ret = spi_bus_initialize(SPI2_HOST, &spiBusConfig, SPI3_HOST);
- // ESP_ERROR_CHECK(ret);
- ret = spi_bus_add_device(SPI3_HOST, &spiDeviceConfig, &s_spiHandle);
- ESP_ERROR_CHECK(ret);
- gpio_pad_select_gpio(NFC_SPI_CS_PIN);
- gpio_set_direction(NFC_SPI_CS_PIN, GPIO_MODE_OUTPUT);
- }