ESP32-S3 does not save data from ADC

RS2022
Posts: 1
Joined: Thu Dec 08, 2022 6:02 am

ESP32-S3 does not save data from ADC

Postby RS2022 » Thu Dec 08, 2022 6:07 am

How do I save my ADC transmission correctly? We are using the ESP32-S3 to get data from an ADC (Analog AD7134), but the ESP32-S3 does not seem to correctly read the data sent by the ADC. It indicates that data was received (err = ESP_OK), but nothing is written to the buffer. Here is a screenshot of the communication between ESP and ADC including the DLCK (orange), the actual data DATA0 (yellow) and the ODR (the Output Data Rate signals a new transfer from the ADC).

DCLK is connected to ESP IO48 pin.
DATA0 is connected to ESP IO47 pin.
ODR is connected to ESP IO20 pin.

It can be seen that data is actually sent to the ESP but it does not seem to capture/save it correctly:

Image

And here a zoomed version:

Image

The official Espressif IDF is used in the latest version (previous versions such as 4.4.1 were also tested). The important part of the code goes as follows:

Code: Select all

    spi_bus_config_t buscfg_ad4134_data={
        .mosi_io_num=AD4134_DATA0_PIN,
        .miso_io_num=NULL,
        .sclk_io_num=AD4134_DCLK_PIN,
        .quadwp_io_num = -1,
        .quadhd_io_num = -1,
        .flags=SPICOMMON_BUSFLAG_SLAVE
    };
 
 
    spi_slave_interface_config_t slvcfg_ad4134 = {
        .mode=0,                         // see fig. 2
        .spics_io_num=AD4134_ODR_PIN,
        .queue_size=1,
        .flags=SPI_DEVICE_HALFDUPLEX,
        .post_setup_cb=NULL,
        .post_trans_cb=NULL
    };
   
 
    // initialize slave
    ESP_ERROR_CHECK(spi_slave_initialize(AD4134_SPI_CHANNEL, &buscfg_ad4134_data, &slvcfg_ad4134, SPI_DMA_DISABLED));
 
    return ESP_OK;
}
 
 
void ad4134_read() {
    WORD_ALIGNED_ATTR uint8_t sendbuf[16];
    WORD_ALIGNED_ATTR uint8_t recvbuf[16];
    memset(sendbuf, 0, sizeof(sendbuf));
    memset(recvbuf, 0, sizeof(recvbuf));
    spi_slave_transaction_t t;
    memset(&t, 0, sizeof(t));
    esp_err_t err;
 
    while(true) {
        //Clear receive buffer, set send buffer to something sane
        memset(recvbuf, 0, sizeof(recvbuf));
        //Set up a transaction of 128 bytes to send/receive
        t.length = 24;
        t.trans_len = 24;
        // t.length = 32;
        t.rx_buffer = recvbuf;
        t.tx_buffer = NULL;
        /* 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.*/
        err = spi_slave_transmit(AD4134_SPI_CHANNEL, &t, portMAX_DELAY);
 
        //spi_slave_transmit does not return until the master has done a transmission, so by here we have sent our data and
        // received data from the master. Print it.
        printf("Received [%i]: ", err);
        for(int i = 0; i<16; i++){
            printf("%02X", recvbuf[i]);
        }
        printf("\n");
        break;
    }

We suspect that the high state of the CS signal is too short (1,5 us). Is there a way to fix this? Or do you have any other idea on what could be the problem?

Who is online

Users browsing this forum: Bing [Bot] and 94 guests