russhughes / gc9a01_mpy

Fast MicroPython driver for GC9A01 display modules written in C
Other
153 stars 31 forks source link

multiple displays: only the last initialized display is working #49

Closed posi74de closed 1 month ago

posi74de commented 1 month ago

I'm trying to run two displays on one SPI bus but only the last initialized display is working. I can run the examples on a single display fine - on both of them. But when I try to both in parallel only the initialzed display is working: when running the test code below only only on tft0 the circle is drawn. When I wap the init() lines the circle is drawn only on tft1 - is there some state in GC9A01 implementation?

import gc9a01
from machine import Pin, SPI

def testcase():
    spi = SPI(2, baudrate=40000000, sck=Pin(18), mosi=Pin(23))

    tft0 = gc9a01.GC9A01(
        spi,
        240,
        240,
        reset=Pin(17, Pin.OUT),
        cs=Pin(5, Pin.OUT),
        dc=Pin(16, Pin.OUT),
        rotation=0,
        options=0,
        buffer_size=0)

    tft1 = gc9a01.GC9A01(
        spi,
        240,
        240,
        reset=Pin(17, Pin.OUT),
        cs=Pin(14, Pin.OUT),
        dc=Pin(16, Pin.OUT),
        rotation=0,
        options=0,
        buffer_size=0)

    tft0.init()
    tft1.init()

    tft0.fill(0)
    tft1.fill(0)

    tft0.circle(119, 119, 119, gc9a01.color565(255, 255, 255))
    tft1.circle(119, 119, 119, gc9a01.color565(255, 255, 255))
posi74de commented 1 month ago

I have done more testing and debugging and found the root cause: the RST line always resets a display independent from the CS line. Each init() call triggers the RST pin which happens twice in my example and so reseting the initialization of the 1st display when calling init() on the 2nd display. By commenting out the reset=... in the 2nd display this can be fixed. As both displays are reset in the init() phase of the 1st display. In my use case this is fine as the displays are resetted once only. In a use case which requires independent resets for both display another pin for the 2nd RST would be required. Instead of using reset=... for only display one could also remove it for displays and handle the reset/RST pin manually by toggling the pin(s) before init(). Closing issue as this is either wrong usage on my end or a hardware issue.