- I (364) Setup: Initializing SPI Busses
- I (364) Setup: Initialized SPI Busses
- I (394) Setup: Testing ESP to PWR Communication
- I (414) SPI_PWR_TEST: Start Test, sending 3 packets for testing
- I (484) SPI_PWR_TEST: Test Finished with 0 Errors
- I (484) Setup: Test succesfull
- I (484) Setup: Testing ESP to CTRL Communication
- ESP_ERROR_CHECK_WITHOUT_ABORT failed: esp_err_t 0x105 (ESP_ERR_NOT_FOUND) at 0x4037abdb
- 0x4037abdb: _esp_error_check_failed_without_abort at C:/Users/UserA/esp/esp-idf/components/esp_system/esp_err.c:37
- file: "../components/SPI/spi_deviceA_driver.c" line 136
- func: deviceA_initialize
- expression: spi_error
For that we intend to use the SPI2_HOST and SPI3_HOST. SPI2 will have 2 slave devices connected and SPI3 3 slave devices.
For this test only one slave is connected to each bus.
Initializing the busses independently, the communication tests works flawlessly. The Problem only occurs if I try to initialize and use both busses at the same time. I initialize the busses in a seperate c file. I try to add the devices in a .c file specific to that device.
The file structure is as followed
components
>SPI
>>include
>>>spi_bus.h
>>>spi_deviceA_driver.h
>>>spi_deviceB_driver.h
>>spi_bus.c
>>spi_deviceA_driver.c
>>spi_deviceB_driver.c
main
>main.c
in main.c the function spi_initialize_busses is called and throws no error
- esp_err_t spi_initialize_busses(){
- esp_err_t err = ESP_OK;
- spi_bus_config_t bus_config_ctrl = {
- .mosi_io_num = CTRL_SPI_MOSI_PIN, //PIN 9
- .miso_io_num = CTRL_SPI_MISO_PIN, //PIN 10
- .sclk_io_num = CTRL_SPI_SCLK_PIN, //PIN 46
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .data4_io_num = -1,
- .data5_io_num = -1,
- .data6_io_num = -1,
- .data7_io_num = -1,
- .max_transfer_sz = 0,
- .flags = 0U,
- .intr_flags = ESP_INTR_FLAG_LEVEL1};
- spi_bus_config_t bus_config_pwr = {
- .mosi_io_num = PWR_SPI_MOSI_PIN, //47
- .miso_io_num = PWR_SPI_MISO_PIN, // 45
- .sclk_io_num = PWR_SPI_SCLK_PIN, // 48
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .data4_io_num = -1,
- .data5_io_num = -1,
- .data6_io_num = -1,
- .data7_io_num = -1,
- .max_transfer_sz = 0,
- .flags = 0U,
- .intr_flags = ESP_INTR_FLAG_LEVEL1};
- err = spi_bus_initialize(PWR_SPI_PERIPHERAL_HOST, &bus_config_pwr, SPI_DMA_DISABLED); //SPI2_HOST
- ESP_ERROR_CHECK(err);
- err = spi_bus_initialize(CTRL_SPI_PERIPHERAL_HOST, &bus_config_ctrl, SPI_DMA_DISABLED); //SPI3_HOST
- ESP_ERROR_CHECK(err);
- return err;
- }
- spi_device_handle_t spi_handle;
- esp_err_t deviceA_initialize(void)
- {
- esp_err_t spi_error = 0;
- spi_device_interface_config_t slave_device_config = {
- .command_bits = 0,
- .address_bits = 0,
- .dummy_bits = 0,
- .mode = 1,
- .duty_cycle_pos = 0,
- .cs_ena_pretrans = 0,
- .cs_ena_posttrans = 0,
- .clock_speed_hz = 1 * 1000 * 1000,
- .input_delay_ns = 0,
- .queue_size = 1,
- .spics_io_num = -1; //multiplexer is used
- .flags = 0U,
- .pre_cb = NULL,
- .post_cb = NULL};
- spi_error = spi_bus_add_device(CTRL_SPI_PERIPHERAL_HOST, &slave_device_config, &spi_handle);
- ESP_ERROR_CHECK_WITHOUT_ABORT(spi_error);
- return spi_error;
- }
- spi_device_handle_t spi_handle;
- esp_err_t deviceB_initialize(void)
- {
- esp_err_t spi_error;
- spi_device_interface_config_t slave_device_config = {
- .command_bits = 0,
- .address_bits = 0,
- .dummy_bits = 0,
- .mode = 1,
- .duty_cycle_pos = 0, // 0 equals 50% duty cycle
- .cs_ena_pretrans = 0,
- .cs_ena_posttrans = 0,
- .clock_speed_hz = 1 * 1000 * 1000,
- .input_delay_ns = 0, // may be further adjusted. taken from ESP32 to ESP32 values
- .queue_size = 1,
- .spics_io_num = deviceB_SPI_CS_1, //14
- .flags = 0U,
- .pre_cb = NULL,
- .post_cb = NULL};
- spi_error = spi_bus_add_device(PWR_SPI_PERIPHERAL_HOST, &slave_device_config, &spi_handle);
- ESP_ERROR_CHECK_WITHOUT_ABORT(spi_error);
- return spi_error;
- }
If i misread the datasheets and User Guide and commited an stupid error i apologize, but if i am correct, the busses should be able to be initialized independently and work.
The Error ONLY occurs if i try to have both busses initialized at the same time. Initializing and Testing the busses individually generates no errors. The workaround right now is to deinit and reinit the busses every communication, however this is not a solution i would deem fit for production. So help to identify the error would be appreciated.
Best Regards