SPI SLAVE bad assertion

chuledeco
Posts: 7
Joined: Thu Feb 13, 2020 3:22 pm

SPI SLAVE bad assertion

Postby chuledeco » Thu Apr 02, 2020 8:48 pm

Hello to all,

I'm having a problem that appears when trying to get data from an AD7768 ADC. I need to read data using the ESP32 as a slave on the VSPI bus.

I'm configuring the SPI bus and the transaction as in the example, deleting all that I do not need. Also, I only have a MISO pin because ESP32 does not send anything.

My problem is data is very erratic, it seems like the SPI driver does not wait that the CS pin goes high and lather low. Could it be that if CS pin is low when calling "spi_slave_transmit()" assume it is asserted and start loading recvbuf in the middle of the previous transaction?

Can you help me to fix it?

I attach the relevant part of the code bellow:

[Codebox]

#define ADC_DCLK 36
#define ADC_DRDY 39
#define ADC_DOUT 19

#define DATA_MOSI ADC_DOUT
#define DATA_MISO -1
#define DATA_SCLK ADC_DCLK
#define DATA_CS ADC_DRDY

#define SPI_MODE 0
#define RCV_HOST VSPI_HOST
#define DMA_CHAN 2


void app_main(void)
{
/*Configure VSPI bus for data input
*
*/
//Configuration for the VSPI bus
spi_bus_config_t buscfg2={
.mosi_io_num=DATA_MOSI,
.miso_io_num=DATA_MISO,
.sclk_io_num=DATA_SCLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz=128
};
//Configuration for the SPI slave interface
spi_slave_interface_config_t slvcfg={
.mode=SPI_MODE,
.spics_io_num=DATA_CS,
.queue_size=3,
.flags=0,
};
// Set apropiated pull-ups
gpio_set_pull_mode(DATA_MOSI, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(DATA_SCLK, GPIO_PULLUP_ONLY);
gpio_set_pull_mode(DATA_CS, GPIO_PULLUP_ONLY);
//Initialize SPI slave interface
ret=spi_slave_initialize(RCV_HOST, &buscfg2, &slvcfg, DMA_CHAN);
assert(ret==ESP_OK);

WORD_ALIGNED_ATTR char recvbuf[20]="";
memset(recvbuf, 0, 20);
spi_slave_transaction_t t_slave;
memset(&t_slave, 0, sizeof(t_slave));

while (true) {


t_slave.length=128; // 4 channels at 32bits (8 bits header and 24 bits data)
t_slave.tx_buffer=NULL;
t_slave.rx_buffer=recvbuf;
memset(recvbuf, 0xA5, 20);

ret=spi_slave_transmit(RCV_HOST, &t_slave, portMAX_DELAY);

ret=spi_slave_transmit(RCV_HOST, &t_slave, portMAX_DELAY);

printf("Rec.length: %d, message: %s\n", t_slave.length, recvbuf);
for (i=0; i< 4; i++)
{
for (j=0; j<4 ; j++)
{
print_byte(recvbuf[4*i+j]);
printf("-");
}
printf("\n");
}
printf("\n");

vTaskDelay(1000 / portTICK_PERIOD_MS);

}
}

[/Codebox]

Who is online

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