spi_device_polling_transmit(spi, &t) return error and assert reboot in SPI Master example code .c
Posted: 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
}
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
}