Menu

ST7735 GLCD controller and SPI

Help
MBB
2019-09-06
2019-11-10
1 2 > >> (Page 1 of 2)
  • MBB

    MBB - 2019-09-06

    RESOLVED: NEW CAPABILITY ADDED TO GLCD DRIVER SUPPORT

    EDITED - JUMP To https://sourceforge.net/p/gcbasic/discussion/579126/thread/c0adbef6f9/#46ab/f797


    Does ST7735.h and GLCD.h support the SPI protocol? If so, can it be made to work with a 160 x 80 Mini TFT display?

     

    Last edit: Anobium 2019-11-10
  • Anobium

    Anobium - 2019-09-07
    It supports the SPI protocol already.  Hardware and Sofware.
    
    If you add to your program the following two constants - it should work.
    
    #define GLCD_WIDTH 160
    #define GLCD_HEIGHT 80
    
     
  • MBB

    MBB - 2019-09-07

    Thanks! I'll try this.

     
  • Anobium

    Anobium - 2019-09-07

    We will probably have to adapt the library but do wire it up and when the pixels don't do what you expect... let me know.

    GLCDCLS will work..but, I would be trying box 0,0,159,79. if box fails then we will have to mod the unit. A very simple change of you have it all wired up.

     
  • MBB

    MBB - 2019-09-08

    I'm using this GLCD
    'Adafruit Mini TFT Feather Wing 160 x 80
    'https://learn.adafruit.com/adafruit-mini-tft-featherwing

    Here is my code:

    ;Chip Settings
    #chip 18F4550,48
    #config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, LVP=OFF, MCLRE=ON

               #include <glcd.h>
    

    ;Defines (Constants)
    #define SPI_HardwareSPI 'comment this out to make into Software SPI but, you may have to change clock lines
    #define GLCD_TYPE GLCD_TYPE_ST7735
    #define DEFAULT_GLCDBACKGROUND 0xF800 ;0x67F0
    #define ST7735TABCOLOR ST7735_MINI160x80

                       #define GLCD_WIDTH 160
                    #define GLCD_HEIGHT 80
    

    'Pin mappings for ST7735
    #define GLCD_DC portE.2 ; Data/Command select Purple Wire
    #define GLCD_CS portB.2 ; /CS Chip select White
    #define GLCD_RESET portC.6
    #define GLCD_DI portB.0 ; SPI SDI (MISO) Not used by this display
    #define GLCD_DO portC.7 ; SPI SDO (MOSI) Blue
    #define GLCD_SCK portB.1 ; SPI SCK Green

    Dir GLCD_DC Out
    Dir GLCD_CS Out
    Dir GLCD_RESET Out
    Dir GLCD_DI In
    Dir GLCD_DO Out
    Dir GLCD_SCK Out

    SPIMode ( Master, SPI_CPOL_0 + SPI_CPHA_0 )
    '
    wait 100 ms

    Do_Again:
    GLCD_CS = 1

    wait 1 s

    GLCD_CS = 0
    GLCD_DC = 0 ;Command = 0 Data = 1 I tried both 0 and 1 but saw no change in GLCD display

    GLCDCLS TFT_BLUE
    box 0, 0, 159, 79

    Goto Do_Again

    On my O'Scope, I see the GLCD_CS transistion from 1 to 0 and back to 1 but there are no clock pulses or data pulses. The display has the backlight on and does not change from a white background.

     
  • Anobium

    Anobium - 2019-09-08

    Cut the code down to diagnose.

    You do not need all the CS tests, GLCDCLS etc etc etc. The setup handled in the library. SPIMode is calculate, Run the chip from the internal OSC so that we can diag the basics.

    This is intended to draw a box using the minimum code. I am assuming the ports/data lines are connected. Test this please. Exactly what happens on the GLCD?

    ;Chip Settings
        #chip 18F4550
    
    #include <glcd.h>
    
    ' let us us software SPI to rule out HW SPI issues.
    ' #define SPI_HardwareSPI  'comment this out to make into Software SPI but, you may have to change clock lines
    #define GLCD_TYPE GLCD_TYPE_ST7735
    
    #define GLCD_WIDTH 160
    #define GLCD_HEIGHT 80
    
    'Pin mappings for ST7735
    #define GLCD_DC portE.2 ;            Data/Command select    Purple Wire
    #define GLCD_CS portB.2 ;            /CS Chip select        White
    #define GLCD_RESET portC.6
    #define GLCD_DI portB.0 ;            SPI SDI (MISO)  Not used by this display
    #define GLCD_DO portC.7 ;            SPI SDO (MOSI)         Blue
    #define GLCD_SCK portB.1 ;           SPI SCK                Green
    
    box 0, 0, 10, 10
    
    Do
    Loop
    
     

    Last edit: Anobium 2019-09-08
  • MBB

    MBB - 2019-09-08

    Yes, the port data lines are connected.

    On the O'Scope I see clock and data pulses but the display is the same as before.

     
  • Anobium

    Anobium - 2019-09-08

    Ok. we have a baseline. tomorrow, I will put up a test rig.

    Check back tomorrow.

     

    Last edit: Anobium 2019-09-09
  • Anobium

    Anobium - 2019-09-09

    The code posted above produces a white box on the display.

    So, this was my approach.

    1. Took stock demo and test in the test rig. This was a 18F47K42. So, this proves the demo works.
    2. Took stock demo created a standalone rig. Again, using a 18F47K42. So, this proves the standalone rig works.
    3. Change the ports of the stock demo to your ports. The stock demo uses software SPI. This ran the stock demo, and, changing the connections to match.
    4. Changed to the code below for the K42. Worked with a white box on the display.
    5. Change the chip to the 18F4550. Worked with white box on the display.

    This is not fast, but, this is prove things. Then, we can sort the frequency.

    Test code.

    ;Chip Settings
        #chip 18F4550
    
    #include <glcd.h>
    
    ' let us us software SPI to rule out HW SPI issues.
    ' #define SPI_HardwareSPI  'comment this out to make into Software SPI but, you may have to change clock lines
    #define GLCD_TYPE GLCD_TYPE_ST7735
    
    #define GLCD_WIDTH 160
    #define GLCD_HEIGHT 80
    
    'Pin mappings for ST7735
    #define GLCD_DC portE.2 ;            Data/Command select    Purple Wire
    #define GLCD_CS portB.2 ;            /CS Chip select        White
    #define GLCD_RESET portC.6
    #define GLCD_DI portB.0 ;            SPI SDI (MISO)  Not used by this display
    #define GLCD_DO portC.7 ;            SPI SDO (MOSI)         Blue
    #define GLCD_SCK portB.1 ;           SPI SCK                Green
    
    box 0, 0, 10, 10
    
    Do
    Loop
    

    Note. The COLORtab only affect the offset position of the display nothing really functional.


    So, check the connections - test.

    And, I have attached my HEX. Could be something in version of toolchain.... maybe.

    Then, post the datasheet for the GCLD. Have you spotted that the INIT is different?


    Test and let me know the results.

     
  • Anobium

    Anobium - 2019-09-09

    I then added the config to get 48mhz, work with the white box. Then, created new demo for 4550 with the stock demo. See attachment.

    ;Chip Settings for 48mhz using a 20 MHz crystal
    #chip 18F4550, 48
    #config FOSC=HSPLL_HS, PLLDIV=5, CPUDIV=OSC1_PLL2,  MCLRE=ON
    

    So, is the GLCD totally different?

     
  • MBB

    MBB - 2019-09-09

    On my O'Scope I see the Clock, Data, and CS pulses so the 18F4550 is sending the data.

    The GLCD remains a blank screen with a white background and the backlight on, i.e. the GLCD is not responding.

     
    • Anobium

      Anobium - 2019-09-09

      No RESET? Very important.

      Are you test the code I posted?

       
  • MBB

    MBB - 2019-09-09

    By RESET I assume you mean : #define GLCD_RESET portC.6
    This goes low for about 750 usec and then about 4.7 seconds later I see the clock pulses. The Data pulses start at about 6.4 seconds after the RESET pulse.

    But the GLCD is the same as before.

    I am using the code you posted.

     
    • Anobium

      Anobium - 2019-09-09

      Datasheet please and code that is meant to work with an Arduino.

      Are you UK based? Send me a private message if the answer concerns you. :-)

       
  • Anobium

    Anobium - 2019-09-09

    I just found the datasheet. The product you have is an ST7735R not ST7735.

    The datasheet for the ST7735 URL is in the Help file.

    Differences between the two are RGBSET (code 0x2D) which is not supported in the current driver.


    So, I want you to port this to your chip. We need to know the parameters for the GLCD. C:\GCB@Syn\GreatCowBasic\Demos\glcd_solutions\glcd_discovery_for_mcufriend_devices\glcd_discovery_spi_data.gcb

    This program will show you on the serial terminal lots of parameters - can we please confirm RDID1, RDID2 and RDID3 by porting the code above.


    Or, send me a GLCD to sort.

     
    • Anobium

      Anobium - 2019-09-09

      And, I just found that these MAY only work at 8mhz. So, slow the clock to the default and then try even slow frequencies... this may be a red herring but try slow frequencies.

       
  • Anobium

    Anobium - 2019-09-09

    and, then, this is most informative. Python init code.

    _INIT_SEQUENCE = bytearray(~~~
    
    b"\x01\x80\x96" # SWRESET and Delay 150ms
    b"\x11\x80\xff" # SLPOUT and Delay
    b"\xb1\x03\x01\x2C\x2D" # _FRMCTR1
    b"\xb2\x03\x01\x2C\x2D" # _FRMCTR2
    b"\xb3\x06\x01\x2C\x2D\x01\x2C\x2D" # _FRMCTR3
    b"\xb4\x01\x07" # _INVCTR line inversion
    b"\xc0\x03\xa2\x02\x84" # _PWCTR1 GVDD = 4.7V, 1.0uA
    b"\xc1\x01\xc5" # _PWCTR2 VGH=14.7V, VGL=-7.35V
    b"\xc2\x02\x0a\x00" # _PWCTR3 Opamp current small, Boost frequency
    b"\xc3\x02\x8a\x2a"
    b"\xc4\x02\x8a\xee"
    b"\xc5\x01\x0e" # _VMCTR1 VCOMH = 4V, VOML = -1.1V
    b"\x20\x00" # _INVOFF
    b"\x36\x01\x18" # _MADCTL bottom to top refresh
    # 1 clk cycle nonoverlap, 2 cycle gate rise, 3 sycle osc equalie,
    # fix on VTL
    b"\x3a\x01\x05" # COLMOD - 16bit color
    b"\xe0\x10\x02\x1c\x07\x12\x37\x32\x29\x2d\x29\x25\x2B\x39\x00\x01\x03\x10" # _GMCTRP1 Gamma
    b"\xe1\x10\x03\x1d\x07\x06\x2E\x2C\x29\x2D\x2E\x2E\x37\x3F\x00\x00\x02\x10" # _GMCTRN1
    b"\x13\x80\x0a" # _NORON
    b"\x29\x80\x64" # _DISPON
    
     

    Last edit: Anobium 2019-09-09
    • Anobium

      Anobium - 2019-09-09

      Ok. I can port the INIT.

      The differences are many Power4, Power5, MADCTL, CASET, GMCTRP1 and GMCTRP2.

      I can have a go at providing you a new INIT but it will be my Tuesday morning (London) time. It will not take more than 30 mins to write a new init and it should work.

      :-)

       
  • MBB

    MBB - 2019-09-09

    I tried C:\GCB@Syn\GreatCowBasic\Demos\glcd_solutions\glcd_discovery_for_mcufriend_devices\glcd_discovery_spi_data.gcb

    I removed this line from the code: #include <uno_mega328p.h>. I don't know the equivalent file for th 18F4550.</uno_mega328p.h>

    I went down to 4 MHz and ran the program.

    At the start I see:

    Read Registers on GLCD device

    controllers with an SPI interface

    reg(0x0000) FF FF FF FF FF FF FF f.k

    reg(0x0001) FF FF FF FF FF FF FF f.k

    reg(0x0002) FF FF FF FF FF FF FF f.k

    reg(0x0003) FF FF FF FF FF FF FF f.k

    All the regiaters read the same as the above.

    At the end I see:

    reg(0x00FC) FF FF FF FF FF FF FF f.k

    reg(0x00FD) FF FF FF FF FF FF FF f.k

    reg(0x00FE) FF FF FF FF FF FF FF f.k

    reg(0x00FF) FF FF FF FF FF FF FF f.k

    Examining :

    Read : GLCD Device ID = 0x0000

    Controller : unknown GLCD

    Completed :

    I saw nothing regarding RDID1, RDID2 and RDID3

     
    • Anobium

      Anobium - 2019-09-09

      Post the code. I will try here. That looks like it is not communicating.

       
  • MBB

    MBB - 2019-09-09

    Here' my code

     
  • Anobium

    Anobium - 2019-09-09

    ok. Check back tomorrow. I will try   to resolve.

     
  • Anobium

    Anobium - 2019-09-10

    Here we go. I have never done this before. Writing a remote GLCD library.

    Baseline code. We will keep it the same but note the change to the GLCD_TYPE.

    ;Chip Settings for 48mhz using a 20 MHz crystal
    #chip 18F4550, 48
    #config FOSC=HSPLL_HS, PLLDIV=5, CPUDIV=OSC1_PLL2,  MCLRE=ON
    
    #include <glcd.h>
    #define GLCD_TYPE GLCD_TYPE_ST7735R
    
    
    ' let us us software SPI to rule out HW SPI issues.  We will test HW SPI later.
    ' #define SPI_HardwareSPI  'comment this out to make into Software SPI but, you may have to change clock lines
    
    
    'Pin mappings for ST7735R
    #define GLCD_DC portE.2 ;            Data/Command select    Purple Wire
    #define GLCD_CS portB.2 ;            /CS Chip select        White
    #define GLCD_RESET portC.6
    #define GLCD_DI portB.0 ;            SPI SDI (MISO)  Not used by this display
    #define GLCD_DO portC.7 ;            SPI SDO (MOSI)         Blue
    #define GLCD_SCK portB.1 ;           SPI SCK                Green
    
    box 0, 0, 20, 20
    
    Do
    Loop
    

    I have added a new type of GLCD the ST7735R. This has a different size and different init cycle but I am reusing as much as I can from the ST7735 library.

    Download the library from here: https://github.com/Anobium/Great-Cow-BASIC-Library-Development/tree/master/ST7735R You will see a ZIP file. Download. Backup existing GLCD files, and then replace with the contents of the ZIP.

    We are using Software SPI to keep things simple. And, this does not test/confirm colors. We will do this later.

    Test with the program above I cannot test... as my ST7735 not longer works with the new library... fancy that! If I have made errors then be patient.

    :-)

     

    Last edit: Anobium 2019-09-10
  • MBB

    MBB - 2019-09-10

    I tried both glcd_discovery_spi_data.gcb and New91.gcb with the 3 new glcd.h include files.

    I assumed that I should use this #define GLCD_TYPE GLCD_TYPE_ST7735R

    I get the following warning:
    '>>> WARNINGs / ERRORs reported by Great Cow BASIC (if Syntax Error, doubleclick on the errormessage below) <<<
    'glcd.h (206): Warning: Cannot find C:\GCB@Syn5\GreatCowBasic\include\glcd_UC1601.h

    I get the same results as before - the GLCD display does not change.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.