Page 1 of 1

Connect a TFT with ST7735S to ESP32 with ESP-IDF

Posted: Tue May 17, 2022 6:30 pm
by nefen1
I cannot communicate with the display. Any help is highly wellcome!

Following are the main configurations data:
spi_bus_config_t:
  1.        
  2. spi_bus_config_t BusCfg= {
  3.           .mosi_io_num=23,            
  4.           .miso_io_num=-1,
  5.           .sclk_io_num=18,            
  6.           .quadwp_io_num=-1,
  7.           .quadhd_io_num=-1,
  8.         };
spi_device_interface_config_t:
  1.         spi_device_interface_config_t DevCfg={
  2.             .mode=0,                                //SPI mode 0
  3.             .cs_ena_pretrans=2,                    
  4.             .clock_speed_hz=40*1000*1000,          
  5.             .spics_io_num=5,                       //CS pin set in init
  6.             .flags = SPI_DEVICE_HALFDUPLEX,
  7.             .queue_size=7,                          /
  8.             .pre_cb=NULL,
  9.             .post_cb=NULL,
  10.         };
THe code for transmitting a command:
  1. void tft_cmd(const uint8_t cmd){
  2.  esp_err_t ret;
  3.   spi_transaction_t t;
  4.   memset(&t, 0, sizeof(t));              
  5.   t.length=8;                  
  6.   t.tx_data[0]=cmd;                    
  7.   t.flags=SPI_TRANS_USE_TXDATA | SPI_TRANS_MODE_DIO;
  8.   gpio_set_level(Dc, 0);                  
  9.   ret=spi_device_polling_transmit(Spi, &t);
  10.   assert(ret==ESP_OK);                
Code for transmitting data:
  1. void tft_data(const uint8_t *data, int len)
  2. {
  3.   esp_err_t ret;
  4.   spi_transaction_t t;
  5.  
  6.   if (len==0) return;                         //no need to send anything
  7.   memset(&t, 0, sizeof(t));                   //Zero out the transaction
  8.   t.length=len*8;                             //Len is in bytes, transaction length is in bits.
  9.   t.tx_buffer=data;  
  10.      t.flags=SPI_TRANS_MODE_DIO;
  11.   gpio_set_level(Dc, 1);
  12.   ret=spi_device_polling_transmit(Spi, &t);
  13.   assert(ret==ESP_OK);                        
  14. }
What am I doing wrong?

Re: Connect a TFT with ST7735S to ESP32 with ESP-IDF

Posted: Wed May 18, 2022 1:00 pm
by ESP_Sprite
Why are you using DIO mode?

Re: Connect a TFT with ST7735S to ESP32 with ESP-IDF

Posted: Fri May 20, 2022 7:11 pm
by nefen1
Thank you for posting!

Yes, DIO is wrong.

Finally I had solved it. Mode should be 3 and not 0