I'm trying to write a basic library to interface with the FT813 chip, and have some awesome UI on my pyboard, but I'm having some issues questions on how to do so.
I'm using the datasheet and the programing guide as a reference.
the initialization sequence for the chip is the following:
- Send te host command "CLKINT" (0x48) to select the internal clock
- Send Host command "ACTIVE" (0x00) to enable the clock to the FT81X. FT81X starts its self diagnosis process and may take up to 300ms. Alternatively, read REG_ID repeatedly until
0x7C is read
But I can not get the chip id to read.
REG_ID should be read by reading 8 bits from the intended address location 302000 (hex)
Writing a command is defined as: When sending a command, the host transmits a 3 byte command. On my case I need to send 0x48 followed by 0x00 twice (page 16 datasheet)
Some information regarding the protocol: Serial data is sent by the most significant bit first, use frequence <11MHz, PCLK polarity is on the rising edge
The code that I have so far is the following:
Code: Select all
import machine import time class FT1X_HAL: def __init__(self, spi, cs): self._spi = spi self._cs = cs def write_cmd(self, data): self._cs.low() self._spi.write(bytearray([data])) self._spi.write(bytearray([0x00])) self._spi.write(bytearray([0x00])) self._cs.high() def read8(self, address): data = bytearray(1) self._cs.low() self._spi.write(bytearray([address])) self._spi.readinto(data) self._cs.high() return data class FT1X(FT1X_HAL): def begin(self): self.write_cmd(0x48) self.write_cmd(0x00) chipid = self.read8(0x302000) # /* Read ID register */ count = 0 while chipid != 0x7C: chipid = self.read8(0x302000) time.sleep(0.01) count += 1 if count > 350: print("timed out") break spi = machine.SPI(2, baudrate=6000000, polarity=0) gpu = FT1X(spi, cs=machine.Pin('Y5')) gpu.begin()