ESP32-PICO-D4 Trouble with SPI

jgauthier
Posts: 2
Joined: Thu May 26, 2022 1:45 pm

ESP32-PICO-D4 Trouble with SPI

Postby jgauthier » Thu Oct 20, 2022 11:53 pm

Hello,

I'm trying to get SPI working between two microprocessors. One is the ESP32, acting as the main and the other is an STM32 acting as a sub node.

One the ESP32 I am using HSPI (There are 3 available).

The issue is that as the Main device I am using spi_device_transmit() to send and receive data.
The data I am receiving is correct. The data I am sending is not correct, with respect to the code.

On the ESP32 I have this loop:

Code: Select all

    
    uint8_t tx_buffer[3] = { 0x00, 0x00, 0x00 };
    while(1) {
        t.length=3*8;
        t.tx_buffer=tx_buffer;
        t.rx_buffer=recvbuf;
        spi_device_transmit(handle, &t);

        printf("%#x %#x %#x\n", recvbuf[0], recvbuf[1], recvbuf[2]);
        sleep(1);
    }
One the STM32 I have this code (currently activated by the CS going low interrupt)

Code: Select all

	
    uint8_t data[3];
    uint8_t send[3] = {0x01,0x02, 0x03};
    if(GPIO_Pin == SPI1_CS_Pin) // If The INT Source Is EXTI Line9 (A9 Pin)
    {
        serprintf("Received CS.\n\r");
        spi_tx_rx(send, data, 3);
        for (uint8_t i=0; i<3; i++) {
            serprintf("%#x ", data[i]);
        }
	serprintf("\n\r");
   }
The ESP32 is showing
"0x1 0x2 0x3" once per second.
The scope analysis is correct as well:

https://www.flickr.com/photos/196758970 ... cx2en8816x
However, you can see that I am sending all 3 bytes of 0s, but that is not what I am showing on the scope, nor is it what the STM32 is receiving:

https://www.flickr.com/photos/196758970 ... 7vGnPB47aL

It is very consistently a 0x3.

I can change the 3rd byte to something like this:
uint8_t tx_buffer[3] = { 0x00, 0x00, 0xF1 };

and the data I receive is:
0x3 0 0xf1

It does not matter what I do with the first byte. It's always 0x3, and the second byte is always 0.

Who is online

Users browsing this forum: Google [Bot] and 46 guests