Set and init for VSPI ok, then considering the code below:
(Ignoring that it will trigger watchdog in some seconds and etc.)
-Or working dedicated without interrupts enabled.
- // SPI configuration
- #define PIN_NUM_MISO GPIO_NUM_19
- #define PIN_NUM_MOSI GPIO_NUM_23
- #define PIN_NUM_CLK GPIO_NUM_18
- #define PIN_NUM_CS GPIO_NUM_5
- spi_bus_config_t bus_config;
- bus_config.miso_io_num = PIN_NUM_MISO;
- bus_config.mosi_io_num = PIN_NUM_MOSI;
- bus_config.sclk_io_num = PIN_NUM_CLK;
- bus_config.quadwp_io_num = -1;
- bus_config.quadhd_io_num = -1;
- bus_config.max_transfer_sz = 0;
- spi_device_interface_config_t dev_config;
- dev_config.clock_speed_hz = 1000000; // Clock speed (1 MHz)
- dev_config.spics_io_num = PIN_NUM_CS;
- dev_config.queue_size = 1;
- dev_config.mode = 0; // SPI mode 0
- spi_device_handle_t spi_handle;
- // Initialize the SPI bus
- esp_err_t ret;
- ret = spi_bus_initialize(VSPI_HOST, &bus_config, SPI_DMA_DISABLED);
- assert(ret == ESP_OK);
- // Attach the device to the SPI bus
- ret = spi_bus_add_device(VSPI_HOST, &dev_config, &spi_handle);
- assert(ret == ESP_OK);
- // Data to send
- spi_transaction_t trans;
- trans.flags = 0;
- trans.length = 64; // Data length in bits
- trans.tx_buffer = data_to_send0;
- uint8_t data_to_send0[8] = { 0xFA, 0x5E, 0x01, 0xD0, 0xDA, 0xD0, 0xCA, 0xB0 };
- uint8_t data_to_send1[8] = { 0xFA, 0x5E, 0x02, 0xD0, 0xDA, 0xD0, 0xCA, 0xB1 };
- while (1)
- {
- trans.tx_buffer = data_to_send0;
- ret = spi_device_polling_transmit(spi_handle, &trans);
- //trans.tx_buffer = data_to_send1;
- //ret = spi_device_polling_transmit(spi_handle, &trans);
- }
(This is not checking status of return, it previously was and it calls and works ok)
1-Even as it is above, with no scheduler interrupts, I checked in the logic analyzer to have a ~14 us delay between the data_to_send0 frames of data. I expect/need no delay in between calls, is something behind scenes that consumes the time after a transmit ends?
2-If I uncomment the second transmit, code breaks. Always. Immediately. So I cannot have double buffering for this? I tried also to let same references and refil a single data_to_send buffer, or have it source of data updated; is there some data lock or similar behind this, causing an access violation or whatever?
I do not want to reinvent the SPI and make a bit banging procedure for it to attend my need, what else could I do, in case someone have seen similar issues?
I need to feed a device near 1MHz limit of SPI functioning, few KB of data for a couple of seconds each time or so.
Thanks
PS. This runs in the second core, a single task, no interrupts. Disabled task watchdog.
PS2. Tried both using
trans.tx_buffer = data_to_send0;
and
trans.tx_buffer = &data_to_send0;
No change in results fir both working and not working cases.