Dual SPI Master/Slave on esp32s3

Slinisa
Posts: 26
Joined: Sat Oct 07, 2023 8:21 am

Dual SPI Master/Slave on esp32s3

Postby Slinisa » Wed Mar 20, 2024 9:47 am

Hi,

I'm trying to setup dual SPI master node, but all I get is single node. I've connected oscilloscope to different pins and only SCK and MOSI have outputs. I can't get the second data pin to work whatever I try. Tried different pins, still nothing. By measuring the SCK length I found that it's transmitting it as single SPI, double time, so it is defined as single SPI, not dual. Need some help!

-------------------- defs -----------------------------
typedef struct SPI_settings_s{
spi_host_device_t host;
spi_device_handle_t spi;
int dma_chan;
spi_device_interface_config_t devcfg;
spi_bus_config_t buscfg;
}SPI_settings_t;

static SPI_settings_t SPI_settings = {
.host = SPI2_HOST,
.dma_chan = SPI_DMA_CH_AUTO,
.devcfg = {
.command_bits = 0,
.address_bits = 0,
.mode = 0, //SPI mode 0
.clock_speed_hz = APB_CLK_FREQ /800, //SPI_MASTER_FREQ_40M
.spics_io_num = 10, //CS pin
.queue_size = 1 //Not sure if needed
},
.buscfg = {
.mosi_io_num = GPIO_NUM_11,
.data1_io_num = GPIO_NUM_9,
.sclk_io_num = GPIO_NUM_12,
.max_transfer_sz = 131072,
.flags = SPICOMMON_BUSFLAG_MASTER | SPICOMMON_BUSFLAG_GPIO_PINS | SPICOMMON_BUSFLAG_SCLK | SPICOMMON_BUSFLAG_DUAL
}
};
--------------- initializing and sending ---------------------------

if(!spi_bus_initialize(SPI_settings.host, &SPI_settings.buscfg, SPI_settings.dma_chan))
if(!spi_bus_add_device(SPI_settings.host, &SPI_settings.devcfg, &SPI_settings.spi)) {
ledDMAbuffer=&ram[0xA000];
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length = 8*0x6000; //length is in bits
t.tx_buffer = ledDMAbuffer;
// t.flags = SPI_TRANS_MODE_DIO; -- causes panic
spi_device_queue_trans(SPI_settings.spi, &t,0);// spi_bus_initialize();
}

liaifat85
Posts: 137
Joined: Wed Dec 06, 2023 2:46 pm

Re: Dual SPI Master/Slave on esp32s3

Postby liaifat85 » Wed Mar 20, 2024 4:11 pm

Uncomment the line t.flags = SPI_TRANS_MODE_DIO; to set the transaction mode appropriately. That may help you to figure out the problem.

Slinisa
Posts: 26
Joined: Sat Oct 07, 2023 8:21 am

Re: Dual SPI Master/Slave on esp32s3

Postby Slinisa » Wed Mar 20, 2024 5:36 pm

The reason it's commented out is it causes panic. Not inside my code but inside function

xPortEnterCriticalTimeout

Slinisa
Posts: 26
Joined: Sat Oct 07, 2023 8:21 am

Re: Dual SPI Master/Slave on esp32s3

Postby Slinisa » Wed Mar 20, 2024 5:53 pm

OK, I've increased task cache (I got stack cannary watchpoint triggered) and no more error, but ... nothing is being transfered. No oscilloscope signal, even on SCK. I'll check if there is an error code when starting SPI transfer.

Slinisa
Posts: 26
Joined: Sat Oct 07, 2023 8:21 am

Re: Dual SPI Master/Slave on esp32s3

Postby Slinisa » Wed Mar 20, 2024 6:00 pm

I get error 258, which is invalid argument. Tried SPI_TRANS_MODE_QIO as well, the same error. When it's commented out, no error and output is present. I have two different ESP32S3 boards, the same problem on both.
Any suggestion?

Slinisa
Posts: 26
Joined: Sat Oct 07, 2023 8:21 am

Re: Dual SPI Master/Slave on esp32s3

Postby Slinisa » Wed Mar 20, 2024 6:25 pm

It seems dual is not working at all? I tried different flags, like

.flags = SPICOMMON_BUSFLAG_MASTER | SPICOMMON_BUSFLAG_GPIO_PINS | SPICOMMON_BUSFLAG_SCLK | SPICOMMON_BUSFLAG_DUAL | SPI_DEVICE_HALFDUPLEX

Ever time the error is the same:
E (183) spi_master: check_trans_valid(704): Incompatible when setting to both multi-line mode and half duplex mode

With rror is 258. I even tried ORing a NOT-ed multiline flats ( !SPI_TRANS_MULTILINE_CMD | !SPI_TRANS_MULTILINE_ADDR), still complaining about multiline mode.

I also tried setting data0_io_num = GPIO_NUM_11 instead of mosi_io_num = GPIO_NUM_11

.data0_io_num = GPIO_NUM_11,
.data1_io_num = GPIO_NUM_13,
.sclk_io_num = GPIO_NUM_12,

and no difference. I googled the flags, only found some Chinese pages. Did anyone try DMA with Dual SPI with success?

Slinisa
Posts: 26
Joined: Sat Oct 07, 2023 8:21 am

Re: Dual SPI Master/Slave on esp32s3

Postby Slinisa » Wed Mar 20, 2024 8:29 pm

Finally got it. What I needed to define was flags in spi_device_interface_config_t used in spi_bus_add_device(SPI_settings.host, &SPI_settings.devcfg, &SPI_settings.spi)

.devcfg = {
.command_bits = 0,
.address_bits = 0,
.mode = 0, //SPI mode 0
.clock_speed_hz = SPI_MASTER_FREQ_40M
.spics_io_num = 10, //CS pin
.flags = SPI_DEVICE_HALFDUPLEX, // <--- THIS!!
.queue_size = 1 //Not sure if needed
},

Who is online

Users browsing this forum: Bing [Bot] and 224 guests