LilyGo-T-Wristband, connect via SPI to the ST7735

bushidik9898
Posts: 1
Joined: Mon Jun 13, 2022 6:43 pm

LilyGo-T-Wristband, connect via SPI to the ST7735

Postby bushidik9898 » Mon Jun 13, 2022 6:54 pm

Hello!

I've got a problem porting Arduino code to the native idf-esp code using LilyGo-T-Wristband board. Cannot read ID register from ST7735 via SPI. Here is my code with SPI init and read:

Code: Select all

    gpio_config_t io_conf;
    io_conf.intr_type = GPIO_INTR_DISABLE;
    io_conf.mode = GPIO_MODE_OUTPUT;
    io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
    io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
    io_conf.pin_bit_mask = (1ULL<<TFT_DC);
    gpio_config(&io_conf); 
 
    esp_err_t ret;
    spi_bus_config_t buscfg;
    memset(&buscfg,0,sizeof(buscfg));
    
    buscfg.miso_io_num= -1; //no MISO line
    buscfg.mosi_io_num=TFT_MOSI;
    buscfg.sclk_io_num=TFT_SCLK;
    buscfg.quadhd_io_num=-1;
    buscfg.max_transfer_sz=160*80*2;
    buscfg.quadwp_io_num = -1;
    buscfg.flags = SPICOMMON_BUSFLAG_MASTER;

    spi_device_interface_config_t devcfg;
    memset(&devcfg, 0, sizeof(devcfg));
  
    devcfg.clock_speed_hz=SPI_READ_FREQUENCY;           //Clock out at 10 MHz
    devcfg.mode=0;                                //SPI mode 0
    devcfg.spics_io_num=TFT_CS;               //CS pin
    devcfg.queue_size=1;                          
    devcfg.flags = SPI_DEVICE_HALFDUPLEX;
  
    //Initialize the SPI bus
    ret=spi_bus_initialize(SPI2_HOST, &buscfg, SPI_DMA_DISABLED);
    ESP_ERROR_CHECK(ret);
    //Attach the LCD to the SPI bus
    ret=spi_bus_add_device(SPI2_HOST, &devcfg, &my_spi);
    ESP_ERROR_CHECK(ret);
    
    //read the ID register 0x04
    gpio_set_level(TFT_DC, 0); //set command mode
    uint8_t cmd = (0x4);

    spi_transaction_t t;
    memset(&t, 0, sizeof(t));          //Zero out the transaction
    t.length=8;                        //Command is 8 bits
    t.rxlength = 0;
    t.tx_buffer=&cmd;                  //The data is the cmd itself
    t.rx_buffer = NULL;
    t.user=(void*)0;                   //D/C needs to be set to 0
    ESP_ERROR_CHECK(spi_device_polling_transmit(my_spi, &t));  //Transmit!

    gpio_set_level(TFT_DC, 1);  //set DATA mode

    uint8_t rbuf[4] = {0};

    memset(&t, 0, sizeof(spi_transaction_t));
    t.tx_buffer=NULL;            //send nothing
    t.length=0;                  //send nothing
    t.rx_buffer=rbuf;            //receive RGB data to buffer
    t.rxlength=8*3;      //one line size in bits
    t.flags=0;                   //undo SPI_TRANS_USE_TXDATA flag
    t.user=(void*)1;
    ESP_ERROR_CHECK(spi_device_polling_transmit(my_spi, &t));  //Transmit!
    
Any ideas?

Who is online

Users browsing this forum: ferrero and 57 guests