Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

Reading the GRAM on ILI9341 displays

mamuespmamuesp Germany/Northern coast

As I had no luck in Gitter, I pose my question again here, it is more persistent in the forum than in a chat board ... :wink:

I’m trying to read the GRAM of the ILI9341 on my ODROID-GO (could use the M5Stack as well). How to do this is described in the data sheet, and I implemented it with the MOS SPI functions according to the ILI9341 lib. I just added some functions like mgos_ili9341_spi_write8…()which are only wraps of the according static funcs in the lib. The problem is: when trying to read the GRAM, no error occurs, but the memory buffer holds no new data )or only 0 … so I'm asking myself what’s wrong? I call the function line by line with w = 320 and y = [0…239]. Anyone any hint, @pimvanpelt perhaps? The code might be found here ...

Comments

  • nliviunliviu Romania

    I tried to read the GRAM or configuration registers and got unconsistent results.
    Eg.

    static bool ili9341_spi_read(uint8_t *data, uint32_t size) {
      struct mgos_spi *spi = mgos_spi_get_global();
    
      if (!spi) {
        LOG(LL_ERROR, ("SPI is disabled, set spi.enable=true"));
        return false;
      }
    
      struct mgos_spi_txn txn = {.cs = mgos_sys_config_get_ili9341_cs_index(),
                                 .mode = 0,
                                 .freq = mgos_sys_config_get_ili9341_spi_freq(),
                                 .hd.tx_data = 0,
                                 .hd.tx_len = 0,
                                 .hd.dummy_len = 0,
                                 .hd.rx_len = size,
                                 .hd.rx_data = data};
      return mgos_spi_run_txn(spi, false, &txn);
    }
    
    void ili9341_read_display_pixel_format() {
      ili9341_spi_write8_cmd(ILI9341_RDPIXFMT);
      mgos_gpio_write(mgos_sys_config_get_ili9341_dc_pin(), 1);
    
      uint8_t buf[2];
      memset(buf, 0x55, sizeof(buf));
      bool ok = ili9341_spi_read(buf, sizeof(buf));
    
      if (ok) {
        LOG(LL_INFO,
            ("dummy=%hhx, Display Pixel Format=%hhx, RIM|DPI=%hhx, DBI=%hhx",
             buf[0], buf[1], (buf[1] >> 4) & 0x0F, buf[1] & 0x0F));
      } else {
        LOG(LL_INFO, ("Error, no SPI data received!"));
      }
    }
    

    Results:

    [Aug  8 18:58:25.299] ili9341_read_display dummy=0, Display Pixel Format=0, RIM|DPI=0, DBI=0
    [Aug  8 18:58:46.433] ili9341_read_display dummy=ff, Display Pixel Format=ff, RIM|DPI=f, DBI=f
    [Aug  8 18:58:56.433] ili9341_read_display dummy=0, Display Pixel Format=0, RIM|DPI=0, DBI=0
    [Aug  8 18:59:06.433] ili9341_read_display dummy=0, Display Pixel Format=0, RIM|DPI=0, DBI=0
    [Aug  8 18:59:16.433] ili9341_read_display dummy=0, Display Pixel Format=0, RIM|DPI=0, DBI=0
    [Aug  8 18:59:26.433] ili9341_read_display dummy=0, Display Pixel Format=0, RIM|DPI=0, DBI=0
    [Aug  8 18:59:36.434] ili9341_read_display dummy=ff, Display Pixel Format=ff, RIM|DPI=f, DBI=f
    [Aug  8 18:59:46.434] ili9341_read_display dummy=ff, Display Pixel Format=ff, RIM|DPI=f, DBI=f
    [Aug  8 18:59:56.434] ili9341_read_display dummy=0, Display Pixel Format=0, RIM|DPI=0, DBI=0
    [Aug  8 19:00:06.434] ili9341_read_display dummy=0, Display Pixel Format=0, RIM|DPI=0, DBI=0
    [Aug  8 19:00:16.434] ili9341_read_display dummy=ff, Display Pixel Format=ff, RIM|DPI=f, DBI=f
    
  • nliviunliviu Romania

    Updated ili9341_spi_read after running tft_demo.c which reported max_rdclock of 8MHz.

    const int SPI_READ_FREQ = 4000000;
    
    static bool ili9341_spi_read(uint8_t *data, uint32_t size) {
      struct mgos_spi *spi = mgos_spi_get_global();
    
      if (!spi) {
        LOG(LL_ERROR, ("SPI is disabled, set spi.enable=true"));
        return false;
      }
    
      struct mgos_spi_txn txn = {
          .cs = mgos_sys_config_get_ili9341_cs_index(),
          .mode = 0,
          .freq = SPI_READ_FREQ,  // mgos_sys_config_get_ili9341_spi_freq(),
          .hd.tx_data = 0,
          .hd.tx_len = 0,
          .hd.dummy_len = 0,
          .hd.rx_len = size,
          .hd.rx_data = data};
      return mgos_spi_run_txn(spi, false, &txn);
    }
    

    Still got unconsistent results.

Sign In or Register to comment.