Menu

GLCD with SPI and HI2C

Help
MBB
2019-12-01
2019-12-02
  • MBB

    MBB - 2019-12-01

    I'm using this GLCD: https://learn.adafruit.com/adafruit-mini-tft-featherwing
    It is an ST7735R which uses SPI. When I use software with only SPI commands in it everything works great.

    If I use it with a circuit that uses both SPI and I2C I have problems. In the below program the first three " GLCDPrint" statements work correctly. After they print on the GLCD screen, the screen turns white and stays white.

    Subsequent " GLCDPrint" commands do not work. When I connect an oscilloscope to the SPI SCK (portD.7) and SPI DO (portC.7) ports I see clock and data pulses being sent whenever I press any of the switches.

    Is GCB able to switch back and forth between I2C and SPI commands? If so what am I doing wrong?

    'Chip Settings.
        #chip 18F4550,48
            #config PLLDIV=1, CPUDIV=OSC1_PLL2, OSC=HSPLL_HS, LVP=OFF, MCLRE=ON
                #include <glcd.h>
                    #define HI2C_BAUD_RATE 100
                        #define HI2C_DATA PORTB.0
                            #define HI2C_CLOCK PORTB.1
                                #define MiniTFT_WRITEADDR 188
                                    #define MiniTFT_READADDR 189
                                         #define GLCD_TYPE GLCD_TYPE_ST7735R_160_80
                                            #define ST7735TABCOLOR ST7735_GREENTAB
    
       'Pin mappings for SPI 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              '                      Gray
                    #define GLCD_DO         portC.7              'SPI SDO (MOSI)        Blue
                        #define GLCD_DI         portC.7              'SPI SDI (MISO)  assume bi-directional DO/DI
                            #define GLCD_SCK        portD.7              'SPI SCK               Green
    
                                #define RESET_Pin 28
                                    #define CTRL_Reset 0 
                                        #define DirClr_GPIO 3 
                                            #define PullenSet_GPIO 11 
                                                #define Set_FunctionReg 5 
                                                       #define Module_Base_Address_GPIO 1 
                                                        #define GPIO_BULK 4
                                                            #define Module_Base_Address_AD 9
                                                                   #define Module_function_register_address_AD0 7
                                                                       #define Module_function_register_address_AD1 8
    
    Dir HI2C_DATA in
    Dir HI2C_CLOCK in
    
    HI2CMode Master
    
    'The Mini TFT needs 4.1 VDC for the GLCD good display quality.  PIC needs to run at 5 VDC.
    ' It will work with 3.5 VDC but colors may blur.
    
    'GLCD screen has black background with the below on it
      GLCDCLS
        GLCDRotate ( Landscape )
          GLCDPrint(4, 0, "Great", TFT_YELLOW )
            GLCDPrint(4, 10, "Cow", TFT_GREEN )
                 GLCDPrint(4, 20, "Basic", TFT_WHITE )                ; This Works
      wait 2 s
    
    Do_Again:
    
    'GLCD screen goes white and stays white
    
    'Setup SAM-D09 chip
      HI2CStart
        HI2CSend MiniTFT_WRITEADDR
          HI2CSend Module_Base_Address_GPIO
            HI2CSend DirClr_GPIO
              HI2CSend 211
                HI2CSend 198
                  HI2CSend 207
                    HI2CSend 220
                      HI2CStop
    
      HI2CStart
        HI2CSend MiniTFT_WRITEADDR
          HI2CSend Module_Base_Address_GPIO
            HI2CSend PullenSet_GPIO 
              HI2CSend 211
                HI2CSend 198
                  HI2CSend 207
                    HI2CSend 220
                      HI2CStop
    
      HI2CStart
        HI2CSend MiniTFT_WRITEADDR
          HI2CSend Module_Base_Address_GPIO
            HI2CSend Set_FunctionReg
              HI2CSend 211
                HI2CSend 198
                  HI2CSend 207
                    HI2CSend 220
                      HI2CStop
    
    'Read Switch Data from SAM-D09
        HI2CStart
          HI2CSend MiniTFT_WRITEADDR
            HI2CSend Module_Base_Address_GPIO
              HI2CSend GPIO_BULK
                HI2CRestart
                  HI2CSend MiniTFT_READADDR
                    HI2CReceive Fourth_Byte
                      HI2CReceive Third_Byte
                        HI2CReceive Button_XYS
                          HI2CReceive Button_AB, Nack 
                            HI2CStop
    
    'The below 7 lines do NOT work - there is only a white screen - No printing occurs
            If Button_XYS.1 = 0 then GLCDPrint(4, 10, "Button B", TFT_RED )
              If Button_XYS.2 = 0 then GLCDPrint(4, 0, "Button A", TFT_YELLOW )
                If Button_XYS.3 = 0 then GLCDPrint(4, 60, "SELECT", TFT_RED )
    
            If Button_AB.2 = 0 then GLCDPrint(4, 20, "UP", TFT_RED )
              If Button_AB.3 = 0 then GLCDPrint(4, 30, "LEFT", TFT_RED )
                If Button_AB.4 = 0 then GLCDPrint(4, 40, "DOWN", TFT_RED )
                  If Button_AB.7 = 0 then GLCDPrint(4, 50, "RIGHT", TFT_RED )
    
    
    Goto Do_Again
    
     

    Last edit: Anobium 2019-12-01
  • Anobium

    Anobium - 2019-12-01

    Is this using the new library I provided?

     
  • Anobium

    Anobium - 2019-12-01

    Please put the project in a ZIP. I will delete the .h posts. It will confuse readers.
    I need the ST7735 (two files) also.

     
  • MBB

    MBB - 2019-12-01

    The code

     
  • MBB

    MBB - 2019-12-01

    Here

     
  • Anobium

    Anobium - 2019-12-01

    Have you confirmed the HWI2C works? Output the i2C discover to a serial terminal not the GLCD.

    Did you check I2C discovery? First rule of I2C - is test with I2C discovery.

    There is nothing obvious in the code. So, I would be check oit I2C discovery.

     
  • MBB

    MBB - 2019-12-01

    Yes, HWI2C is working. In my original program there was more code and the "IF" statements were bigger. I changed them in the version I sent you to reduce the confusion. (the version I sent you has the same problem as the longer version)

    Here is what was after the HI2C READ. (All of this worked except the "GLCDPrint" statements.

                          locate 0, 0
                            print Fourth_Byte
                              print " "
                                print ByteToBin(Fourth_Byte)
    
                                  locate 1, 0
                                    print Third_Byte
                                      print " "
                                        print ByteToBin(Third_Byte)
    
                                          locate 2, 0
                                            print Button_XYS
                                              print " "
                                                print ByteToBin(Button_XYS)
    
                                                  locate 3, 0
                                                    print Button_AB
                                                      print " "
                                                        print ByteToBin(Button_AB)
    
    locate 0, 14
    
        If Button_XYS.1 = 0 then
          print "B"
            GLCDPrint(4, 10, "Button B", TFT_RED )
              End If
    
                If Button_XYS.2 = 0 then
                  print "A"
                    GLCDPrint(4, 0, "Button A", TFT_YELLOW )
                      End If
    
                        If Button_XYS.3 = 0 then
                                print "S" ;Push for Select
                                  GLCDPrint(4, 60, "SELECT", TFT_RED )
                                    End If
    
                If Button_AB.2 = 0 then
                      print "U"
                        GLCDPrint(4, 20, "UP", TFT_RED )
                              End If
    
                If Button_AB.3 = 0 then
                  print "L"
                    GLCDPrint(4, 30, "LEFT", TFT_RED )
                      End If
    
                        If Button_AB.4 = 0 then
                          print "D"
                            GLCDPrint(4, 40, "DOWN", TFT_RED )
                              End If
    
                            If Button_AB.7 = 0 then
                              print "R"
                                GLCDPrint(4, 50, "RIGHT", TFT_RED )
                                  End If
    
     
  • MBB

    MBB - 2019-12-02

    I figured out most of this problem. The GLCD_RESET does not go directly to the GLCD. It goes to Pin 7 of the ATSAMD09D14A-MU chip that is on the GLCD board. Pin 7 which is labeled TFT_RST is an active low. I changed the HI2CSend 207 to HI2CSend 206. This puts a low on pin 7.

    Now all the switches cause a read out on the display EXCEPT Button B which causes the display to go white and stay white even when other buttons are pressed.

     
  • Anobium

    Anobium - 2019-12-02

    It sounds like you are getting there.

    :=)

     

Log in to post a comment.