我使用ESP32S3的SPI master模式控制一个SPI器件,配置为mode=3,但是初始化完成后,时钟线一直保持在低电平。
我查了是在spi_bus_initialize函数调用spicommon_bus_initialize_io里面再调用esp_rom_gpio_connect_out_signal(bus_config->sclk_io_num, spi_periph_signal[host].spiclk_out, false, false);之后时钟线即被拉低。无论SPI模式mode=0~3任何情况。
尝试了各种配置,没找打解决办法,不知道大家有遇到过吗?
信号我用saleae logic2采集了波形,测试了多次,每次都是上电后第一帧数据出错。
数据和代码见附件。
MCU:ESP32S3
IDE:ESP-IDF V5.1
- void CSLOW(void)
- {
- gpio_set_level(48, 0);
- }
- void CSHIGH(void)
- {
- gpio_set_level(48, 1);
- }
- void app_main(void)
- {
- spi_device_handle_t spi;
- char buf[] = {1, 2, 3, 4, 5, 6, 7, 8};
- gpio_config_t ioconfig = {
- .mode = GPIO_MODE_OUTPUT,
- .intr_type = GPIO_INTR_DISABLE,
- .pull_up_en = GPIO_PULLUP_ENABLE,
- .pin_bit_mask = (1ULL << 48),
- };
- gpio_config(&ioconfig);
- spi_bus_config_t busconfig = {
- .mosi_io_num = 19,
- .miso_io_num = 20,
- .sclk_io_num = 21,
- .quadhd_io_num = -1,
- .quadwp_io_num = -1,
- };
- spi_bus_initialize(SPI2_HOST, &busconfig, SPI_DMA_CH_AUTO);
- spi_device_interface_config_t devconfig = {
- .spics_io_num = -1,
- .clock_speed_hz = 1000000,
- .mode = 3,
- .queue_size = 3,
- // .post_cb = CSHIGH,
- // .pre_cb = CSLOW,
- };
- spi_bus_add_device(SPI2_HOST, &devconfig, &spi);
- spi_transaction_t t = {
- .length = 8 * 8,
- .tx_buffer = buf,
- .rx_buffer = NULL,
- };
- while (1)
- {
- vTaskDelay(pdMS_TO_TICKS(3000));
- CSLOW();
- spi_device_transmit(spi, &t);
- CSHIGH();
- }
- vTaskDelete(NULL);
- }