Unhandled exception in spi_device_polling_start()
Posted: Wed May 29, 2024 2:48 am
I'm trying to interface with an ADX345 (https://www.analog.com/media/en/technic ... dxl345.pdf) using 5MHz 4-wire SPI on HSPI_HOST controller. I worked through the various error messages but now I hit an unhandled exception error in the esp_spi_driver component.
Error message exerpt:
My code:
Error message exerpt:
- I (31) boot: ESP-IDF v5.3-dev-3593-g64a1ed07d9-dirty 2nd stage bootloader
- I (37) boot: chip revision: v3.0
- I (41) boot.esp32: SPI Speed : 40MHz
- I (46) boot.esp32: SPI Mode : DIO
- I (50) boot.esp32: SPI Flash Size : 2MB
- I (224) cpu_start: Pro cpu start user code
- I (224) cpu_start: cpu freq: 160000000 Hz
- I (249) app_init: ESP-IDF: v5.3-dev-3593-g64a1ed07d9-dirty
- I (256) efuse_init: Min chip rev: v0.0
- I (261) efuse_init: Max chip rev: v3.99
- I (266) efuse_init: Chip rev: v3.0
- I (311) spi_flash: detected chip: generic
- I (347) Main: Initializing SPI bus... on core 0
- I (347) Main: Adding device to SPI bus...
- I (357) Main: Probing accelerator...
- Guru Meditation Error: Core 0 panic'ed (InstrFetchProhibited). Exception was unhandled.
- Core 0 register dump:
- PC : 0x00000003 PS : 0x00060e30 A0 : 0x800858f8 A1 : 0x3ffb1c00
- A2 : 0x3ffb3120 A3 : 0x3ffb3064 A4 : 0x3ffb2f7c A5 : 0x3ffb3158
- A6 : 0x3ffb1cb0 A7 : 0x3ffb302c A8 : 0x800855c4 A9 : 0x3ffb1be0
- A10 : 0x3ffb1cb0 A11 : 0x3ffb1c00 A12 : 0x3ffb1c00 A13 : 0x00000008
- A14 : 0x00000000 A15 : 0x3ffb300c SAR : 0x00000008 EXCCAUSE: 0x00000014
- EXCVADDR: 0x00000000 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0x00000000
- 0x4000c2e0: memcpy in ROM
- 0x4000c2f6: memcpy in ROM
- Backtrace: 0x00000000:0x3ffb1c00 0x400858f5:0x3ffb1c50 0x400859c2:0x3ffb1c80 0x400d6446:0x3ffb1ca0 0x400d65e5:0x3ffb1d00 0x400d6939:0x3ffb1da0 0x400d6971:0x3ffb1dd0 0x400e9518:0x3ffb1df0 0x40087a65:0x3ffb1e20
- 0x400858f5: spi_device_polling_start at /Users/janick/Documents/IDF/esp-idf/components/esp_driver_spi/src/gpspi/spi_master.c:1376
- 0x400859c2: spi_device_polling_transmit at /Users/janick/Documents/IDF/esp-idf/components/esp_driver_spi/src/gpspi/spi_master.c:1431
- spi_bus_config_t busConfig;
- busConfig.mosi_io_num = 23;
- busConfig.miso_io_num = 19;
- busConfig.sclk_io_num = 18;
- busConfig.quadwp_io_num = -1;
- busConfig.quadhd_io_num = -1;
- busConfig.max_transfer_sz = 4; // bytes
- busConfig.flags = SPICOMMON_BUSFLAG_MASTER | SPICOMMON_BUSFLAG_SCLK | SPICOMMON_BUSFLAG_MISO | SPICOMMON_BUSFLAG_MOSI;
- busConfig.intr_flags = 0;
- busConfig.isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO;
- ESP_LOGI(TAG, "Initializing SPI bus... on core %d", xTaskGetCoreID(xTaskGetCurrentTaskHandle()));
- ESP_ERROR_CHECK(spi_bus_initialize(HSPI_HOST, &busConfig, SPI_DMA_DISABLED));
- spi_device_interface_config_t devConfig;
- devConfig.command_bits = 0;
- devConfig.address_bits = 8;
- devConfig.dummy_bits = 0;
- devConfig.mode = 0;
- devConfig.clock_speed_hz = 5000000;
- devConfig.spics_io_num = 5;
- devConfig.queue_size = 32;
- devConfig.flags = SPI_DEVICE_HALFDUPLEX;
- ESP_LOGI(TAG, "Adding device to SPI bus...");
- ESP_ERROR_CHECK(spi_bus_add_device(HSPI_HOST, &devConfig, &mSPIDev));
- ESP_LOGI(TAG, "Probing accelerator...");
- uint8_t devId = accRead(0x00);
- uint32_t accRead(uint8_t addr, uint8_t bytes = 1)
- {
- if (bytes == 0) return 0;
- if (bytes > 4) bytes = 4;
- addr &= 0x3F;
- spi_transaction_t trans;
- trans.flags = SPI_TRANS_USE_RXDATA;
- trans.tx_buffer = nullptr;
- trans.addr = 0x80 | addr;
- if (bytes > 1) trans.addr |= 0x40;
- trans.length = 0;
- trans.rxlength = bytes * 8U;
- ESP_ERROR_CHECK(spi_device_polling_transmit(mSPIDev, &trans));
- auto rdat = *((uint32_t*)trans.rx_data);
- if (bytes < 4) rdat &= (1U << (bytes * 8)) - 1;
- ESP_LOGI(TAG, "accRead 0x%02x = 0x%08lx", addr, rdat);
- return rdat;
- }