I initialize the spi as follows
- static esp_err_t spi_master_init(void)
- {
- esp_err_t ret;
- spi_bus_config_t buscfg = {
- .miso_io_num = PIN_NUM_MISO,
- .mosi_io_num = PIN_NUM_MOSI,
- .sclk_io_num = PIN_NUM_CLK,
- .quadwp_io_num = -1,
- .quadhd_io_num = -1,
- .max_transfer_sz = SPI_DEFAULT_BUFFER_LENGTH * 8,
- };
- // SPI mode, representing a pair of (CPOL, CPHA) configuration:
- // 0: (0, 0) 1: (0, 1) 2: (1, 0) 3: (1, 1)
- spi_device_interface_config_t devcfg = {
- .clock_speed_hz = SERIAL_CLOCK_SPEED, // for mcp2517 serial clock speed must be less or equal half of sys clock of mcp2517.
- .mode = 0, // SPI mode 0
- .spics_io_num = PIN_NUM_CS, // CS pin
- .queue_size = 1,
- .input_delay_ns = 20,
- .cs_ena_posttrans = 3,
- //.flags= SPI_DEVICE_HALFDUPLEX,
- // We want to be able to queue 7 transactions at a time
- //.pre_cb=can_spi_pre_transfer_callback, //Specify pre-transfer callback to handle D/C line
- };
- // Initialize the SPI bus
- #if (defined DMA_ENABLED && DMA_ENABLED)
- ret = spi_bus_initialize(CAN_SPI_HOST, &buscfg, DMA_CHAN);
- #else
- ret = spi_bus_initialize(CAN_SPI_HOST, &buscfg, 0);
- #endif
- ESP_ERROR_CHECK(ret);
- // Attach the device to the SPI bus
- ret = spi_bus_add_device(CAN_SPI_HOST, &devcfg, &spi_device);
- ESP_ERROR_CHECK(ret);
- return ret;
- }
- spi_transaction_t t;
- if (len == 0)
- return ESP_FAIL; // no need to send anything
- // Zero out the transaction
- memset(&t, 0, sizeof(t));
- t.length = len * 8; // Len is in bytes, transaction length is in bits.
- t.tx_buffer = SpiTxData;
- esp_err_t ret = spi_device_transmit(spi_device, &t);
Core 0 register dump:
PC : 0x4008b55b PS : 0x00060530 A0 : 0x8008bb41 A1 : 0x3ffbb9c0
0x4008b55b: check_trans_valid at C:/Users/tufan/esp/esp-idf/components/driver/spi_master.c:735 (discriminator 2)
A2 : 0x3ffdffff A3 : 0x3ffbba70 A4 : 0x00000000 A5 : 0x00000080
A6 : 0x00000000 A7 : 0x00000005 A8 : 0x3ffbbbc0 A9 : 0x3ffbbb80
A10 : 0x000004ac A11 : 0x3f404528 A12 : 0x3f40498c A13 : 0x0000048e
A14 : 0x3f404528 A15 : 0x3f404f0c SAR : 0x00000004 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000088 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xfffffffe
Backtrace: 0x4008b558:0x3ffbb9c0 0x4008bb3e:0x3ffbb9f0 0x4008bc2a:0x3ffbba30 0x400dba7a:0x3ffbba60 0x400dbb3c:0x3ffbbac0 0x400da99d:0x3ffbbae0 0x400dae91:0x3ffbbb00 0x400d8e00:0x3ffbbb80 0x400d8e98:0x3ffbbbc0 0x400d89f3:0x3ffbbbf0 0x400d8a50:0x3ffbbc20 0x401ae786:0x3ffbbc50 0x40092a6d:0x3ffbbc80
0x4008b558: check_trans_valid at C:/Users/tufan/esp/esp-idf/components/driver/spi_master.c:733 (discriminator 2)
0x4008bb3e: spi_device_queue_trans at C:/Users/tufan/esp/esp-idf/components/driver/spi_master.c:866
0x4008bc2a: spi_device_transmit at C:/Users/tufan/esp/esp-idf/components/driver/spi_master.c:944
0x400dba7a: spi_master_transfer at C:/Users/tufan/esp/ble_spp_server/components/mcp2517/spi.c:130
0x400dbb3c: SPI_TransferData at C:/Users/tufan/esp/ble_spp_server/components/mcp2517/spi.c:57
0x400da99d: DRV_CANFDSPI_WriteByteArray at C:/Users/tufan/esp/ble_spp_server/components/mcp2517/mcp2517.c:441
0x400dae91: DRV_CANFDSPI_RamInit at C:/Users/tufan/esp/ble_spp_server/components/mcp2517/mcp2517.c:2779
0x400d8e00: mcp2517_reset at C:/Users/tufan/esp/ble_spp_server/main/spi_controller.c:190 (discriminator 13)
0x400d8e98: spi_controller_init at C:/Users/tufan/esp/ble_spp_server/main/spi_controller.c:92 (discriminator 13)
0x400d89f3: tasks_init at C:/Users/tufan/esp/ble_spp_server/main/main.c:50
0x400d8a50: app_main at C:/Users/tufan/esp/ble_spp_server/main/main.c:29
0x401ae786: main_task at C:/Users/tufan/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/port_common.c:131 (discriminator 2)
0x40092a6d: vPortTaskWrapper at C:/Users/tufan/esp/esp-idf/components/freertos/FreeRTOS-Kernel/portable/xtensa/port.c:154
at
static SPI_MASTER_ISR_ATTR esp_err_t check_trans_valid(spi_device_handle_t handle, spi_transaction_t *trans_desc)
{
SPI_CHECK(handle != NULL, "invalid dev handle", ESP_ERR_INVALID_ARG);
spi_host_t *host = handle->host;
handle->host becomes 0.
Any help will be highly appreciated.