esp32-s3如何进行3线spi通信?[已解决]

jr-test
Posts: 100
Joined: Mon Aug 23, 2021 3:04 am

esp32-s3如何进行3线spi通信?[已解决]

Postby jr-test » Mon Dec 20, 2021 10:01 am

想通过esp32-s3驱动3线spi的屏,但是一直初始化不成功。所以来求助一下esp32的3线spi通信。

enjoyic
Posts: 3
Joined: Sun Apr 24, 2022 2:10 am

Re: esp32-s3如何进行3线spi通信?

Postby enjoyic » Tue May 03, 2022 2:56 am

不知道通过st7789驱动修改是否可以,好像st7789也需要spi配置的。
学为鸟人

lisongzehn
Posts: 2
Joined: Tue Jul 12, 2022 1:19 am

Re: esp32-s3如何进行3线spi通信?

Postby lisongzehn » Tue Jul 12, 2022 1:41 am

1、SPI配置为3Wire 9Bit模式
  1. void SPI_3Wire_Interface_Init(  esp_err_t* ret, \
  2.                                 spi_device_handle_t* spi, \
  3.                                 spi_bus_config_t* buscfg, \
  4.                                 spi_device_interface_config_t* devcfg)
  5. {
  6.     buscfg->miso_io_num=-1;
  7.     buscfg->mosi_io_num=PIN_NUM_SPI_3WIRE_SDA_IO;
  8.     buscfg->sclk_io_num=PIN_NUM_SPI_3WIRE_SCLK_O;
  9.     buscfg->quadwp_io_num=-1;
  10.     buscfg->quadhd_io_num=-1;
  11.     //buscfg.data4_io_num=-1;
  12.     //buscfg.data5_io_num=-1;
  13.     //buscfg.data6_io_num=-1;
  14.     //buscfg.data7_io_num=-1;
  15.     buscfg->max_transfer_sz=xSPI_Max_transfer_size; //= 4096 Byte  
  16.     buscfg->flags=SPICOMMON_BUSFLAG_DUAL;  
  17.     //buscfg.intr_flags=;  
  18.  
  19.     devcfg->command_bits=1;     //D/Cx位,0 cmd, 1 data
  20.     //devcfg.address_bits=24;
  21.     //devcfg.dummy_bits=;
  22.     devcfg->mode=xSPI_CPOL_CPHA_mode;   //CPOL, CPHA xSPI_CPOL_CPHA_mode = 0   
  23.     //devcfg.duty_cycle_pos;   
  24.     //devcfg.cs_ena_pretrans;
  25.     //devcfg.cs_ena_posttrans;
  26.     devcfg->clock_speed_hz=xSPI_Clock_Speed_For_DM_Initial; //=1MHz        
  27.     //devcfg.input_delay_ns=;
  28.     //devcfg->spics_io_num=PIN_NUM_SPI_4WIRE_2_CS_O;   
  29.     devcfg->flags=SPI_DEVICE_3WIRE | SPI_DEVICE_HALFDUPLEX; //3线半双工
  30.     devcfg->queue_size=7;                          
  31.     //*devcfg.pre_cb=RS_transfer_callback;  //D/C(RS)处理
  32.     //devcfg.post_cb=;
  33.  
  34.     //Initialize the SPI bus
  35.     *ret=spi_bus_initialize(LCD_HOST, buscfg, SPI_DMA_CH_AUTO);  
  36.     ESP_ERROR_CHECK(*ret);
  37.     //Attach the LCD to the SPI bus
  38.     *ret=spi_bus_add_device(LCD_HOST, devcfg, spi);
  39.     ESP_ERROR_CHECK(*ret);
  40. }
2、写1R1D
  1. lcd_write_1R1D(0xFE, 0x20);
  2.  
  3. void lcd_write_1R1D(const uint8_t cmd, const uint8_t data)
  4. {
  5.     DM_CS(0);
  6.  
  7.     //发送cmd
  8.     memset(&sendcfg, 0, sizeof(sendcfg));  
  9.     sendcfg.cmd = 0;                        //cmd = 0
  10.     sendcfg.length=8;                      
  11.     sendcfg.tx_buffer = &cmd;
  12.     ret=spi_device_polling_transmit(spi, &sendcfg);    
  13.     assert(ret==ESP_OK);                    
  14.  
  15.     //发送data
  16.     memset(&sendcfg, 0, sizeof(sendcfg));  
  17.     sendcfg.cmd = 1;                        //data = 1
  18.     sendcfg.length=8;                      
  19.     sendcfg.tx_buffer = &data;
  20.     ret=spi_device_polling_transmit(spi, &sendcfg);    
  21.     assert(ret==ESP_OK);                    
  22.  
  23.     DM_CS(1);
  24. }
3、波形图
1R1D波形图.jpg
1R1D波形图.jpg (95.97 KiB) Viewed 3525 times

Who is online

Users browsing this forum: No registered users and 33 guests