ESP32-S3 SPI Slave MISO Problem
Posted: Mon Oct 02, 2023 2:58 am
I'm running into a strange issue while trying to set up my ESP32-S3 as an SPI slave. The ESP32 reads data from the master perfectly, but it's having some problems while trying to send out data on MISO. It seems like the ESP32 is having issues getting MISO set up with the right value. Sometimes it briefly goes to high and then immediately goes back low on the falling edge of SCLK. Other times it just doesn't set a high level on MISO when it should be. This is most evident when I hardcode the program to send nothing but repeated 0b01010101 (0x55).
I'm honestly not sure if this is a hardware or software problem at this point, but I was able to bit bang the SPI interface before and it worked 95% well. Applicable code snippets and logic analyzer screenshots are below.
I'm honestly not sure if this is a hardware or software problem at this point, but I was able to bit bang the SPI interface before and it worked 95% well. Applicable code snippets and logic analyzer screenshots are below.
Code: Select all
void spi_task() {
uint8_t send_byte = 0x00;
uint8_t recv_byte = 0x00;
spi_slave_transaction_t t;
memset(&t, 0, sizeof(t));
t.length=8; // 8 Bits of Data
t.tx_buffer=&send_byte;
t.rx_buffer=&recv_byte;
while(1) {
recv_byte = 0x00;
spi_slave_transmit(SPI2_HOST, &t, portMAX_DELAY);
// Code here that picks new send_byte based on recv_byte
// Removed due to hard coding send_byte for testing
send_byte = 0b01010101;
}
}
//Main application
void app_main(void)
{
//Configuration for the SPI bus
spi_bus_config_t buscfg={
.mosi_io_num=GPIO_MOSI,
.miso_io_num=GPIO_MISO,
.sclk_io_num=GPIO_SCLK,
};
//Configuration for the SPI slave interface
spi_slave_interface_config_t slvcfg={
.mode=0,
.spics_io_num=GPIO_CS,
.queue_size=1,
.flags=0,
.post_setup_cb=my_post_setup_cb,
.post_trans_cb=my_post_trans_cb
};
// Set Up GPIO
gpio_setup(); // (Custom Function Removed for Brevity)
//Initialize SPI slave interface
spi_slave_initialize(SPI2_HOST, &buscfg, &slvcfg, SPI_DMA_DISABLED);
// Initialize the SPI Task
xTaskCreate(&spi_task, "SPI_TASK", 4096, NULL, 1, NULL);
}