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:
And here a zoomed version:
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?