esp32-s3如何进行3线spi通信?[已解决]
esp32-s3如何进行3线spi通信?[已解决]
想通过esp32-s3驱动3线spi的屏,但是一直初始化不成功。所以来求助一下esp32的3线spi通信。
-
- Posts: 2
- Joined: Tue Jul 12, 2022 1:19 am
Re: esp32-s3如何进行3线spi通信?
1、SPI配置为3Wire 9Bit模式
2、写1R1D
3、波形图
- void SPI_3Wire_Interface_Init( esp_err_t* ret, \
- spi_device_handle_t* spi, \
- spi_bus_config_t* buscfg, \
- spi_device_interface_config_t* devcfg)
- {
- buscfg->miso_io_num=-1;
- buscfg->mosi_io_num=PIN_NUM_SPI_3WIRE_SDA_IO;
- buscfg->sclk_io_num=PIN_NUM_SPI_3WIRE_SCLK_O;
- buscfg->quadwp_io_num=-1;
- buscfg->quadhd_io_num=-1;
- //buscfg.data4_io_num=-1;
- //buscfg.data5_io_num=-1;
- //buscfg.data6_io_num=-1;
- //buscfg.data7_io_num=-1;
- buscfg->max_transfer_sz=xSPI_Max_transfer_size; //= 4096 Byte
- buscfg->flags=SPICOMMON_BUSFLAG_DUAL;
- //buscfg.intr_flags=;
- devcfg->command_bits=1; //D/Cx位,0 cmd, 1 data
- //devcfg.address_bits=24;
- //devcfg.dummy_bits=;
- devcfg->mode=xSPI_CPOL_CPHA_mode; //CPOL, CPHA xSPI_CPOL_CPHA_mode = 0
- //devcfg.duty_cycle_pos;
- //devcfg.cs_ena_pretrans;
- //devcfg.cs_ena_posttrans;
- devcfg->clock_speed_hz=xSPI_Clock_Speed_For_DM_Initial; //=1MHz
- //devcfg.input_delay_ns=;
- //devcfg->spics_io_num=PIN_NUM_SPI_4WIRE_2_CS_O;
- devcfg->flags=SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX; //3线半双工
- devcfg->queue_size=7;
- //*devcfg.pre_cb=RS_transfer_callback; //D/C(RS)处理
- //devcfg.post_cb=;
- //Initialize the SPI bus
- *ret=spi_bus_initialize(LCD_HOST, buscfg, SPI_DMA_CH_AUTO);
- ESP_ERROR_CHECK(*ret);
- //Attach the LCD to the SPI bus
- *ret=spi_bus_add_device(LCD_HOST, devcfg, spi);
- ESP_ERROR_CHECK(*ret);
- }
- lcd_write_1R1D(0xFE, 0x20);
- void lcd_write_1R1D(const uint8_t cmd, const uint8_t data)
- {
- DM_CS(0);
- //发送cmd
- memset(&sendcfg, 0, sizeof(sendcfg));
- sendcfg.cmd = 0; //cmd = 0
- sendcfg.length=8;
- sendcfg.tx_buffer = &cmd;
- ret=spi_device_polling_transmit(spi, &sendcfg);
- assert(ret==ESP_OK);
- //发送data
- memset(&sendcfg, 0, sizeof(sendcfg));
- sendcfg.cmd = 1; //data = 1
- sendcfg.length=8;
- sendcfg.tx_buffer = &data;
- ret=spi_device_polling_transmit(spi, &sendcfg);
- assert(ret==ESP_OK);
- DM_CS(1);
- }
Who is online
Users browsing this forum: No registered users and 37 guests