ESP32-S3 SPI Slave MISO Problem

stepstools
Posts: 5
Joined: Mon Oct 02, 2023 2:42 am

ESP32-S3 SPI Slave MISO Problem

Postby stepstools » 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.

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);
}
Attachments
waves.PNG
waves.PNG (19.15 KiB) Viewed 1664 times

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-S3 SPI Slave MISO Problem

Postby ESP_Sprite » Mon Oct 02, 2023 9:36 am

That looks more like glitches from other signals being capacitively coupled to MISO, to be honest. Not sure why MISO goes high later on.

stepstools
Posts: 5
Joined: Mon Oct 02, 2023 2:42 am

Re: ESP32-S3 SPI Slave MISO Problem

Postby stepstools » Mon Oct 02, 2023 10:19 pm

ESP_Sprite wrote: That looks more like glitches from other signals being capacitively coupled to MISO, to be honest. Not sure why MISO goes high later on.
MISO goes high later on during the time between when the SPI transaction ends and the next one is set up. Not sure why the slave driver does that.

After some more troubleshooting it seems like the ESP32 is double detecting the falling edges. That’s why it briefly sets up the 1 for the second bit before immediately going back to 0 for the third bit. Also why the first four falling edges have MISO activity but the last four don’t.

Your reply reminded me that I completely forgot to put decoupling capacitors in the circuit. That could be causing the glitches. I’ll fix it and then report back.

stepstools
Posts: 5
Joined: Mon Oct 02, 2023 2:42 am

Re: ESP32-S3 SPI Slave MISO Problem

Postby stepstools » Tue Oct 03, 2023 2:50 am

No joy. I have the devboard hooked up to the peripheral on a breadboard, so it is a bit of a rats nest. MISO looks even worse on the oscilloscope...some pretty serious glitching and such. At this point I'm stumped as to why. The SCLK signal looks pretty clean on the scope and the bit banged MISO looks fine too, so I'm stumped as to what's causing the problem.

stepstools
Posts: 5
Joined: Mon Oct 02, 2023 2:42 am

Re: ESP32-S3 SPI Slave MISO Problem

Postby stepstools » Thu Oct 05, 2023 12:35 am

Hooked the circuit up to my scope. It looks like MISO spikes on every falling edge when transmitting 0b01010101. However, for 0b00000000 there is no spiking. There is definitely some capacative coupling on my circuit, but not enough to cause those spikes. Still totally stumped.
Attachments
01010101.png
Sending 0b01010101
01010101.png (27.08 KiB) Viewed 1453 times
00000000.png
Sending 0b00000000
00000000.png (26.49 KiB) Viewed 1453 times

Who is online

Users browsing this forum: MicroController and 81 guests