Closed billy521 closed 9 years ago
@Pfannex do you know?
Hi,
please post a link to the display. Are you sure that your wiring is correctly? Do you also changed the hardware board configuration to SPI?
Pf@nne
Hi Pfannex,
The display I am using is http://www.buydisplay.com/default/lcd-5-inch-display-480x272-tft-module-touch-screen-for-mp4-gps
and the RA8875 board I am using is https://www.adafruit.com/product/1590
I have checked the wiring several times and am sure it is correct. The only one not connected is the dc connection gpio 24. I am not sure what this does in SPI mode or where it coonects on the board I am using.
Any help would be much appreciated.
Thanks.
To be sure that your hardware and your wiring is OK, you should test your equipment with the adafruit library.
Alternatively you can write a short python script, only to test the init sequence and draw a colored screen.
If needed, I can search my test sequence.
If you could let me have a test script that would be great. Does the gpio DC pin need to be connected anywhere?
I will not be able to test until Friday as away. On 14 Dec 2014 14:46, "Pfannex" notifications@github.com wrote:
To be sure that your hardware and your wiring is OK, you should test your equipment with the adafruit libary.
Alternatively you can write a short python script, only to test the init sequence and draw a colored screen.
If needed, I can search my test sequence.
Reply to this email directly or view it on GitHub https://github.com/notro/rpi-firmware/issues/12#issuecomment-66915352.
Hi,
some controllers need a dc-pin to switch between (D)ata- and (C)ommand-Mode. The RA8875 will do this by software, so the dc-pin is not needed.
Here is my PYTHON Testcode, I hope that I found a working copy.
#!/usr/bin/env python
###########################################################
# INIT Raspberry Hardware
###########################################################
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) ##USE GPIO names
GPIO.setup(7, GPIO.OUT) #/RESET
GPIO.setup(8, GPIO.OUT) #/CS0
import spidev
import time
import random
import struct
import os
from functools import partial
import pygame
from array import array
from PIL import Image
spi = spidev.SpiDev()
spi.open(0,0) #SPI-Port0 / ChipSelect @ CE0(GPIO8)
spi.max_speed_hz = 20000000
hz = float(spi.max_speed_hz) / 1000000
print "SPI @" , hz , "MHz"
spi.cshigh = False
spi.mode = 3
print "SPI-Mode =" , spi.mode
## CPOL = CLOCK Polaritaet
## CPOL=0 CLK ist inaktiv LOW
## CPOL=1 CLK ist inaktiv HIGH
## CPHA = Datenuebername
## CPHA=0 Datenuebernahme mit erster Flanke, Wechsel mit zweiter Flanke
## CPHA=1 Wechsel mit erster Flanke, Datenuebernahme mit zweiter Flanke
## Mode CPOL CPHA
## 0 0 0 CLK LOW | Datenuebernahme mit steigender Flanke, Wechsel mit fallender Flanke
## 1 0 1 CLK LOW | Wechsel mit steigender Flanke, Datenuebernahme mit fallender Flanke
## 2 1 0 CLK HIGH | Datenuebernahme mit fallender Flanke, Wechsel mit steigender Flanke
## 3 1 1 CLK HIGH | Wechsel mit fallender Flanke, Datenuebernahme mit steigender Flanke
REG88 = 0x1F
REG89 = 0x02
#GPIO.output(8, True)
###########################################################
# SPI-Routines
###########################################################
def WriteCMD(Register):
GPIO.output(8, False)
spi.writebytes([0x80, Register])
GPIO.output(8, True)
time.sleep(0.0001)
def WriteDATA(DataValue):
GPIO.output(8, False)
spi.writebytes([0x00, DataValue])
GPIO.output(8, True)
time.sleep(0.0001)
def WriteREG(Register, DataValue):
WriteCMD(Register)
WriteDATA(DataValue)
#if ReadREG(Register) != DataValue:
#print "DATA ERROR @", "0x%0.2X" % Register, " | ", "0x%0.2X" % ReadREG(Register), " <> ", "0x%0.2X" % DataValue
def ReadREG(Register):
WriteCMD(Register)
GPIO.output(8, False)
spi.writebytes([0x40])
SPI_Read = spi.readbytes(1)
GPIO.output(8, True)
return SPI_Read[0]
def ReadStatus():
GPIO.output(8, False)
spi.writebytes([0xC0])
SPI_Read = spi.readbytes(1)
GPIO.output(8, True)
return SPI_Read[0]
def CheckBusy():
Count = 0
while Count < 1000:
if ReadStatus != 0x80:
break
else:
Count = Count + 1
#print "BusyCount: ", Count
def TEST_SPI_RW():
print "WriteREG"
WriteREG(0x63, 0)
WriteREG(0x64, 0)
WriteREG(0x65, 0)
print "ReadREG = ", ReadREG(0x63)
print "ReadREG = ", ReadREG(0x64)
print "ReadREG = ", ReadREG(0x65)
WriteREG(0x63, 3)
WriteREG(0x64, 4)
WriteREG(0x65, 5)
print "ReadREG = ", ReadREG(0x63)
print "ReadREG = ", ReadREG(0x64)
print "ReadREG = ", ReadREG(0x65)
print "ReadStatus = ", ReadStatus()
###########################################################
# RESET RA8875
###########################################################
def RA8875_Reset():
print "RA8875 Reset"
GPIO.output(7, False)
time.sleep(0.5)
GPIO.output(7, True)
time.sleep(0.3)
###########################################################
# Set Active Window
###########################################################
def ActiveWindow(x1, y1, x2, y2): #ggf. noch genauer maskieren 10Bit/9Bit
WriteREG(0x30 , x1 & 0x00FF) # x1-LOW
WriteREG(0x31 , (x1 & 0xFF00) >> 8) # x1-HIGH
WriteREG(0x32 , y1 & 0x00FF) # y1-LOW
WriteREG(0x33 , (y1 & 0xFF00) >> 8) # y1-HIGH
WriteREG(0x34 , x2 & 0x00FF) # x2-LOW
WriteREG(0x35 , (x2 & 0xFF00) >> 8) # x2-HIGH
WriteREG(0x36 , y2 & 0x00FF) # y2-LOW
WriteREG(0x37 , (y2 & 0xFF00) >> 8) # y2-HIGH
###########################################################
# RA8875 PLLINI
###########################################################
def RA8875_PLL_ini():
print "RA8875 PLL setting"
WriteREG(0x88 , REG88) # PLL setting 800*400 0B|02
WriteREG(0x89 , REG89)
###########################################################
# RA8875 INIT
###########################################################
def RA8875_INIT():
RA8875_Reset()
print "RA8875 INIT"
RA8875_PLL_ini()
CheckBusy()
WriteREG(0x10 , 0x0C) #//SYSR bit[4:3] color bit[2:1]= MPU interface 65K
WriteREG(0x04 , 0x82) #PCLK
#Horizontal set
WriteREG(0x14 , 0x3b) #99 + 1 x 8 =800
WriteREG(0x15 , 0x00)
WriteREG(0x16 , 0x01)
WriteREG(0x17 , 0x00)
WriteREG(0x18 , 0x05)
# Vertical set
WriteREG(0x19 , 0x0f) #479 low
WriteREG(0x1a , 0x01) #479 high
WriteREG(0x1b , 0x02)
WriteREG(0x1c , 0x00)
WriteREG(0x1d , 0x07)
WriteREG(0x1e , 0x00)
WriteREG(0x1f , 0x09)
ActiveWindow(0, 0, 480, 272)
WriteREG(0x8a , 0x81) #1000_0001=0x81 / Enable SysCLK/2
WriteREG(0x8b , 0xFF) #Brightness parameter 0xff-0x00
time.sleep(0.01)
WriteREG(0x01 , 0x80) #display on
ClearScreen(0x1f)
time.sleep(0.001)
###########################################################
# Text Color
###########################################################
def Split_RGB_RED(Color): #RED GREEN BLUE
return Color >> 11 #(1111_1|xxx_xxx|x_xxxx >> 11) = 1_1111 = 0x1F
def Split_RGB_GREEN(Color):
return (Color >> 5) & 0x3F #(1111_1|111_111|x_xxxx >> 5) = (111_11|11_1111 & 11_1111) = 11_1111 = 0x3F
def Split_RGB_BLUE(Color):
return Color & 0x1f #(xxxx_x|xxx_xxx|1_1111 & 1_1111) = 1_1111 = 0x1F
def Color24_Low16(R,G,B):
return (R & 0xF8) | (((G&0xFC) & 0x38) >> 3)
def Color24_High16(R,G,B):
return (((G&0xFC) & 0x07) << 5) | (B&0xF8)
def Text_BGC_RGB(R,G,B): #RED GREEN BLUE
WriteREG(0x60, R) #xxxx_x|xxx_xxx|x_xxxx / in 16-Bit-Mode
WriteREG(0x61, G)
WriteREG(0x62, B)
def Text_FGC_RGB(R,G,B):
WriteREG(0x63, R)
WriteREG(0x64, G)
WriteREG(0x65, B)
def Text_BGC(Color):
Text_BGC_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color))
def Text_FGC(Color):
Text_FGC_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color))
###########################################################
# ClearScreen
###########################################################
def ClearScreen_RGB(R,G,B):
ActiveWindow(0, 0, 480, 272)
Text_BGC_RGB(R,G,B)
WriteREG(0x8e, 0x80)
CheckBusy()
def ClearScreen(Color):
ClearScreen_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color))
def TEST_ClearScreen(ScreensCount,Delay):
count = 0
while (count <= ScreensCount):
ClearScreen(int(random.getrandbits(16)))
time.sleep(Delay)
count = count + 1
###########################################################
# DrawLine
###########################################################
def DrawLine(x1,y1,x2,y2,Color):
WriteREG(0x91, x1 & 0xff) # X_Start [10Bit] 1111_1111 -> LSB
WriteREG(0x92, (x1 >> 8) & 0x03) # xxxx_xx11 -> HSB
WriteREG(0x93, y1 & 0xff) # Y_Start [9Bit] 1111_1111 -> LSB
WriteREG(0x94, (y1 >> 8) & 0x01) # xxxx_xxx1 -> HSB
WriteREG(0x95, x2 & 0xff) # X_Ende [10Bit] 1111_1111 -> LSB
WriteREG(0x96, (x2 >> 8) & 0x03) # xxxx_xx11 -> HSB
WriteREG(0x97, y2 & 0xff) # Y_Ende [9Bit] 1111_1111 -> LSB
WriteREG(0x98, (y2 >> 8) & 0x01) # xxxx_xxx1 -> HSB
Text_FGC(Color)
WriteREG(0x90, 0x80) #DrawLine Start Signal 1000_xxx0
WriteREG(0x90, 0x00)
def TEST_DrawLine(LinesCount):
count = 0
while (count <= LinesCount):
DrawLine(int(random.getrandbits(10)), int(random.getrandbits(9)), int(random.getrandbits(10)), int(random.getrandbits(9)), int(random.getrandbits(16)) )
count = count + 1
count = 0
while (count <= 479):
DrawLine(0,0,799,count,int(random.getrandbits(16)))
count = count + 1
###########################################################
# MemoryWrite
###########################################################
def Set_MemoryWrite_Cursor(x,y):
WriteREG(0x46, x & 0xff) # X [10Bit] 1111_1111 -> LSB
WriteREG(0x47, (x >> 8) & 0x03) # xxxx_xx11 -> HSB
WriteREG(0x48, y & 0xff) # Y [9Bit] 1111_1111 -> LSB
WriteREG(0x49, (y >> 8) & 0x01) # xxxx_xxx1 -> HSB
def load_image_data(filename):
result = array('h')
result.fromstring(pygame.image.load(filename).convert(16).get_buffer().raw)
result.byteswap()
return result.tostring()
def Show_Pic(x1,y1,FileName):
Pic = Image.open(FileName)
biWidth, biHeight = Pic.size
BufferSize = biWidth*biHeight*2
x2 = x1 + biWidth -1
y2 = y1 + biHeight
ActiveWindow(x1,y1,x2,y2)
ActiveWindow(x1,y1,x2,y2)
Set_MemoryWrite_Cursor(x1,y1)
#print "pygame.init() =", pygame.init()
pygame.init()
try:
image_data = load_image_data(FileName)
block_length = 0xfff
blocks = (
image_data[i:i + block_length]
for i in xrange(0, len(image_data), block_length)
)
WriteCMD(0x02)
GPIO.output(8, False)
spi.writebytes([0x00]) #WriteData Byte
spi.max_speed_hz = 20000000
hz = float(spi.max_speed_hz) / 1000000
print "SPI @" , hz , "MHz"
for block in blocks:
spi.writebytes(map(ord, block))
GPIO.output(8, True)
finally:
pygame.quit()
###########################################################
# TouchController
###########################################################
def CTP_ReadStatus():
WriteREG(0x70,0x80)
print ReadREG(0x70)
print ReadREG(0x71)
while 1:
print ReadREG(0x74)
###########################################################
# MAIN
###########################################################
WriteREG(0x46, 0xAA)
print ReadREG(0x46)
WriteREG(0x48, 0x55)
print ReadREG(0x48)
RA8875_INIT()
#TEST_SPI_RW()
#TEST_ClearScreen(100,0.01)
#TEST_DrawLine(100)
#DrawLine(10,10,200,200, 0x1F)
Show_Pic(0,0,"hintern_24_480x272.bmp")
'''
time.sleep(1)
ClearScreen(0)
Show_Pic(0,0,"Test.jpg")
#time.sleep(1)
ClearScreen(0)
Show_Pic(0,0,"1.bmp")
#time.sleep(1)
ClearScreen(0)
Show_Pic(0,0,"2.bmp")
#time.sleep(1)
ClearScreen(0)
Show_Pic(0,0,"3.bmp")
#time.sleep(1)
ClearScreen(0)
Show_Pic(0,0,"4.bmp")
#time.sleep(1)
ClearScreen(0)
Show_Pic(0,0,"5.bmp")
#CTP_ReadStatus()
'''
###########################################################
# END
###########################################################
spi.close()
GPIO.cleanup()
Thanks for that. Will give it a try at the weekend. On 15 Dec 2014 18:41, "Pfannex" notifications@github.com wrote:
Hi,
some controllers need a dc-pin to switch between (D)ata- and (C)ommand-Mode. The RA8875 will do this by software, so the dc-pin is not needed.
Here is my PYTHON Testcode, I hope that I found a working copy.
!/usr/bin/env python
###########################################################
INIT Raspberry Hardware
########################################################### import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) ##USE GPIO names GPIO.setup(7, GPIO.OUT) #/RESET GPIO.setup(8, GPIO.OUT) #/CS0
import spidev import time import random import struct import os from functools import partial import pygame from array import array from PIL import Image
spi = spidev.SpiDev() spi.open(0,0) #SPI-Port0 / ChipSelect @ CE0(GPIO8) spi.max_speed_hz = 20000000 hz = float(spi.max_speed_hz) / 1000000 print "SPI @" , hz , "MHz" spi.cshigh = False spi.mode = 3 print "SPI-Mode =" , spi.mode
CPOL = CLOCK Polaritaet
CPOL=0 CLK ist inaktiv LOW
CPOL=1 CLK ist inaktiv HIGH
CPHA = Datenuebername
CPHA=0 Datenuebernahme mit erster Flanke, Wechsel mit zweiter Flanke
CPHA=1 Wechsel mit erster Flanke, Datenuebernahme mit zweiter Flanke
Mode CPOL CPHA
0 0 0 CLK LOW | Datenuebernahme mit steigender Flanke, Wechsel mit fallender Flanke
1 0 1 CLK LOW | Wechsel mit steigender Flanke, Datenuebernahme mit fallender Flanke
2 1 0 CLK HIGH | Datenuebernahme mit fallender Flanke, Wechsel mit steigender Flanke
3 1 1 CLK HIGH | Wechsel mit fallender Flanke, Datenuebernahme mit steigender Flanke
REG88 = 0x1F REG89 = 0x02
GPIO.output(8, True)
###########################################################
SPI-Routines
########################################################### def WriteCMD(Register): GPIO.output(8, False) spi.writebytes([0x80, Register]) GPIO.output(8, True) time.sleep(0.0001) def WriteDATA(DataValue): GPIO.output(8, False) spi.writebytes([0x00, DataValue]) GPIO.output(8, True) time.sleep(0.0001) def WriteREG(Register, DataValue): WriteCMD(Register) WriteDATA(DataValue)
if ReadREG(Register) != DataValue:
#print "DATA ERROR @", "0x%0.2X" % Register, " | ", "0x%0.2X" % ReadREG(Register), " <> ", "0x%0.2X" % DataValue
def ReadREG(Register): WriteCMD(Register) GPIO.output(8, False) spi.writebytes([0x40]) SPI_Read = spi.readbytes(1) GPIO.output(8, True) return SPI_Read[0] def ReadStatus(): GPIO.output(8, False) spi.writebytes([0xC0]) SPI_Read = spi.readbytes(1) GPIO.output(8, True) return SPI_Read[0]
def CheckBusy(): Count = 0 while Count < 1000: if ReadStatus != 0x80: break else: Count = Count + 1
print "BusyCount: ", Count
def TEST_SPI_RW(): print "WriteREG" WriteREG(0x63, 0) WriteREG(0x64, 0) WriteREG(0x65, 0) print "ReadREG = ", ReadREG(0x63) print "ReadREG = ", ReadREG(0x64) print "ReadREG = ", ReadREG(0x65)
WriteREG(0x63, 3) WriteREG(0x64, 4) WriteREG(0x65, 5) print "ReadREG = ", ReadREG(0x63) print "ReadREG = ", ReadREG(0x64) print "ReadREG = ", ReadREG(0x65) print "ReadStatus = ", ReadStatus()
###########################################################
RESET RA8875
###########################################################
def RA8875_Reset(): print "RA8875 Reset" GPIO.output(7, False) time.sleep(0.5) GPIO.output(7, True) time.sleep(0.3)
###########################################################
Set Active Window
########################################################### def ActiveWindow(x1, y1, x2, y2): #ggf. noch genauer maskieren 10Bit/9Bit WriteREG(0x30 , x1 & 0x00FF) # x1-LOW WriteREG(0x31 , (x1 & 0xFF00) >> 8) # x1-HIGH WriteREG(0x32 , y1 & 0x00FF) # y1-LOW WriteREG(0x33 , (y1 & 0xFF00) >> 8) # y1-HIGH WriteREG(0x34 , x2 & 0x00FF) # x2-LOW WriteREG(0x35 , (x2 & 0xFF00) >> 8) # x2-HIGH WriteREG(0x36 , y2 & 0x00FF) # y2-LOW WriteREG(0x37 , (y2 & 0xFF00) >> 8) # y2-HIGH
###########################################################
RA8875 PLLINI
########################################################### def RA8875_PLL_ini(): print "RA8875 PLL setting"
WriteREG(0x88 , REG88) # PLL setting 800*400 0B|02 WriteREG(0x89 , REG89)
###########################################################
RA8875 INIT
########################################################### def RA8875_INIT(): RA8875_Reset() print "RA8875 INIT" RA8875_PLL_ini() CheckBusy()
WriteREG(0x10 , 0x0C) #//SYSR bit[4:3] color bit[2:1]= MPU interface 65K WriteREG(0x04 , 0x82) #PCLK #Horizontal set WriteREG(0x14 , 0x3b) #99 + 1 x 8 =800 WriteREG(0x15 , 0x00) WriteREG(0x16 , 0x01) WriteREG(0x17 , 0x00) WriteREG(0x18 , 0x05) # Vertical set WriteREG(0x19 , 0x0f) #479 low WriteREG(0x1a , 0x01) #479 high WriteREG(0x1b , 0x02) WriteREG(0x1c , 0x00) WriteREG(0x1d , 0x07) WriteREG(0x1e , 0x00) WriteREG(0x1f , 0x09) ActiveWindow(0, 0, 480, 272) WriteREG(0x8a , 0x81) #1000_0001=0x81 / Enable SysCLK/2 WriteREG(0x8b , 0xFF) #Brightness parameter 0xff-0x00 time.sleep(0.01) WriteREG(0x01 , 0x80) #display on ClearScreen(0x1f) time.sleep(0.001)
###########################################################
Text Color
########################################################### def Split_RGB_RED(Color): #RED GREEN BLUE return Color >> 11 #(1111_1|xxx_xxx|x_xxxx >> 11) = 1_1111 = 0x1F def Split_RGB_GREEN(Color): return (Color >> 5) & 0x3F #(1111_1|111_111|x_xxxx >> 5) = (111_11|11_1111 & 11_1111) = 11_1111 = 0x3F def Split_RGB_BLUE(Color): return Color & 0x1f #(xxxx_x|xxx_xxx|1_1111 & 1_1111) = 1_1111 = 0x1F
def Color24_Low16(R,G,B): return (R & 0xF8) | (((G&0xFC) & 0x38) >> 3) def Color24_High16(R,G,B): return (((G&0xFC) & 0x07) << 5) | (B&0xF8)
def Text_BGC_RGB(R,G,B): #RED GREEN BLUE WriteREG(0x60, R) #xxxx_x|xxx_xxx|x_xxxx / in 16-Bit-Mode WriteREG(0x61, G) WriteREG(0x62, B) def Text_FGC_RGB(R,G,B): WriteREG(0x63, R) WriteREG(0x64, G) WriteREG(0x65, B)
def Text_BGC(Color): Text_BGC_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color)) def Text_FGC(Color): Text_FGC_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color))
###########################################################
ClearScreen
########################################################### def ClearScreen_RGB(R,G,B): ActiveWindow(0, 0, 480, 272) Text_BGC_RGB(R,G,B) WriteREG(0x8e, 0x80) CheckBusy() def ClearScreen(Color): ClearScreen_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color))
def TEST_ClearScreen(ScreensCount,Delay): count = 0 while (count <= ScreensCount): ClearScreen(int(random.getrandbits(16))) time.sleep(Delay) count = count + 1
###########################################################
DrawLine
########################################################### def DrawLine(x1,y1,x2,y2,Color):
WriteREG(0x91, x1 & 0xff) # X_Start [10Bit] 1111_1111 -> LSB WriteREG(0x92, (x1 >> 8) & 0x03) # xxxx_xx11 -> HSB WriteREG(0x93, y1 & 0xff) # Y_Start [9Bit] 1111_1111 -> LSB WriteREG(0x94, (y1 >> 8) & 0x01) # xxxx_xxx1 -> HSB WriteREG(0x95, x2 & 0xff) # X_Ende [10Bit] 1111_1111 -> LSB WriteREG(0x96, (x2 >> 8) & 0x03) # xxxx_xx11 -> HSB WriteREG(0x97, y2 & 0xff) # Y_Ende [9Bit] 1111_1111 -> LSB WriteREG(0x98, (y2 >> 8) & 0x01) # xxxx_xxx1 -> HSB Text_FGC(Color) WriteREG(0x90, 0x80) #DrawLine Start Signal 1000_xxx0 WriteREG(0x90, 0x00)
def TEST_DrawLine(LinesCount): count = 0 while (count <= LinesCount): DrawLine(int(random.getrandbits(10)), int(random.getrandbits(9)), int(random.getrandbits(10)), int(random.getrandbits(9)), int(random.getrandbits(16)) ) count = count + 1 count = 0 while (count <= 479): DrawLine(0,0,799,count,int(random.getrandbits(16))) count = count + 1
###########################################################
MemoryWrite
########################################################### def Set_MemoryWrite_Cursor(x,y): WriteREG(0x46, x & 0xff) # X [10Bit] 1111_1111 -> LSB WriteREG(0x47, (x >> 8) & 0x03) # xxxx_xx11 -> HSB WriteREG(0x48, y & 0xff) # Y [9Bit] 1111_1111 -> LSB WriteREG(0x49, (y >> 8) & 0x01) # xxxx_xxx1 -> HSB
def load_image_data(filename): result = array('h') result.fromstring(pygame.image.load(filename).convert(16).get_buffer().raw) result.byteswap() return result.tostring()
def Show_Pic(x1,y1,FileName):
Pic = Image.open(FileName) biWidth, biHeight = Pic.size BufferSize = biWidth*biHeight*2 x2 = x1 + biWidth -1 y2 = y1 + biHeight ActiveWindow(x1,y1,x2,y2) ActiveWindow(x1,y1,x2,y2) Set_MemoryWrite_Cursor(x1,y1) #print "pygame.init() =", pygame.init() pygame.init() try: image_data = load_image_data(FileName) block_length = 0xfff blocks = ( image_data[i:i + block_length] for i in xrange(0, len(image_data), block_length) ) WriteCMD(0x02) GPIO.output(8, False) spi.writebytes([0x00]) #WriteData Byte spi.max_speed_hz = 20000000 hz = float(spi.max_speed_hz) / 1000000 print "SPI @" , hz , "MHz" for block in blocks: spi.writebytes(map(ord, block)) GPIO.output(8, True) finally: pygame.quit()
###########################################################
TouchController
###########################################################
def CTP_ReadStatus(): WriteREG(0x70,0x80) print ReadREG(0x70) print ReadREG(0x71) while 1: print ReadREG(0x74)
###########################################################
MAIN
###########################################################
WriteREG(0x46, 0xAA) print ReadREG(0x46) WriteREG(0x48, 0x55) print ReadREG(0x48)
RA8875_INIT()
TEST_SPI_RW()
TEST_ClearScreen(100,0.01)
TEST_DrawLine(100)
DrawLine(10,10,200,200, 0x1F)
Show_Pic(0,0,"hintern_24_480x272.bmp")
''' time.sleep(1) ClearScreen(0) Show_Pic(0,0,"Test.jpg")
time.sleep(1)
ClearScreen(0) Show_Pic(0,0,"1.bmp")
time.sleep(1)
ClearScreen(0) Show_Pic(0,0,"2.bmp")
time.sleep(1)
ClearScreen(0) Show_Pic(0,0,"3.bmp")
time.sleep(1)
ClearScreen(0) Show_Pic(0,0,"4.bmp")
time.sleep(1)
ClearScreen(0) Show_Pic(0,0,"5.bmp")
CTP_ReadStatus()
'''
###########################################################
END
###########################################################
spi.close() GPIO.cleanup()
Reply to this email directly or view it on GitHub https://github.com/notro/rpi-firmware/issues/12#issuecomment-67042739.
You also can try to slow down the RA8875 internal CLOCK-speed. Have a look into the RA8875 manual....
Hi,
Tried the script and cannot get anything to work. Registers of your test script keep reading 255 all the time.
Can I check that I am using the correct pins for my Raspberry B+
Pin 19 - MOSI Pin 21 - MISO Pin 22 - RESET Pin 23 - CLK Pin 24 - CE0
Regards
Billy
-----Original Message-----From: Pfannex notifications@github.com Reply-to: notro/rpi-firmware <reply +00688baa3af905fa7d5af70fe715441e4553edb63021d46792cf0000000110a6ed6892a169ce0316b658@reply.github.com> To: notro/rpi-firmware rpi-firmware@noreply.github.com Cc: billy521 billy.robson.me@gmail.com Subject: Re: [rpi-firmware] RA8875 with er_tft050_02 display (#12) Date: Mon, 15 Dec 2014 10:41:44 -0800
Hi,
some controllers need a dc-pin to switch between (D)ata- and (C)ommand-Mode. The RA8875 will do this by software, so the dc-pin is not needed.
Here is my PYTHON Testcode, I hope that I found a working copy.
###########################################################
########################################################### import RPi.GPIO as GPIO GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) ##USE GPIO names GPIO.setup(7, GPIO.OUT) #/RESET GPIO.setup(8, GPIO.OUT) #/CS0
import spidev import time import random import struct import os from functools import partial import pygame from array import array from PIL import Image
spi = spidev.SpiDev() spi.open(0,0) #SPI-Port0 / ChipSelect @ CE0(GPIO8) spi.max_speed_hz = 20000000 hz = float(spi.max_speed_hz) / 1000000 print "SPI @" , hz , "MHz" spi.cshigh = False spi.mode = 3 print "SPI-Mode =" , spi.mode
REG88 = 0x1F REG89 = 0x02
###########################################################
########################################################### def WriteCMD(Register): GPIO.output(8, False) spi.writebytes([0x80, Register]) GPIO.output(8, True) time.sleep(0.0001) def WriteDATA(DataValue): GPIO.output(8, False) spi.writebytes([0x00, DataValue]) GPIO.output(8, True) time.sleep(0.0001) def WriteREG(Register, DataValue): WriteCMD(Register) WriteDATA(DataValue)
#print "DATA ERROR @", "0x%0.2X" % Register, " | ", "0x%0.2X" % ReadREG(Register), " <> ", "0x%0.2X" % DataValue
def ReadREG(Register): WriteCMD(Register) GPIO.output(8, False) spi.writebytes([0x40]) SPI_Read = spi.readbytes(1) GPIO.output(8, True) return SPI_Read[0] def ReadStatus(): GPIO.output(8, False) spi.writebytes([0xC0]) SPI_Read = spi.readbytes(1) GPIO.output(8, True) return SPI_Read[0]
def CheckBusy(): Count = 0 while Count < 1000: if ReadStatus != 0x80: break else: Count = Count + 1
def TEST_SPI_RW():
print "WriteREG"
WriteREG(0x63, 0)
WriteREG(0x64, 0)
WriteREG(0x65, 0)
print "ReadREG = ", ReadREG(0x63)
print "ReadREG = ", ReadREG(0x64)
print "ReadREG = ", ReadREG(0x65)
WriteREG(0x63, 3)
WriteREG(0x64, 4)
WriteREG(0x65, 5)
print "ReadREG = ", ReadREG(0x63)
print "ReadREG = ", ReadREG(0x64)
print "ReadREG = ", ReadREG(0x65)
print "ReadStatus = ", ReadStatus()
###########################################################
###########################################################
def RA8875_Reset(): print "RA8875 Reset" GPIO.output(7, False) time.sleep(0.5) GPIO.output(7, True) time.sleep(0.3)
###########################################################
########################################################### def ActiveWindow(x1, y1, x2, y2): #ggf. noch genauer maskieren 10Bit/9Bit WriteREG(0x30 , x1 & 0x00FF) # x1-LOW WriteREG(0x31 , (x1 & 0xFF00) >> 8) # x1-HIGH WriteREG(0x32 , y1 & 0x00FF) # y1-LOW WriteREG(0x33 , (y1 & 0xFF00) >> 8) # y1-HIGH WriteREG(0x34 , x2 & 0x00FF) # x2-LOW WriteREG(0x35 , (x2 & 0xFF00) >> 8) # x2-HIGH WriteREG(0x36 , y2 & 0x00FF) # y2-LOW WriteREG(0x37 , (y2 & 0xFF00) >> 8) # y2-HIGH
###########################################################
########################################################### def RA8875_PLL_ini(): print "RA8875 PLL setting"
WriteREG(0x88 , REG88) # PLL setting 800*400 0B|02
WriteREG(0x89 , REG89)
###########################################################
########################################################### def RA8875_INIT(): RA8875_Reset() print "RA8875 INIT" RA8875_PLL_ini() CheckBusy()
WriteREG(0x10 , 0x0C) #//SYSR bit[4:3] color bit[2:1]= MPU interface 65K
WriteREG(0x04 , 0x82) #PCLK
#Horizontal set
WriteREG(0x14 , 0x3b) #99 + 1 x 8 =800
WriteREG(0x15 , 0x00)
WriteREG(0x16 , 0x01)
WriteREG(0x17 , 0x00)
WriteREG(0x18 , 0x05)
# Vertical set
WriteREG(0x19 , 0x0f) #479 low
WriteREG(0x1a , 0x01) #479 high
WriteREG(0x1b , 0x02)
WriteREG(0x1c , 0x00)
WriteREG(0x1d , 0x07)
WriteREG(0x1e , 0x00)
WriteREG(0x1f , 0x09)
ActiveWindow(0, 0, 480, 272)
WriteREG(0x8a , 0x81) #1000_0001=0x81 / Enable SysCLK/2
WriteREG(0x8b , 0xFF) #Brightness parameter 0xff-0x00
time.sleep(0.01)
WriteREG(0x01 , 0x80) #display on
ClearScreen(0x1f)
time.sleep(0.001)
###########################################################
########################################################### def Split_RGB_RED(Color): #RED GREEN BLUE return Color >> 11 #(1111_1|xxx_xxx|x_xxxx >> 11) = 1_1111 = 0x1F def Split_RGB_GREEN(Color): return (Color >> 5) & 0x3F #(1111_1|111_111|x_xxxx >> 5) = (111_11|11_1111 & 11_1111) = 11_1111 = 0x3F def Split_RGB_BLUE(Color): return Color & 0x1f #(xxxx_x|xxx_xxx|1_1111 & 1_1111) = 1_1111 = 0x1F
def Color24_Low16(R,G,B): return (R & 0xF8) | (((G&0xFC) & 0x38) >> 3) def Color24_High16(R,G,B): return (((G&0xFC) & 0x07) << 5) | (B&0xF8)
def Text_BGC_RGB(R,G,B): #RED GREEN BLUE
WriteREG(0x60, R) #xxxx_x|xxx_xxx|x_xxxx / in 16-Bit-Mode
WriteREG(0x61, G)
WriteREG(0x62, B)
def Text_FGC_RGB(R,G,B):
WriteREG(0x63, R)
WriteREG(0x64, G)
WriteREG(0x65, B)
def Text_BGC(Color): Text_BGC_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color)) def Text_FGC(Color): Text_FGC_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color))
###########################################################
########################################################### def ClearScreen_RGB(R,G,B): ActiveWindow(0, 0, 480, 272) Text_BGC_RGB(R,G,B) WriteREG(0x8e, 0x80) CheckBusy() def ClearScreen(Color): ClearScreen_RGB(Split_RGB_RED(Color),Split_RGB_GREEN(Color),Split_RGB_BLUE(Color))
def TEST_ClearScreen(ScreensCount,Delay): count = 0 while (count <= ScreensCount): ClearScreen(int(random.getrandbits(16))) time.sleep(Delay) count = count + 1
###########################################################
########################################################### def DrawLine(x1,y1,x2,y2,Color):
WriteREG(0x91, x1 & 0xff) # X_Start [10Bit] 1111_1111 -> LSB
WriteREG(0x92, (x1 >> 8) & 0x03) # xxxx_xx11 -> HSB
WriteREG(0x93, y1 & 0xff) # Y_Start [9Bit] 1111_1111 -> LSB
WriteREG(0x94, (y1 >> 8) & 0x01) # xxxx_xxx1 -> HSB
WriteREG(0x95, x2 & 0xff) # X_Ende [10Bit] 1111_1111 -> LSB
WriteREG(0x96, (x2 >> 8) & 0x03) # xxxx_xx11 -> HSB
WriteREG(0x97, y2 & 0xff) # Y_Ende [9Bit] 1111_1111 -> LSB
WriteREG(0x98, (y2 >> 8) & 0x01) # xxxx_xxx1 -> HSB
Text_FGC(Color)
WriteREG(0x90, 0x80) #DrawLine Start Signal 1000_xxx0
WriteREG(0x90, 0x00)
def TEST_DrawLine(LinesCount):
count = 0
while (count <= LinesCount):
DrawLine(int(random.getrandbits(10)), int(random.getrandbits(9)), int(random.getrandbits(10)), int(random.getrandbits(9)), int(random.getrandbits(16)) )
count = count + 1
count = 0
while (count <= 479):
DrawLine(0,0,799,count,int(random.getrandbits(16)))
count = count + 1
###########################################################
########################################################### def Set_MemoryWrite_Cursor(x,y): WriteREG(0x46, x & 0xff) # X [10Bit] 1111_1111 -> LSB WriteREG(0x47, (x >> 8) & 0x03) # xxxx_xx11 -> HSB WriteREG(0x48, y & 0xff) # Y [9Bit] 1111_1111 -> LSB WriteREG(0x49, (y >> 8) & 0x01) # xxxx_xxx1 -> HSB
def load_image_data(filename): result = array('h') result.fromstring(pygame.image.load(filename).convert(16).get_buffer().raw) result.byteswap() return result.tostring()
def Show_Pic(x1,y1,FileName):
Pic = Image.open(FileName)
biWidth, biHeight = Pic.size
BufferSize = biWidth*biHeight*2
x2 = x1 + biWidth -1
y2 = y1 + biHeight
ActiveWindow(x1,y1,x2,y2)
ActiveWindow(x1,y1,x2,y2)
Set_MemoryWrite_Cursor(x1,y1)
#print "pygame.init() =", pygame.init()
pygame.init()
try:
image_data = load_image_data(FileName)
block_length = 0xfff
blocks = (
image_data[i:i + block_length]
for i in xrange(0, len(image_data), block_length)
)
WriteCMD(0x02)
GPIO.output(8, False)
spi.writebytes([0x00]) #WriteData Byte
spi.max_speed_hz = 20000000
hz = float(spi.max_speed_hz) / 1000000
print "SPI @" , hz , "MHz"
for block in blocks:
spi.writebytes(map(ord, block))
GPIO.output(8, True)
finally:
pygame.quit()
###########################################################
###########################################################
def CTP_ReadStatus(): WriteREG(0x70,0x80) print ReadREG(0x70) print ReadREG(0x71) while 1: print ReadREG(0x74)
###########################################################
###########################################################
WriteREG(0x46, 0xAA) print ReadREG(0x46) WriteREG(0x48, 0x55) print ReadREG(0x48)
RA8875_INIT()
Show_Pic(0,0,"hintern_24_480x272.bmp")
''' time.sleep(1) ClearScreen(0) Show_Pic(0,0,"Test.jpg")
ClearScreen(0) Show_Pic(0,0,"1.bmp")
ClearScreen(0) Show_Pic(0,0,"2.bmp")
ClearScreen(0) Show_Pic(0,0,"3.bmp")
ClearScreen(0) Show_Pic(0,0,"4.bmp")
ClearScreen(0) Show_Pic(0,0,"5.bmp")
'''
###########################################################
###########################################################
spi.close() GPIO.cleanup()
— Reply to this email directly or view it on GitHub.
Hi, do you use a logic analyzer?
Hi, no haven't got any test equipment at all. Are the connections I'm using correct. On 19 Dec 2014 18:26, "Pfannex" notifications@github.com wrote:
Hi, do you use a logic analyzer?
Reply to this email directly or view it on GitHub https://github.com/notro/rpi-firmware/issues/12#issuecomment-67676595.
I youse the model B, do you change the reset and CS Pin in the program?
I haven't changed those pins. Will try that tomorrow. Thanks. On 19 Dec 2014 20:45, "Pfannex" notifications@github.com wrote:
I youse the model B, do you change the reset and CS Pin in the program?
Reply to this email directly or view it on GitHub https://github.com/notro/rpi-firmware/issues/12#issuecomment-67694760.
Closing issue since there has been no activity for more than 2 months. Reopen if needed.
I already had the er_tft050_2 display so bought the RA8875 break out module to drive it.
I assumed that it would work with the er_tftm050_2 driver in fbtft, but the display only goes white with the backlight on.
Will it work with that driver?
The only gpio not connected is dc, not sure where, if any, this would go on the RA8875 module.
Anyone help. Thank you