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]
SPI SLAVE bad assertion
Jump to
- English Forum
- Explore
- News
- General Discussion
- FAQ
- Documentation
- Documentation
- Sample Code
- Discussion Forum
- Hardware
- ESP-IDF
- ESP-BOX
- ESP-ADF
- ESP-MDF
- ESP-WHO
- ESP-SkaiNet
- ESP32 Arduino
- IDEs for ESP-IDF
- ESP-AT
- ESP IoT Solution
- ESP RainMaker
- Rust
- ESP8266
- Report Bugs
- Showcase
- Chinese Forum 中文社区
- 活动区
- 乐鑫活动专区
- 讨论区
- 全国大学生物联网设计竞赛乐鑫答疑专区
- ESP-IDF 中文讨论版
- 《ESP32-C3 物联网工程开发实战》书籍讨论版
- 中文文档讨论版
- ESP-AT 中文讨论版
- ESP-BOX 中文讨论版
- ESP IoT Solution 中文讨论版
- ESP-ADF 中文讨论版
- ESP Mesh 中文讨论版
- ESP Cloud 中文讨论版
- ESP-WHO 中文讨论版
- ESP-SkaiNet 中文讨论版
- ESP 生产支持讨论版
- 硬件问题讨论
- 项目展示
Who is online
Users browsing this forum: No registered users and 66 guests
- All times are UTC
- Top
- Delete cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. ESP8266EX and ESP32 are some of our products.