Connect a TFT with ST7735S to ESP32 with ESP-IDF
Posted: Tue May 17, 2022 6:30 pm
I cannot communicate with the display. Any help is highly wellcome!
Following are the main configurations data:
spi_bus_config_t:
spi_device_interface_config_t:
THe code for transmitting a command:
Code for transmitting data:
What am I doing wrong?
Following are the main configurations data:
spi_bus_config_t:
- spi_bus_config_t BusCfg= {
- .mosi_io_num=23,
- .miso_io_num=-1,
- .sclk_io_num=18,
- .quadwp_io_num=-1,
- .quadhd_io_num=-1,
- };
- spi_device_interface_config_t DevCfg={
- .mode=0, //SPI mode 0
- .cs_ena_pretrans=2,
- .clock_speed_hz=40*1000*1000,
- .spics_io_num=5, //CS pin set in init
- .flags = SPI_DEVICE_HALFDUPLEX,
- .queue_size=7, /
- .pre_cb=NULL,
- .post_cb=NULL,
- };
- void tft_cmd(const uint8_t cmd){
- esp_err_t ret;
- spi_transaction_t t;
- memset(&t, 0, sizeof(t));
- t.length=8;
- t.tx_data[0]=cmd;
- t.flags=SPI_TRANS_USE_TXDATA | SPI_TRANS_MODE_DIO;
- gpio_set_level(Dc, 0);
- ret=spi_device_polling_transmit(Spi, &t);
- assert(ret==ESP_OK);
- void tft_data(const uint8_t *data, int len)
- {
- esp_err_t ret;
- spi_transaction_t t;
- if (len==0) return; //no need to send anything
- memset(&t, 0, sizeof(t)); //Zero out the transaction
- t.length=len*8; //Len is in bytes, transaction length is in bits.
- t.tx_buffer=data;
- t.flags=SPI_TRANS_MODE_DIO;
- gpio_set_level(Dc, 1);
- ret=spi_device_polling_transmit(Spi, &t);
- assert(ret==ESP_OK);
- }