ESP32 SPI garbled

testdog
Posts: 1
Joined: Mon Jun 03, 2019 9:16 pm

ESP32 SPI garbled

Postby testdog » Mon Jul 22, 2019 2:13 pm

Any chance I could get some help with this?

am using a modified version of https://github.com/espressif/esp-idf/tr ... /spi_slave essentially the master just "listens" and the slave just sends data via SPI. I am using two https://learn.adafruit.com/adafruit-huz ... 2-feather Huzzah32 ESP32s

However, on my master side I receive the following data while using "make monitor":

Code: Select all

recvbuf[11269]: ���������������������������������������������������������������������������������������������������������������������������������@H@T@`@t@$@\?@\@h?@t?@p��@p�

recvbuf[11270]: ���������������������������������������������������������������������������������������������������������������������������������@H@T@`@t@$@\?@\@h?@t?@p��@p�
The sender is sending a string:
"This is the receiver, sending data for transmission number %04d"
Here is my two code sets:

https://gist.github.com/DrTester0x42/a0 ... d33c77e66a

Why is my data "garbled" and what can I do to fix this?


See also:
https://github.com/espressif/esp-idf/issues/3801
Last edited by testdog on Tue Jul 23, 2019 1:32 pm, edited 1 time in total.

mikemoy
Posts: 627
Joined: Fri Jan 12, 2018 9:10 pm

Re: ESP32

Postby mikemoy » Tue Jul 23, 2019 12:25 pm

Try something simpler to check if it works.

Slave's end.

Code: Select all

        uint8_t tx_data[5]={0};

	tx_data[0] = 't';
	tx_data[1] = 'e';
	tx_data[2] = 's';
	tx_data[3] = 't';


    while(1) {

        //Set up a transaction of 128 bytes to send/receive
        t.length=4*8;
        t.tx_buffer=tx_data;

        /* This call enables the SPI slave interface to send/receive to the sendbuf and recvbuf. The transaction is
        initialized by the SPI master, however, so it will not actually happen until the master starts a hardware transaction
        by pulling CS low and pulsing the clock etc. In this specific example, we use the handshake line, pulled up by the
        .post_setup_cb callback that is called as soon as a transaction is ready, to let the master know it is free to transfer
        data.
        */
        ret=spi_slave_transmit(HSPI_HOST, &t, portMAX_DELAY);
        printf("msg: %s\n", tx_data);
        n++;

       // lets slow this down a bit. 
       vTaskDelay(200 / portTICK_PERIOD_MS);

    }




Master end...


Code: Select all

    while(1) {
        uint8_t rx_data[128]={0};
        t.length=128*8;
        t.rx_buffer=rx_data;

        ret=spi_device_transmit(handle, &t);
        printf("recvbuf[%d]: %s\n", n ,rx_data);
        n++;
       
       // lets slow this down a bit. 
       vTaskDelay(200 / portTICK_PERIOD_MS);
    }


Who is online

Users browsing this forum: Bhaydar, dzungpv and 97 guests