为什么espidf的spi就是很慢

This commit is contained in:
2026-02-18 04:00:04 +08:00
parent ce0b15e2fa
commit 4adb13d748
10 changed files with 453 additions and 16 deletions
+38 -16
View File
@@ -49,7 +49,8 @@ void spi_init()
.quadwp_io_num = -1, // 不使用 QWP
.quadhd_io_num = -1, // 不使用 QHD
.max_transfer_sz = 4096, // 最大传输大小
.flags = SPICOMMON_BUSFLAG_MASTER,
.flags = 0,
.intr_flags = 0,
};
// 2. 初始化 SPI 总线
@@ -69,6 +70,9 @@ void spi_init()
.spics_io_num = LCD_CS,
.queue_size = 7, // 队列深度
.flags = SPI_DEVICE_NO_DUMMY, // 禁用 dummy 周期
.input_delay_ns = 0,
.pre_cb = NULL,
.post_cb = NULL,
};
@@ -82,15 +86,33 @@ void spi_init()
}
// SPI 写数据
esp_err_t lcd_spi_write8(uint8_t data) {
spi_transaction_t trans = {
.length = 8, // 数据位数
.tx_buffer = &data, // 发送缓冲区
.rx_buffer = NULL, // 不接收
// 高速数据传输函数
esp_err_t spi_transfer_fast(spi_device_handle_t spi, uint8_t *tx_data, uint8_t *rx_data, size_t len)
{
spi_transaction_t t = {
.flags = 0,
.cmd = 0,
.addr = 0,
.length = 8 * len,
.tx_buffer = tx_data,
.rx_buffer = rx_data,
};
return spi_device_transmit(lcd_spi, &trans);
// 使用轮询传输(小数据量更快)
return spi_device_polling_transmit(spi, &t);
}
// SPI 写数据
esp_err_t lcd_spi_write8(uint8_t data) {
// spi_transaction_t trans = {
// .length = 8, // 数据位数
// .tx_buffer = &data, // 发送缓冲区
// .rx_buffer = NULL, // 不接收
// };
// return spi_device_transmit(lcd_spi, &trans);
return spi_transfer_fast(lcd_spi,&data,NULL,1);
}
// SPI 写数据
@@ -100,15 +122,15 @@ esp_err_t lcd_spi_write16(uint16_t data) {
tx_buf[1] = data & 0xFF;
tx_buf[0] = (data >> 8) & 0xFF;
spi_transaction_t trans = {
.length = 16, // 数据位数
.tx_buffer = tx_buf, // 发送缓冲区
.rx_buffer = NULL, // 不接收
};
// spi_transaction_t trans = {
// .length = 16, // 数据位数
// .tx_buffer = tx_buf, // 发送缓冲区
// .rx_buffer = NULL, // 不接收
// };
return spi_device_transmit(lcd_spi, &trans);
// return spi_device_transmit(lcd_spi, &trans);
return spi_transfer_fast(lcd_spi,tx_buf,NULL,2);
}
// SPI 写命令