Need help with SPI full duplex read

mbutura
Posts: 10
Joined: Tue Jan 02, 2018 3:38 pm

Need help with SPI full duplex read

Postby mbutura » Thu Jan 04, 2018 8:02 pm

Hi all,

I am trying to setup tests for ESP32 full duplex, I am reading only a byte. I have the ESP32 connected to a protocol analyser and the MISO line is connected to a signal generator at a tenth of the frequency of the SPI clock to simulate data on the MISO line. Using the analyser I can see the data sent on MISO is fine and I get the the data on MISO line and decode it but am just getting zeroed out data on tx_data array of the SPI transaction on the ESP32.

I am on v3.0-rc1.

Code: Select all

void lgw_spi_r(spi_device_handle_t* concentrator, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data)
{
    ESP_LOGD(TAG, "ENTERED FUNCTION [%s]", __func__);

    uint8_t size=0; 
    
    spi_transaction_ext_t j;

    // check input variables
    assert(concentrator != NULL);
    if ((address & 0x80) != 0)
    {
        ESP_LOGD(TAG,"WARNING: SPI address > 127\n");
    }
    assert(data != NULL);

    // prepare frame to be sent
    //We send a 0x00 as the line is full duplex and handles reads and writes concurrently.
    if (spi_mux_mode == LGW_SPI_MUX_MODE1)
    {
        address = ((uint16_t)spi_mux_target<<8)|((READ_ACCESS | (address & 0x7F))<<0);
        size = 2;
    }
    else
    {
        address = ((READ_ACCESS | (address & 0x7F))<<0);
        size = 1;
    }
    ESP_LOGD(TAG,"SPI address field is 0x%04X in hexadecimal",address);

    // I/O transaction
    // zero out the transaction struct first
    memset(&j, 0, sizeof(j));

    j.address_bits=size*8;
    j.base.flags=SPI_TRANS_VARIABLE_ADDR|SPI_TRANS_USE_TXDATA|SPI_TRANS_USE_RXDATA;
    j.base.addr=address;
    j.base.length=8;
    //tx data is already zeroed out. Saves a line of code.
    //rx length is also zeroed out. rx length is therefore equal to length.
    esp_err_t ret=spi_device_transmit(*concentrator, (spi_transaction_t*)&j); //Perform the transmit transaction!
    assert(ret==ESP_OK);
    
#if CONFIG_LOG_DEFAULT_LEVEL >= 3
    for(int i=0; i<4; i++)
    {
        ESP_LOGI(TAG, "Received data value is [%u], Value: 0x%02X", i, j.base.rx_data[i]);
    }
#endif
    data = (void*)(j.base.rx_data); //Pointer points to transaction rx buffer
}
Result:

Code: Select all

D (65182) loragw_spi: ENTERED FUNCTION [lgw_spi_r]
D (65187) loragw_spi: SPI address field is 0x0055 in hexadecimal
I (65193) loragw_spi: Received data value is [0], Value: 0x00
I (65199) loragw_spi: Received data value is [1], Value: 0x00
I (65206) loragw_spi: Received data value is [2], Value: 0x00
I (65212) loragw_spi: Received data value is [3], Value: 0x00

mbutura
Posts: 10
Joined: Tue Jan 02, 2018 3:38 pm

Re: Need help with SPI full duplex read

Postby mbutura » Sat Jan 06, 2018 10:00 pm

Solved. The code is fine and works with a SPI device connected. Logic analyser decoded MISO data is in agreement with that in tx_data array. Do not simulate data on the miso line with a signal generator!

Who is online

Users browsing this forum: No registered users and 91 guests