1. spi_master: check_trans_valid(698): rxdata transfer > host maximum

问题原因是spi_transaction_t事件多次重复定义,解决方法是将
spi_transaction_t t;
转移到while(1)循环外面,不要每次都重复定义:
static void spi_task(void *pvParameters){
//Configuration for the SPI bus
spi_bus_config_t buscfg = {
.mosi_io_num = GPIO_BB_MOSI,
.miso_io_num = GPIO_BB_MISO,
.sclk_io_num = GPIO_BB_SCLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1
//.max_transfer_sz = 81920
};
//Configuration for the SPI device on the other side of the bus
spi_device_interface_config_t devcfg = {
.command_bits = 0,
.address_bits = 0,
.dummy_bits = 0,
.clock_speed_hz = 20000000, //20MHz时钟频率
.input_delay_ns = 0,
.duty_cycle_pos = 128, //50% duty cycle
.mode = 2,
.spics_io_num = GPIO_BB_CS,
.cs_ena_posttrans = 3,
.queue_size = 3
};
//注册发送CMOS控制指令的SPI 通道
static esp_err_t ret_cmos;
//Initialize the SPI bus and add the device we want to send stuff to.
ret_cmos = spi_bus_initialize(CMOSCTRL_HOST, &buscfg, SPI_DMA_CH_AUTO);
assert(ret_cmos==ESP_OK);
ret_cmos = spi_bus_add_device(CMOSCTRL_HOST, &devcfg, &handle_cmos);
assert(ret_cmos==ESP_OK);
spi_transaction_t t;
while(1){
t.length = sizeof(cmos_sendbuf)*8;
t.tx_buffer = cmos_sendbuf;
t.rx_buffer = cmos_recvbuf;
ESP_ERROR_CHECK(spi_device_transmit(handle_cmos, &t));
vTaskDelay(1 / portTICK_PERIOD_MS);
}
}
2. spi_master: check_trans_valid(1103): txdata transfer > host maximum
问题原因可能为:
1)传输缓冲区大小不正确
2)当待传输数据量很大时未开启DMA
3)传输大量数据时未更改spi_bus_config_t结构体中的最大传输数据长度
对应的解决方案:
2)在初始化SPI总线时开启DMA,但需要注意,这时SPI模式0不支持使用:
//Initialize the SPI bus and add the device we want to send stuff to.
ret_cmos = spi_bus_initialize(CMOSCTRL_HOST, &buscfg, SPI_DMA_CH_AUTO);
assert(ret_cmos==ESP_OK);
ret_cmos = spi_bus_add_device(CMOSCTRL_HOST, &devcfg, &handle_cmos);
assert(ret_cmos==ESP_OK);
3) 在spi_bus_config_t结构体中配置最大传输长度:
//Configuration for the SPI bus
spi_bus_config_t buscfg = {
.mosi_io_num = GPIO_BB_MOSI,
.miso_io_num = GPIO_BB_MISO,
.sclk_io_num = GPIO_BB_SCLK,
.quadwp_io_num = -1,
.quadhd_io_num = -1
.max_transfer_sz = 81920
};
文章讲述了spi_master中出现的重复定义问题以及检查传输有效性的错误,涉及了DMA使用、传输缓冲区大小、最大传输数据长度配置等,提供了相应的解决方案。
5728

被折叠的 条评论
为什么被折叠?



