How to use the DIO SPI on ESP32 with espidf?

Viewed 10

I'm trying to use the DIO SPI mode on the ESP32 with the espidf (version 4.4). But I encountered problems.

I have a ram device (ref 23LC1024) than can be accessed with several modes (single, dual, quad).

The single mode works perfectly (can write and read back)

The dual mode creates problems.

Here is how I configure the SPI bus (same setup for single or dual mode)

    memset(&config, 0, sizeof(spi_bus_config_t));
    config.mosi_io_num = MOSI_PIN;
    config.miso_io_num = MISO_PIN;
    config.sclk_io_num = SCLK_PIN;
    config.quadwp_io_num = -1; // -1 not used
    config.quadhd_io_num = -1; // -1 not used
    config.flags = SPICOMMON_BUSFLAG_DUAL | SPICOMMON_BUSFLAG_MASTER;
    spi_bus_initialize(VSPI_HOST, &config, SPI_DMA_DISABLED); // 0 DMA not used

Now the setup for the device (same setup for single mode or dual):

spi_device_interface_config_t devcfg = {
            .clock_speed_hz = freq,
            .command_bits = 8,  
            .address_bits = 24, 
            .dummy_bits = 8,    
            .mode = 0,          // SPI MODE 0
            .flags = 0,         
            .spics_io_num = _cs,
            .queue_size = 1, 
            .pre_cb = NULL,  
            .post_cb = NULL};
        ESP_ERROR_CHECK(spi_bus_add_device(VSPI_HOST, &devcfg, &data_Ram));

Now the setup for the transaction:

spi_transaction_t t;
    memset(&t, 0, sizeof(t)); // Zero out the transaction
    t.cmd = WRITE;
    t.tx_buffer = data;
    t.rx_buffer = NULL;
    t.addr = address;
    t.length = size * 8;
    if (USE_DIO)     // configure these flags in case of DIO
        t.flags = SPI_TRANS_MODE_DIO | SPI_TRANS_MULTILINE_ADDR | SPI_TRANS_MULTILINE_CMD;

    ESP_ERROR_CHECK(spi_device_transmit(data_Ram, &t)); // Transmit!

It works nicely in the single mode but with the dual mode I got the error:

E (1618) spi_master: check_trans_valid(699): Incompatible when setting to both multi-line mode and half duplex mode

Does it mean I cannot use DIO in half duplex mode with the SPI master library?

Is there something I should change in my setup ? I tried to specify the SPI_DEVICE_HALFDUPLEX flag in the spi_device_interface_config_t. Does not help.

Unfortunately I did not find any example on internet.

Thanks for your heads up!

0 Answers
Related