Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2c read timeout error with CST816T #594

Closed
Jswood33 opened this issue Jul 25, 2024 · 3 comments
Closed

i2c read timeout error with CST816T #594

Jswood33 opened this issue Jul 25, 2024 · 3 comments
Labels
stale Inactive issues

Comments

@Jswood33
Copy link

Jswood33 commented Jul 25, 2024

Carefully written Issues are more likely to be given priority.
丁寧に記述された報告は優先して対応される可能性が高くなります。

Environment ( 実行環境 )

  • MCU or Board name: ESP-WROOVER-ie
  • Panel Driver IC: [P169H002-CTP] ST7789 CST816T
  • Bus type: [SPI|I2C]
  • LovyanGFX version: [Latest Master]
  • FrameWork version: [ESP-IDF v5.1.1]
  • Build Environment: [VScode]
  • Operating System: [Windows]

Problem Description ( 問題の内容 )

After an unknown amount of time the i2c bus that the touch sensor uses locks up and won't be freed until I reset the device. Usually last a few hours (10-11) then a freeze occurs with this error message: LGFX: i2c read error : read timeout

Expected Behavior ( 期待される動作 )

I2C to run "forever"

Actual Behavior ( 実際の動作 )

I2C locks after an unknown amount of hours.

Steps to reproduce ( 再現のための前提条件 )

  1. step1
  2. ...

// If possible, attach a picture of your setup/wiring here.

image

Code to reproduce this issue ( 再現させるためのコード )

#pragma once

#define LGFX_USE_V1

#include <LovyanGFX.hpp>

#define TFT_WIDTH 240
#define TFT_HEIGHT 300

class LGFX : public lgfx::LGFX_Device
{
lgfx::Panel_ST7789      _panel_instance;
    lgfx::Bus_SPI       _bus_instance; 
    lgfx::Light_PWM     _light_instance;
    lgfx::Touch_CST816S _touch_instance;
  

public:
  LGFX(void)
  {
    { 
      auto cfg = _bus_instance.config();  
// SPI
      cfg.spi_host = VSPI_HOST;     
      cfg.spi_mode = 0;             
      cfg.freq_write = 40000000;   
      cfg.freq_read  = 16000000;    
      cfg.spi_3wire  = true;        
      cfg.use_lock   = true;        
      cfg.dma_channel = SPI_DMA_CH_AUTO; 
      cfg.pin_sclk = 18;            
      cfg.pin_mosi = 19;            
      cfg.pin_miso = -1;            
      cfg.pin_dc   =  2;                


      _bus_instance.config(cfg);    
      _panel_instance.setBus(&_bus_instance);      
    }

    { 
      auto cfg = _panel_instance.config();    

      cfg.pin_cs           =     5;  
      cfg.pin_rst          =    15;  
      cfg.pin_busy         =    -1;        

      cfg.panel_width      =   TFT_WIDTH;  
      cfg.panel_height     =   TFT_HEIGHT;  
      cfg.offset_x         =     0;  
      cfg.offset_y         =     0;  
      cfg.offset_rotation  =     0;  
      cfg.dummy_read_pixel =     8;  
      cfg.dummy_read_bits  =     1;  
      cfg.readable         =  true;  
      cfg.invert           = true;  
      cfg.rgb_order        = true;  
      cfg.dlen_16bit       = false;  
      cfg.bus_shared       = false;  

      _panel_instance.config(cfg);
    }

    { 
      auto cfg = _light_instance.config();    

      cfg.pin_bl =  4;              
      cfg.invert = false;           
      cfg.freq   = 44100;           
      cfg.pwm_channel = 7;          

      _light_instance.config(cfg);
      _panel_instance.setLight(&_light_instance);  
    }

    { 
      auto cfg = _touch_instance.config();

      cfg.x_min      = 0;    
      cfg.x_max      = 239;  
      cfg.y_min      = 0;    
      cfg.y_max      = 300;  
      cfg.pin_int    = 13;   
      cfg.bus_shared = true; 
      cfg.offset_rotation = 0;

// I2C
      cfg.i2c_port = 0;      
      cfg.i2c_addr = 0x15;   
      cfg.pin_sda  = 21;     
      cfg.pin_scl  = 22;     
      cfg.freq = 400000;     

      _touch_instance.config(cfg);
      _panel_instance.setTouch(&_touch_instance);  
    }


    setPanel(&_panel_instance); 
  }
};

Please submit complete source code that can reproduce your problem.
あなたの問題を再現できる完全なソースコードを提示してください。

#include "main.h"

Main App;

#define TAG "GUI_Demo"
#define A_TAG "LSM303AH"

LSM303AH acc;
uint8_t status;

void Main::setup(void)
{
    //Initialize i2c
    i2c_config_t i2c_conf;
    i2c_conf.mode = I2C_MODE_MASTER;
    i2c_conf.sda_io_num = 21;
    i2c_conf.sda_pullup_en = GPIO_PULLUP_DISABLE;
    i2c_conf.scl_io_num = 22;
    i2c_conf.scl_pullup_en = GPIO_PULLUP_DISABLE;
    i2c_conf.master.clk_speed = 400000;
    i2c_conf.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL;
    i2c_param_config(I2C_NUM_0, &i2c_conf);
    i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
    i2c_set_timeout((i2c_port_t)I2C_NUM_0, 0xFFFFF);    
    
    // Initialize NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret ); 

    status = LSM303AH_init( &acc );    
}

extern "C" void app_main(void)
{
    App.setup();      
    lcd.init();         // Initialize LovyanGFX
    lcd.initDMA();      // Init DMA
    lv_init();          // Initialize lvgl    
    
    if (lv_display_init() != ESP_OK) // Configure LVGL
    {
        ESP_LOGE(TAG, "LVGL setup failed!!!");
    }
    
    // /* Initialize the event loop */
    ESP_ERROR_CHECK(esp_event_loop_create_default());    
    lvgl_acquire();    
    ui_init();
    lvgl_release();
    
    while (1) {
        vTaskDelay(pdMS_TO_TICKS(10));

        /* Try to take the semaphore, call lvgl related function on success */
        if (pdTRUE == xSemaphoreTake(xGuiSemaphore, portMAX_DELAY)) {
            lv_task_handler();
            lv_timer_handler();
            //lv_timer_handler_run_in_period(5); /* run lv_timer_handler() every 5ms */
            xSemaphoreGive(xGuiSemaphore);
        }
        if (status != 255) {
            if (LSM303AH_DataReady(&acc)) {
                LSM303AH_ReadAccelerations(&acc);
                printf("X: %.2f, Y: %.2f, Z: %.2f\r\n", acc.acc_raw[0], acc.acc_raw[1], acc.acc_raw[2]);
            }
        }        
    }
}
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Inactive issues label Aug 25, 2024
Copy link

github-actions bot commented Sep 1, 2024

This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2024
@tobozo
Copy link
Collaborator

tobozo commented Sep 1, 2024

FIY motors can interfer with I2C, so it's worth trying to disconnect your vibration motor and see if the problem is still there

if it is, then you should use twisted pairs / shielded cable with I2C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Inactive issues
Projects
None yet
Development

No branches or pull requests

2 participants