spi_device_polling_transmit(spi, &t) return error and assert reboot in SPI Master example code .c

chriscckan
Posts: 6
Joined: Tue Sep 05, 2023 8:51 am

spi_device_polling_transmit(spi, &t) return error and assert reboot in SPI Master example code .c

Postby chriscckan » Mon Sep 11, 2023 12:49 pm

I am using ESP32-S3 dev board with ESP_IDF v5.1, when running the example code of SPI master with minimum changes (only LCD command set), the program will cause assert failed and then reboot, 100% happen, this is due to ret value is not ESP OK, it said argument problem. But actual code is exactly the example code, not modified. Pls help clarify any bug in the example code or in the v5.1 SPI API library?

this problem happened in non ESP OK return value from the polling_transmitt call and then assert failed then reboot.
example code from spi_master_example_main.c
void lcd_cmd(spi_device_handle_t spi, const uint8_t cmd, bool keep_cs_active)
{
esp_err_t ret;
spi_transaction_t t;
memset(&t, 0, sizeof(t)); //Zero out the transaction
t.length=8; //Command is 8 bits
t.tx_buffer=&cmd; //The data is the cmd itself
t.user=(void*)0; //D/C needs to be set to 0
if (keep_cs_active) {
t.flags = SPI_TRANS_CS_KEEP_ACTIVE; //Keep CS active after data transfer
}
ret=spi_device_polling_transmit(spi, &t); //Transmit!
assert(ret==ESP_OK); //Should have had no issues. ,<<-- reset happen here
}

chriscckan
Posts: 6
Joined: Tue Sep 05, 2023 8:51 am

SPI master example code, if set keep_cs_active will cause reset problem

Postby chriscckan » Mon Sep 11, 2023 1:18 pm

I am using ESP-IDF v5.1 on ESP32-S3 board, I trace the SPI master example code and finally I found this flag cause the argument problem so ret will not be ESP OK so assert will cause reboot of the system. But how come people can only set false for this cs keep active, and cannot set true for it in the calling to spi_device_polling_transmit()?


if (keep_cs_active) {
t.flags = SPI_TRANS_CS_KEEP_ACTIVE; //Keep CS active after data transfer
}
ret=spi_device_polling_transmit(spi, &t); //Transmit!
assert(ret==ESP_OK); //Should have had no issues.

MicroController
Posts: 1725
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: spi_device_polling_transmit(spi, &t) return error and assert reboot in SPI Master example code .c

Postby MicroController » Tue Sep 12, 2023 12:19 pm

https://docs.espressif.com/projects/esp ... TickType_t
ESP_ERR_INVALID_ARG if parameter is invalid. This can happen if SPI_TRANS_CS_KEEP_ACTIVE flag is specified while the bus was not acquired (spi_device_acquire_bus() should be called first)

Who is online

Users browsing this forum: No registered users and 225 guests