Tyler,
First thing, make sure you are using the same controller. If you are, it's most likely my code. I have had some bugs so. I changed hardware version, but the display is wired the same right now.
CON
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000
''PINS FOR LCD
RS = 16 ''PINS FOR CS - TO KEEP FROM FLOATING
LCD_WR = 17 ''and sd card defs
DEV_SD_CLK = 18
DEV_SD_DI = 19
DEV_SD_DO = 20
DEV_SPI_EN = 21
DEV_SPI_ADD0 = 22
DEV_SPI_ADD1 = 23
DEV_SPI_ADD_LE = 24
DEV_SPI_LCD_RES = 0
DEV_SPI_SDC_CS = 1
DEV_SPI_TSC_CS = 2
DEV_SPI_EXT_CS = 3
DEV_SPI_EXT_POT_CS = 0
DEV_SPI_EXT_SW_CS = %100
''LCD REGISTERS
REG_OSCILLATOR = $0000 ''Oscillator (R00h) (POR = 0000h)
REG_DRIVEROUTPUTCONTROL = $0001 ''Driver Output Control (R01h) (POR = 2B3Fh)
REG_LCDDRIVINGWAVFORM = $0002 ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)
REG_POWERCONTROL1 = $0003 '' (R03H)
REG_DISPLAYCONTROL = $0007 ''Display Control (R07h) (POR = 0000h)
REG_FRAMECYCLECONTROL = $000B ''Frame Cycle Control (R0Bh) (POR = 5308h)D308 BY DATASHEET
REG_POWERCONTROL2 = $000C '' (R0Ch) (POR = 0004)
REG_POWERCONTROL3 = $000D ''
REG_POWERCONTROL4 = $000E ''
REG_GATESCANPOSITION = $000F ''Gate Scan Position (R0Fh) (POR = 0000h)
REG_SLEEPMODE = $0010 ''Sleep mode (R10h) (POR = 0001h)
REG_ENTRYMODE = $0011 ''Entry Mode (R11h) (POR = 6830h)
REG_HPORCH = $0016 '' (R16h) (POR = EF1Ch)
REG_VPORCH = $0017 '' (R17h) (POR = 0003h)
REG_POWERCONTROL5 = $001E ''
REG_RAMDATAWRITE = $0022 ''
REG_RAMWRITEDATAMASK1 = $0023 '' (R23h) (POR = 0000h)
REG_RAMWRITEDATAMASK2 = $0024 '' (R24h) (POR = 0000h)
REG_VERTICALSCROLCONTROL1 = $0041 '' (R41h) (POR = 0000h)
REG_VERTICALSCROLCONTROL2 = $0042 '' (R42h) (POR = 0000h)
REG_HORIZONTALRAMADDRESSPOS = $0044 '' (R44h) (POR = EF00h)
REG_VERTICALRAMADDRESSSTART = $0045 '' (R45h) (POR = 0000h)
REG_VERTICALRAMADDRESSEND = $0046 '' (R46h) (POR = 013Fh)
REG_FIRSTWINDOWSTART = $0048 '' (R48h) (POR = 0000h)
REG_FIRSTWINDOWEND = $0049 '' (R49h) (POR = 013Fh)
REG_SECONDWINDOWSTART = $004A '' (R4Ah) (POR = 0000h)
REG_SECONDWINDOWEND = $004B '' (R4Bh) (POR = 013Fh)
REG_SETGDDRXADDRESSCOUNTER = $004E '' (R4Eh) (POR = 0000h)
REG_SETGDDRYADDRESSCOUNTER = $004F '' (R4Fh) (POR = 0000h)
FONT_ROM_ADDRESS = $8000
BGCOLOR = $0fff
TXTCOLOR = $0000
OBJ
'fat : "SD3.01_FATEngine.spin" ' thanks to Kye
spi : "SPI_ASM" ' thanks to Beau
wait : "timing" ' thanks to parallax
pst : "Parallax Serial Terminal"
VAR
long ActiveColor, WindowX1, WindowX2, WindowY1, WindowY2
PUB Bootstrap
EnableDisplayPins
OUTA[DEV_SPI_EN] := 0
OUTA[DEV_SPI_ADD_LE] := 0
'OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := 3
'SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 4,8,%100)
'wait.pause1s(100)
Init_SSD1289
'ClearScreen
PST_Init
SPI.start(5,0)
'Init_SD
Repeat
Test_Main
PUB Init_SD | pe ''broken?
PST.CLEAR
pst.Str(string("Testing for SD card")) ' helpful message if card is out, better than just a blank screen
pst.newline
'pst.dec(fat.FATEngineStart(20,18,19,22,-1, 1, 1, 1,-1))
pst.newline
'pst.str(string("sucess"))
pst.newline
pst.str(string("mounting fat"))
pst.newline
'pst.DEC(fat.partitionError)
'fat.mountPartition(0) ' mount the sd card
wait.pause1s(5)
pst.str(string("mounting fat done"))
pst.newline
PUB TestTS | yval, xval,x,y
Enable_Touch ''Old format was OUTA[TS_CS] := 0 ' enable the touch screen
'SPI.start(3,0) ' delay,state Already running?
'Shiftout = data,clock,mode,bits,value
'shiftin = data,clock,mode,bits
'SPI read S, A2, A1, A0, Mode, SER, PD1, PD0
' 1 0 0 1 1 0 0 0
' MSB first
' 001 is X
' 101 is Y
repeat
pst.clear
SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1101_0000) ' reads x from 500 to 3700 (off < 500 )
xval := SPI.SHIFTIN(DEV_SD_DO, DEV_SD_CLK,2, 12)
SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1001_0000) ' reads y from 400 to 3800 (off > 3800 )
yval := SPI.SHIFTIN(DEV_SD_DO,DEV_SD_CLK,2, 12)
pst.Dec(xval)
pst.newline
pst.Dec(yval)
wait.pause1ms(10)
Disable_Touch ''Old format was OUTA[TS_CS] := 1 ' disable the touch screen
PUB Init_SSD1289 ''Init Display
EnableDisplayPins ''enable pins 0 to 15
WriteHigh
LCD_Reset ''reset screen
wait.pause1ms(5)
LCD_Reset ''then init screen
wait.pause1ms(5)
Lcd_Write_Com (REG_DISPLAYCONTROL) ''Display Control (R07h) (POR = 0000h)
Lcd_Write_Data($0021) ''GON = 1 DTE = 0 D[1:0] = 01
Lcd_Write_Com (REG_OSCILLATOR) ''Oscillator (R00h) (POR = 0000h)
Lcd_Write_Data($0001) ''Turn on oscillator
Lcd_Write_Com (REG_DISPLAYCONTROL) ''Display Control (R07h) (POR = 0000h)
Lcd_Write_Data($0023) ''GON = 1 DTE = 0 D[1:0] = 11
Lcd_Write_Com (REG_SLEEPMODE) ''Sleep mode (R10h) (POR = 0001h)
Lcd_Write_Data($0000) '' ''exit sleep mode
Lcd_Write_Com (REG_DISPLAYCONTROL) ''Display Control (R07h) (POR = 0000h)
Lcd_Write_Data($0033) ''GON = 1 DTE = 1 D[1:0] = 11
Lcd_Write_Com (REG_ENTRYMODE) ''Entry Mode (R11h) (POR = 6830h)
Lcd_Write_Data($6838) ''
Lcd_Write_Com (REG_LCDDRIVINGWAVFORM) ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)($1000)
Lcd_Write_Data($1000) '' ''
Lcd_Write_Com (REG_GATESCANPOSITION) ''Gate Scan Position (R0Fh) (POR = 0000h) ($0000)
Lcd_Write_Data($0000) '' '' ''
Lcd_Write_Com (REG_DRIVEROUTPUTCONTROL) ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) 433f ($633F)
Lcd_Write_Data($6B3F) '' ''
Lcd_Write_Com (REG_FRAMECYCLECONTROL) ''Frame Cycle Control (R0Bh) (POR = 5308h) ($5308)
Lcd_Write_Data($5308) '' '
Lcd_Write_Com (REG_DISPLAYCONTROL) ''Display Control (R07h) (POR = 0000h) ($0033)
Lcd_Write_Data($0033) ''GON = 1 DTE = 1 D[1:0] = 11
PUB PST_Init | PstCog ''Starts Parallax Serial Terminal for debugging.
PstCog := (pst.Start(115200) -1) '' returns the cog pst started in
pst.Str(String("Parallax Serial Terminal started in cog ")) '' talk to human
pst.Dec(PstCog) '' displays cog on PST ''
wait.pause1s(5) '' wait a bit
PUB Test_Main | char, tmp
pst.Clear
pst.Str(String("Function Test Main Menu"))
pst.NewLine
pst.Str(String("1 for Font Test 1"))
pst.NewLine
pst.Str(String("2 for Color Test"))
pst.Newline
pst.Str(String("3 for Hello World"))
pst.NewLine
pst.Str(String("4 for FreeRun Color Test"))
pst.NewLine
pst.Str(String("5 for Sd Test"))
pst.NewLine
pst.Str(String("6 for TS Test"))
pst.NewLine
pst.Str(String("7 for External SPI Test"))
pst.NewLine
char := pst.DecIn
if (char == 1)
FontTest
elseif (char == 2)
pst.newline
pst.str(string("Select Hex Color 0000 -FFFF"))
pst.NewLine
char := pst.hexin
ColorTest(char)
elseif (char == 3)
HelloWorld
elseif (char == 4)
ColorTestFreeRUN
elseif (char == 5)
Init_SD
elseif (char == 6)
TestTS
elseif (char == 7)
Spi_Test
'pst.
return
PUB Spi_Test | char, address, data
repeat
pst.Clear
pst.Str(String("1 for pot test"))
Pst.NewLine
Pst.Str(String("2 for switch test"))
Pst.NewLine
char := pst.DecIn
if (char == 1)
Pst.Clear
Pst.Str(String("Input Pot Address 0 - 3"))
Pst.NewLine
address := Pst.DecIn
Pst.NewLine
Pst.Str(String("Input Pot Value"))
Pst.Newline
data := Pst.DecIn
address <<= 8
data := data + address
wait.pause1s(1)
Set_Spi_Ext_Address(0)
SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 11, data)
StrobeCS
Disable_Spi_Ext
PUB ColorTestFreeRUN | color
repeat
repeat color from $0000 to $FFFF step 1
ColorTest(Color)
PUB ColorTest(Color) | idxr, idxc
SetWindow(0, 0, 239, 319)
SetGAddress(0,0)
repeat idxr from 0 to 319
repeat idxc from 0 to 239
Lcd_Write_Com(REG_RAMDATAWRITE)
Lcd_Write_Data(Color)
return
PUB HelloWorld | char, row, col
PropFont_WriteCr(72, 0, 0*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(101, 0, 1*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(108, 0, 2*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(108, 0, 3*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(111, 0, 4*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(32, 0, 5*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(87, 0, 6*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(111, 0, 7*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(114, 0, 8*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(108, 0, 9*16, 0, 0, BGCOLOR, TXTCOLOR)
PropFont_WriteCr(100, 0, 10*16, 0, 0, BGCOLOR, TXTCOLOR)
PUB FontTest | tmp, char, row, col, rbor, cbor
pst.Clear
pst.Str(String("Select character"))
pst.newline
char := pst.DecIn
pst.Str(String("Select Row"))
pst.newline
row := pst.DecIn
pst.Str(String("Select Col"))
pst.newline
col := pst.DecIn
pst.Str(String("Select RBor"))
pst.newline
rbor := pst.DecIn
pst.Str(String("Select CBor"))
pst.newline
cbor := pst.DecIn
PropFont_WriteCr(char, row, col, rbor, cbor, BGCOLOR, TXTCOLOR)
return
PUB ClearScreen | idxr, idxc
Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER)
Lcd_Write_Data(0)
Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER)
Lcd_Write_Data(0)
repeat idxr from 0 to 76800
Lcd_Write_Com(REG_RAMDATAWRITE)
Lcd_Write_Data(BGCOLOR)
return
PUB PropFont_WriteCr(Character, PosR, PosC, RBorder, CBorder, BgC, TxC) | characterpointer, odd_even, bitpatern[32], idx, pxlidx, lcdidx, pxlidxdcd, x1, y1, x2, y2
odd_even := character & $0001
characterpointer := character & $fffe
characterpointer >>= 1
characterpointer *= 32
repeat idx from 0 to 31
bitpatern[idx] := long[FONT_ROM_ADDRESS][characterpointer + idx]
y1 := PosC + CBorder
y2 := (PosC + 15) - CBorder
x1 := PosR + RBorder
x2 := (PosR + 31) - RBorder
SetWindow(x1, y1, x2, y2)
SetGAddress(x1,y1)
repeat idx from RBorder to 31 - RBorder
repeat pxlidx from odd_even + (CBorder*2) to (odd_even + 30) - (CBorder*2) step 2
pxlidxdcd := |< pxlidx
if ((bitpatern[idx] & pxlidxdcd) == pxlidxdcd)
Lcd_Write_Com(REG_RAMDATAWRITE)
Lcd_Write_Data(TxC)
else
Lcd_Write_Com(REG_RAMDATAWRITE)
Lcd_Write_Data(BgC)
SetWindow(0, 0, 239, 319)
return
PUB SetWindow(x1, y1, x2, y2) | HORIZONTALRAMADDRESSPOS
WindowX1 := x1
WindowX2 := x2
WindowY1 := y1
WindowY2 := y2
HORIZONTALRAMADDRESSPOS := x1 + (x2 << 8)
Lcd_Write_Com ( REG_HORIZONTALRAMADDRESSPOS)
Lcd_Write_Data(HORIZONTALRAMADDRESSPOS)
Lcd_Write_Com (REG_VERTICALRAMADDRESSSTART)
Lcd_Write_Data(y1)
Lcd_Write_Com (REG_VERTICALRAMADDRESSEND)
Lcd_Write_Data(y2)
PUB SetGAddress(x,y)
Lcd_Write_Com (REG_SETGDDRxADDRESSCOUNTER) ''max %1111_1111, $FF
Lcd_Write_Data(x)
Lcd_Write_Com (REG_SETGDDRyADDRESSCOUNTER) ''max %1_0011_1111, $13f
Lcd_Write_Data(y)
return
''PUB ChangeOrientation(n) ' pass true = portrait or false = landscape, changes global variable orientation in this object
'' EnableLatchPins
'' orientation := n
'' if orientation
'' Lcd_Write_Com(REG_DRIVEROUTPUTCONTROL)
'' ILIcmd($0001,$0100) ' set SS and SM bit 0001 0100 portrait
'' ILIcmd($0003,$1030) ' set GRAM write direction and BGR=1. $0003 $1030
'' else
'' ILIcmd($0001,$0000) ' set SS and SM bit 0001 0000 landscape
'' ILIcmd($0003,$1038) ' landscape $1028 = original but 1038 is correct - not mirror image
PUB Enable_SDC
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS '
OUTA[DEV_SPI_EN] := 1
PUB Disable_SDC
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS '
OUTA[DEV_SPI_EN] := 1
PUB Set_Spi_Ext_Address(Ext_Spi_Address)
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_EXT_CS
wait.pause1s(1)
OUTA[DEV_SPI_ADD_LE] := 0
wait.pause1s(1)
SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 8, Ext_Spi_Address)
wait.pause1s(1)
OUTA[DEV_SPI_ADD_LE] := 1
wait.pause1s(1)
OUTA[DEV_SPI_ADD_LE] := 0 '
PUB Disable_SPI_EXT '
OUTA[DEV_SPI_EN] := 1
PUB StrobeCS
OUTA[DEV_SPI_EN] := 0
wait.pause1ms(5)
OUTA[DEV_SPI_EN] := 1
'********************** private methods *********************
PRI Enable_Touch
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS
OUTA[DEV_SPI_EN] := 0 '
PRI Disable_Touch
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS
OUTA[DEV_SPI_EN] := 0 '
PRI LCD_Reset
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_LCD_RES
outa[DEV_SPI_EN] := 0
wait.pause1ms(5) ''wait here if necessary '
outa[DEV_SPI_EN] := 1
PRI LCD_Writ_Bus(V)
OUTA[15..0] := V
WriteLow ' write pin low
WriteHigh ' toggle write pin
PRI Lcd_Write_Com(V)
RSLow
LCD_Writ_Bus(V)
PRI Lcd_Write_Data(V)
RSHigh
LCD_Writ_Bus(V)
PRI EnableDisplayPins
DIRA:=%00000001_11100011_11111111_11111111 ' , Reset, WR, RS and 16 data lines active
PRI TristateDisplayPins ' tristate all pins -
DIRA:=%00000001_11100010_00000000_00000000 ''
PRI RSLow
outa[RS] := 0
PRI RSHigh
outa[RS] := 1 '
PRI WriteLow
outa[LCD_WR] := 0 '
PRI WriteHigh
outa[LCD_WR] := 1
Pub Deadend 'Deadend
repeat
wait.pause1s(10000)
Not everything is working yet, but this *should* display pixels if you have the same controller.
eagletalontim, I can't work on the sd card right now, but hopefully dr A will figure this out. It would be a real bummer to find out the cage itself is bad. I hope I was doing something wrong. I was looking at the 5v crowd and they seem to have it working. I would THINK just removing the resistors would work, but bypassing may be key too. All I know is I tried both and I still have nothing. I'm making progress with the analog board, but still having issues. Time to RTFM...
Thanks, for the reply i'll try that out. I have tried to get the sd card working to and no luck so far. Weird i was hoping to use it and save some space(and money).
Tyler, which controller does your display use? Which display are you using? The one thing that comes to mind is POR values. Your display MAY NOT have the same Power On Reset values even if it is the same controller.
I am commenting code right now. I used to be in the habit of commenting as I wrote. I have been slacking off a bit.
I still have not been able to get my analog board to work. I will be switching back to my BS2 to test the control circuitry I added. The board was working with the BS2before I added the control circuitry. I'm hoping I'm just doing something wrong.
Found another wiring mistake. I wired DEV_SPI_ADD_LE to DEV_SPI_EN. I am correcting this now.
Other bugs found. Fixing those as well. I will be updating the final rev of ScreenTest shortly.
Thanks for the commented code i'll look at that later today when I have time. I hope Dr. A can firgure out the sd card, i can't. I read on a gadget gangstar forum that when not using PSM Sd Card reader your must put the Cs first instead of Do. As in:
...mount_explicit(CS, DI, CLK, DO) 'Gives me -100
instead of:
...mount_explicit(DO, CLK, DI, CS) 'Gives me -1
But unfortunately it doesn't seem to work, but mabye switching the order will provide a fix for this pesky sd card reader.
I hope Dr. A can firgure out the sd card, i can't. I read on a gadget gangstar forum that when not using PSM Sd Card reader your must put the Cs first instead of Do. As in:
...mount_explicit(CS, DI, CLK, DO) 'Gives me -100
instead of:
...mount_explicit(DO, CLK, DI, CS) 'Gives me -1
But unfortunately it doesn't seem to work, but mabye switching the order will provide a fix for this pesky sd card reader.
Cheers,
Tyler
I will have to look into this. I have most of my hardware revisions done. I think I will leave multiplexing the parallel bus for later when I need it. I have one more chip to mount and connect on my analog board, which is fully working now. Hopefully all will go well with this.
Just got my screens in today I ordered 2 and got 4. Guess it is an error in my favor. I will continue to follow this thread for updates on the SD card reading. Just have to get mine to turn on, then display a pixel... the fun begins!
@ eagle, Awesome! I want to order 4 more of these things. I'm about ready to start working on the sd card, although I don't think I need it yet. I've been writing and drawing a GUI. I still haven't bound anything yet, but it's getting close. I'm getting excited at the potential. I'm still using spin drivers to write the display which is slow. I will be converting to ASM shortly. Drawing a screen is not horrible, but takes about 12 seconds. This is single threaded still, but I will be implementing multi-threading as soon as I get the drivers working. I hate to have to write my own text based gui, but I couldn't find anything that fit my needs close enough. I want font scaling because the simple borders control I have is not enough. Hats off to the guys at parallax for programming this font on the rom. It looks great.
Tyler, which controller does your display use? Which display are you using? The one thing that comes to mind is POR values. Your display MAY NOT have the same Power On Reset values even if it is the same controller.
I am commenting code right now. I used to be in the habit of commenting as I wrote. I have been slacking off a bit.
I still have not been able to get my analog board to work. I will be switching back to my BS2 to test the control circuitry I added. The board was working with the BS2before I added the control circuitry. I'm hoping I'm just doing something wrong.
Found another wiring mistake. I wired DEV_SPI_ADD_LE to DEV_SPI_EN. I am correcting this now.
Other bugs found. Fixing those as well. I will be updating the final rev of ScreenTest shortly.
Hey, thanks for the help! I have tried your latest test and still miserable failure. You mentioned that my displays may not have the same Power on and Reset values as yours(I believe we are using the same exact touchscreen module). How do I find out these values for my board and how do I adapt the code to address this? I think this may solve my troubles(My display doesn't seem to turn on or Reset ).
I mentioned those PORs because I am not setting every register on power on. You might want to try setting all the registers. I don't know enough to advise the correct values. With how forgiving these displays are, I wonder if you have a hardware issue. Did you connect Vcc to a good +5v? LCD Chip Select to ground and Write to +3.3? Does the backlight come on? Make sure LCD reset is 3v after power on. I have not needed reset, or used it other than making it high in the bootstrap.
I mentioned those PORs because I am not setting every register on power on. You might want to try setting all the registers. I don't know enough to advise the correct values. With how forgiving these displays are, I wonder if you have a hardware issue. Did you connect Vcc to a good +5v? LCD Chip Select to ground and Write to +3.3? Does the backlight come on? Make sure LCD reset is 3v after power on. I have not needed reset, or used it other than making it high in the bootstrap.
Thanks for your patience. Yes I am using a good 5 volt for the VCC. I have put LCD CS to gnd and Write to 3.3 volt. Yes the Backlight turns in. But the LCD reset isn't 3V(tested with multimeter and got mere millivolts). My problem is that when I load the demo the backlight stays on but nothing comes up on the screen, don't know what to make of this though.
I sacrificed one of the displays by completely removing the SD socket and connecting wires to my own. Started with my own socket with lots of bypass caps and running the SD card off the propeller's 3V supply. First socket kept shorting the supply - who knows why but that one ended up in the bin. New socket. Moved the supply over to the local regulator. Removed first the 470uF, then the 22uF then the 0.1uF. No difference.
And then finally the answer. Bypassed the three 2k resistors.
So that is all you need to do. Remove those three resistors and replace with little wire links. Mine are not beautiful but they work fine. See attached photo. 10k pullups on the 4 lines. Oh and don't forget the card goes in upside down.
Tyler, your problem is the reset line. It must be high for the display to work. Otherwise the screen will just sit blank. You may be able to tie directly to 3v supply. I do not seem to need it, but results may vary.
Dr.A, I'm glad you got the card working. I will try again now that the rest of the hardware works.
Victory! Your were right joe my problem was the reset. I put it straight to the 3V just as you suggested and it worked perfectly. Now i'll move on to wiring touch recognition(hopefully it will take me less than a week ). Thanks for your help Joe and Dr. Acula(over on his thread).
@Dr. A im glad you solved the mystery of the sd card i'll definintly modify my board as you suggested and see if it works.
Awesome! I'm glad I could help. The touch input is very simple. DI, DO, Ck and CS. Write a byte, read 12. X-Y decoding looks to be decently easy.I will play with this in a couple days.
I have been thinking about freeing up the reset line since the screen doesn't seem to need it. I need to hook the CS line for the sd card back up and do some more tests. The sd cards I'm using (tried 3) might be the culprit. Now that everything else is working, it would be nice to have. I hope to have my sd breakout today or tomorrow, so that will give me something to test against as well.
I'm currently working out a couple aspects of the future menu design. I like using the propeller ROM font. It looks nice and has a comprehensive character set. I still need to write a few methods for the PropFont object, but this is what I have so far.
This is my PropFont object.
I'm sorry that I have not commented this code yet. I need to finish abstraction as well. It seems to run ok, other than being a bit slow. I have some ideas for optimization, but have not started working it out. I am convinced that using 2 cogs running Pasm will speed up display writes significantly. Before I can work on asm I need to finish the spin code. This includes a working character based gui. The current top object looks something like this.
That's the main portion of the code, some helper methods in the top object are
PUB Enable_SDC
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS '
OUTA[DEV_SPI_EN] := 1
PUB Disable_SDC
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_SDC_CS '
OUTA[DEV_SPI_EN] := 1
PUB Set_Spi_Ext_Address(Ext_Spi_Address)
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_EXT_CS
wait.pause1ms(1)
OUTA[DEV_SPI_ADD_LE] := 0
wait.pause1ms(1)
SPI.SHIFTOUT(DEV_SD_DO, DEV_SD_CLK, 5, 3, Ext_Spi_Address)
wait.pause1ms(1)
OUTA[DEV_SPI_ADD_LE] := 1
wait.pause1ms(1)
'OUTA[DEV_SPI_ADD_LE] := 0
'
PUB Disable_SPI_EXT '
OUTA[DEV_SPI_EN] := 1
PUB StrobeCS
OUTA[DEV_SPI_EN] := 0
wait.pause1ms(10)
OUTA[DEV_SPI_EN] := 1
PUB TestTS | yval, xval,x,y
Enable_Touch ''Old format was OUTA[TS_CS] := 0 ' enable the touch screen
'SPI.start(3,0) ' delay,state Already running?
'Shiftout = data,clock,mode,bits,value
'shiftin = data,clock,mode,bits
'SPI read S, A2, A1, A0, Mode, SER, PD1, PD0
' 1 0 0 1 1 0 0 0
' MSB first
' 001 is X
' 101 is Y
repeat
pst.clear
SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1101_0000) ' reads x from 500 to 3700 (off < 500 )
xval := SPI.SHIFTIN(DEV_SD_DO, DEV_SD_CLK,2, 12)
SPI.SHIFTOUT(DEV_SD_DI, DEV_SD_CLK, 5, 8 , %1001_0000) ' reads y from 400 to 3800 (off > 3800 )
yval := SPI.SHIFTIN(DEV_SD_DO,DEV_SD_CLK,2, 12)
pst.Dec(xval)
pst.newline
pst.Dec(yval)
wait.pause1ms(10)
Disable_Touch ''Old format was OUTA[TS_CS] := 1 ' disable the touch screen
PUB PST_Init | PstCog ''Starts Parallax Serial Terminal for debugging.
PstCog := (pst.Start(115200) -1) '' returns the cog pst started in
pst.Str(String("Parallax Serial Terminal started in cog ")) '' talk to human
pst.Dec(PstCog) '' displays cog on PST ''
wait.pause1s(2)
'********************** private methods *********************
PRI Enable_Touch
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS
OUTA[DEV_SPI_EN] := 0 '
PRI Disable_Touch
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_TSC_CS
OUTA[DEV_SPI_EN] := 0
PRI LCD_Reset
OUTA[DEV_SPI_ADD1..DEV_SPI_ADD0] := DEV_SPI_LCD_RES
outa[DEV_SPI_EN] := 0
wait.pause1ms(5) ''wait here if necessary '
outa[DEV_SPI_EN] := 1
These are the basics. Once I get propfont finished, I'll re-write in asm which should speed up the display quite a bit. 12 seconds to display a blank screen is a bit too slow IMO. 4 sounds WAY more reasonable.
I've been working on the assembly program and had a lightbulb go off. I can save several instructions by adding a 10k pullup to the LCD write line. Instead of adding lcdwriteline to the data to be sent out, making pins = data, then pulling the write line low and back high again, flow will go make pins=data, mux lcdwrite*DIR* out, then back to input. I will be updating my hardware to this soon, but I'm writing without the update so I can test the difference this makes.
I will also be using a pullup on RS. This will save some code too.
edit,
Made hardware changes. I'm obviously doing something wrong in my ASM test. I don't know what now, I'll have to come back to this in a bit. Maybe someone can find my mistake, I'm burnt out at this point.
CON
_clkmode = xtal1 + pll16x ' use crystal x 16
_xinfreq = 5_000_000
DEV_SPI_EN = 21
PUB BOOT 'bootstrap
dirA[DEV_SPI_EN] := 1
OUTA[DEV_SPI_EN] := 1
cognew(@entry, 0)
repeat
wait.pause1s(5)
DAT
org 0
entry mov dira, DirsEnabled 'initalize pins
mov outa, PinsInit 'and set write high
'then initalize display
mov LCD_Data,asmREG_DISPLAYCONTROL ''Display Control (R07h) (POR = 0000h)
call #writecmd
mov LCD_Data,DISPLAYCONTROL0 '' GON = 1 DTE = 0 D[1:0] = 01
call #writedat
mov LCD_Data,asmREG_OSCILLATOR ''Oscillator (R00h) (POR = 0000h)
call #writecmd
mov LCD_Data,OSCILLATOR ''Turn on oscillator
call #writedat
mov LCD_Data,asmREG_DISPLAYCONTROL ''Display Control (R07h) (POR = 0000h)
call #writecmd
mov LCD_Data,DISPLAYCONTROL1 ''GON = 1 DTE = 0 D[1:0] = 11
call #writedat
mov LCD_Data,asmREG_SLEEPMODE ''Sleep mode (R10h) (POR = 0001h)
call #writecmd
mov LCD_Data,SLEEPMODE '' ''exit sleep mode
call #writedat
mov LCD_Data,asmREG_DISPLAYCONTROL ''Display Control (R07h) (POR = 0000h)
call #writecmd
mov LCD_Data,DISPLAYCONTROL2 ''GON = 1 DTE = 1 D[1:0] = 11
call #writedat
mov LCD_Data,asmREG_ENTRYMODE ''Entry Mode (R11h) (POR = 6830h)
call #writecmd
mov LCD_Data,ENTRYMODE ''
call #writedat
mov LCD_Data,asmREG_LCDDRIVINGWAVFORM ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)($1000)
call #writecmd
mov LCD_Data,DRIVINGWAVEFORM '' ''
call #writedat
mov LCD_Data,asmREG_GATESCANPOSITION ''Gate Scan Position (R0Fh) (POR = 0000h) ($0000)
call #writecmd
mov LCD_Data,GATESCANPOSITION ''
call #writedat
mov LCD_Data,asmREG_DRIVEROUTPUTCONTROL ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) 433f ($633F)
call #writecmd
mov LCD_Data,DRIVEROUTPUT ''
call #writedat
mov LCD_Data,asmREG_FRAMECYCLECONTROL ''Frame Cycle Control (R0Bh) (POR = 5308h) ($5308)
call #writecmd
mov LCD_Data,FRAMECYCLE ''
call #writedat
mov LCD_Data,asmREG_DISPLAYCONTROL ''Display Control (R07h) (POR = 0000h) ($0033)
call #writecmd
mov LCD_Data,DISPLAYCONTROL2 ''GON = 1 DTE = 1 D[1:0] = 11
call #writedat
mov LCD_Data,asmREG_DISPLAYCONTROL ''Display Control (R07h) (POR = 0000h) ($0033)
call #writecmd
mov LCD_Data,DISPLAYCONTROL2 ''GON = 1 DTE = 1 D[1:0] = 11
call #writedat
mov LCD_Data,asmREG_HORIZONTALRAMADDRESSPOS
call #writecmd
mov LCD_Data,asmHORIZONTALRAMADDRESSPOS
call #writedat
mov LCD_Data,asmREG_VERTICALRAMADDRESSSTART
call #writecmd
mov LCD_Data,#0
call #writedat
mov LCD_Data,asmREG_VERTICALRAMADDRESSEND
call #writecmd
mov LCD_Data,239
call #writedat
loop mov LCD_Data,asmREG_RAMDATAWRITE
call #writecmd
mov LCD_Data,asmColor
call #writedat
jmp #loop
writecmd
mov outa, LCD_Data wc
nop
muxc dira,RSpin
nop
muxnc dira,WritePin
nop
muxc dira,WritePin
nop
muxnc dira,RSpin
nop
writecmd_ret
writedat
mov outa, LCD_Data wc
nop
muxnc dira,WritePin
nop
muxc dira,WritePin
nop
writedat_ret
asmColor long $0000
PinsInit long %00000000_00000000_00000000_00000000
DirsDisabled long %00000000_00000000_11111111_11111111
DirsEnabled long %00000000_00000000_11111111_11111111
BackgroundColorASM long $ffff
ActiveColorASM long $0000
WritePin long %00000000_00000010_00000000_00000000
RSPin long %00000000_00000001_00000000_00000000
GATESCANPOSITION long $0000_0000
SLEEPMODE long $0000_0000
OSCILLATOR long $0000_0001
DISPLAYCONTROL0 long $0000_0021
DISPLAYCONTROL1 long $0000_0023
DISPLAYCONTROL2 long $0000_0033
FRAMECYCLE long $0000_5308
DRIVEROUTPUT long $0000_6B3F
DRIVINGWAVEFORM long $0000_1000
ENTRYMODE long $0000_6838
asmXADDRESSCOUNTER long $0000_0000
asmHORIZONTALRAMADDRESSPOS long $0001_3F00
asmREG_OSCILLATOR long $0000_0000 ''Oscillator (R00h) (POR = 0000h)
asmREG_DRIVEROUTPUTCONTROL long $0000_0001 ''Driver Output Control (R01h) (POR = 2B3Fh)
asmREG_LCDDRIVINGWAVFORM long $0000_0002 ''LCD-Driving-Waveform Control (R02h) (POR = 0000h)
asmREG_POWERCONTROL1 long $0000_0003 '' (R03H)
asmREG_DISPLAYCONTROL long $0000_0007 ''Display Control (R07h) (POR = 0000h)
asmREG_FRAMECYCLECONTROL long $0000_000B ''Frame Cycle Control (R0Bh) (POR = 5308h)D308 BY DATASHEET
asmREG_POWERCONTROL2 long $0000_000C '' (R0Ch) (POR = 0004)
asmREG_POWERCONTROL3 long $0000_000D ''
asmREG_POWERCONTROL4 long $0000_000E ''
asmREG_GATESCANPOSITION long $0000_000F ''Gate Scan Position (R0Fh) (POR = 0000h)
asmREG_SLEEPMODE long $0000_0010 ''Sleep mode (R10h) (POR = 0001h)
asmREG_ENTRYMODE long $0000_0011 ''Entry Mode (R11h) (POR = 6830h)
asmREG_HPORCH long $0000_0016 '' (R16h) (POR = EF1Ch)
asmREG_VPORCH long $0000_0017 '' (R17h) (POR = 0003h)
asmREG_POWERCONTROL5 long $0000_001E ''
asmREG_RAMDATAWRITE long $0000_0022 ''
asmREG_RAMWRITEDATAMASK1 long $0000_0023 '' (R23h) (POR = 0000h)
asmREG_RAMWRITEDATAMASK2 long $0000_0024 '' (R24h) (POR = 0000h)
asmREG_VERTICALSCROLCONTROL1 long $0000_0041 '' (R41h) (POR = 0000h)
asmREG_VERTICALSCROLCONTROL2 long $0000_0042 '' (R42h) (POR = 0000h)
asmREG_HORIZONTALRAMADDRESSPOS long $0000_0044 '' (R44h) (POR = EF00h)
asmREG_VERTICALRAMADDRESSSTART long $0000_0045 '' (R45h) (POR = 0000h)
asmREG_VERTICALRAMADDRESSEND long $0000_0046 '' (R46h) (POR = 013Fh)
asmREG_FIRSTWINDOWSTART long $0000_0048 '' (R48h) (POR = 0000h)
asmREG_FIRSTWINDOWEND long $0000_0049 '' (R49h) (POR = 013Fh)
asmREG_SECONDWINDOWSTART long $0000_004A '' (R4Ah) (POR = 0000h)
asmREG_SECONDWINDOWEND long $0000_004B '' (R4Bh) (POR = 013Fh)
asmREG_SETGDDRXADDRESSCOUNTER long $0000_004E '' (R4Eh) (POR = 0000h)
asmREG_SETGDDRYADDRESSCOUNTER long $0000_004F '' (R4Fh) (POR = 0000h)
LCD_data res 1
What you're doing here is running a huge loop full of nops. The nr modifier at the tail of your instructions stands for no result meaning the destination isn't affected. I don't think that's the idea here. So just remove them and let the insns do their default behaviour.
@Tyler, the colors are two bytes RRRRRGGG_GGGBBBBB so you get 5 levels for red and blue, and 6 levels for green. White is 11111111_11111111 which is hex FFFF
@Tyler, hex would be $FFFF. remember $ is Hex and hex is base 16. 0 - 9 and A thru F.
Thanks Kuroneko, I'll try again. Not very good @asm.
Thanks Joe! It worked perfectly(i need to read up on HEX im not familiar with it).
@Dr. Acula I bypassed the 2K resistors and the SD Card still didn't work. I tested my links they seemed fine, but my program still returned "Failed to Mount"(-1). Are there any other issues that may cause the sd not to work? I have formatted it to FAT-16 and it's a Lexar SDHC 4GB Sd card(if that helps with the diagnosis).
I have a working dat block. It writes a blank screen in a flash. I hope I can squeeze the character read and decode into the clock cycles wasted by the write loop. Very promising results. I'm glad I took the jump from spin to ASM. ASM is not that much harder, it's just it requires that much more though to making things work.
I hooked the sd card on my screen back up, but I haven't tested it yet. Now that spin code works, I'm going to investigate again. The hardware mods work great. Getting ASM working was top priority, now on to sd card!
*edit*
the question I have now is on cognew formatting..
is it?
cognew(@entry, @buffer)
or?
cognew(@entry,@@buffer)
A 50sec delay is usually an indicator that waitcnt just missed its target and is now waiting for a full wrap-around. Can you figure out where in your code it blocks (delay could be in an object)?
This is a little bit of code for those that can print a pixel but can't get an SD card working in order to display a font. Uses the internal propeller font which is inside the propeller chip.
PUB Propfont ' use propeller font in the rom for bootup messages when debugging sd cards
curx := 0 ' set cursor to top left of screen (common variable)
cury := 0
Propfont_string(string("Loading SD")) ' string to send
Propfont_string(string("Loading Font"))
PUB Propfont_string(stringptr) 'print at curx,cury
repeat strsize(stringptr)
ILI9325.draw(curx,cury,curx+15,cury+31) ' location to start drawing
Propfont_out(byte[stringptr++])
curx +=16
curx := 0
cury += 32 ' new line at end of string
PUB Propfont_out(ascii) | address,pixels
address := $8000 + (ascii >> 1) << 7 ' get rom address
repeat 32 ' 32 rows per character, split in two parts
pixels := long[address] ' get rom font data
pixels := pixels >> (ascii & 1) ' shift for odd characters
repeat 16 ' 16 columns
if pixels & 1
ILI9325.pixel(%00000111_11100000) ' foreground color RRRRRGGG_GGGBBBBB
else
ILI9325.pixel(%00000000_00000000) ' background color
pixels := pixels >> 2 ' alternate pixels interleaved so shift 2
address += 4 'increment address by 4 bytes
Comments
First thing, make sure you are using the same controller. If you are, it's most likely my code. I have had some bugs so. I changed hardware version, but the display is wired the same right now.
Not everything is working yet, but this *should* display pixels if you have the same controller.
eagletalontim, I can't work on the sd card right now, but hopefully dr A will figure this out. It would be a real bummer to find out the cage itself is bad. I hope I was doing something wrong. I was looking at the 5v crowd and they seem to have it working. I would THINK just removing the resistors would work, but bypassing may be key too. All I know is I tried both and I still have nothing. I'm making progress with the analog board, but still having issues. Time to RTFM...
I am commenting code right now. I used to be in the habit of commenting as I wrote. I have been slacking off a bit.
I still have not been able to get my analog board to work. I will be switching back to my BS2 to test the control circuitry I added. The board was working with the BS2before I added the control circuitry. I'm hoping I'm just doing something wrong.
Found another wiring mistake. I wired DEV_SPI_ADD_LE to DEV_SPI_EN. I am correcting this now.
Other bugs found. Fixing those as well. I will be updating the final rev of ScreenTest shortly.
...mount_explicit(CS, DI, CLK, DO) 'Gives me -100
instead of:
...mount_explicit(DO, CLK, DI, CS) 'Gives me -1
But unfortunately it doesn't seem to work, but mabye switching the order will provide a fix for this pesky sd card reader.
Cheers,
Tyler
Hey, bonus. Tempting to order 2000 and see what happens.
6 hours to go before work stops and soldering time starts
Hey, thanks for the help! I have tried your latest test and still miserable failure. You mentioned that my displays may not have the same Power on and Reset values as yours(I believe we are using the same exact touchscreen module). How do I find out these values for my board and how do I adapt the code to address this? I think this may solve my troubles(My display doesn't seem to turn on or Reset ).
Thanks Again,
Tyler
Thanks for your patience. Yes I am using a good 5 volt for the VCC. I have put LCD CS to gnd and Write to 3.3 volt. Yes the Backlight turns in. But the LCD reset isn't 3V(tested with multimeter and got mere millivolts). My problem is that when I load the demo the backlight stays on but nothing comes up on the screen, don't know what to make of this though.
Thanks,
Tyler
I sacrificed one of the displays by completely removing the SD socket and connecting wires to my own. Started with my own socket with lots of bypass caps and running the SD card off the propeller's 3V supply. First socket kept shorting the supply - who knows why but that one ended up in the bin. New socket. Moved the supply over to the local regulator. Removed first the 470uF, then the 22uF then the 0.1uF. No difference.
And then finally the answer. Bypassed the three 2k resistors.
So that is all you need to do. Remove those three resistors and replace with little wire links. Mine are not beautiful but they work fine. See attached photo. 10k pullups on the 4 lines. Oh and don't forget the card goes in upside down.
Dr.A, I'm glad you got the card working. I will try again now that the rest of the hardware works.
@Dr. A im glad you solved the mystery of the sd card i'll definintly modify my board as you suggested and see if it works.
Thanks,
Tyler
I have been thinking about freeing up the reset line since the screen doesn't seem to need it. I need to hook the CS line for the sd card back up and do some more tests. The sd cards I'm using (tried 3) might be the culprit. Now that everything else is working, it would be nice to have. I hope to have my sd breakout today or tomorrow, so that will give me something to test against as well.
I'm currently working out a couple aspects of the future menu design. I like using the propeller ROM font. It looks nice and has a comprehensive character set. I still need to write a few methods for the PropFont object, but this is what I have so far.
This is my PropFont object. I'm sorry that I have not commented this code yet. I need to finish abstraction as well. It seems to run ok, other than being a bit slow. I have some ideas for optimization, but have not started working it out. I am convinced that using 2 cogs running Pasm will speed up display writes significantly. Before I can work on asm I need to finish the spin code. This includes a working character based gui. The current top object looks something like this. That's the main portion of the code, some helper methods in the top object are These are the basics. Once I get propfont finished, I'll re-write in asm which should speed up the display quite a bit. 12 seconds to display a blank screen is a bit too slow IMO. 4 sounds WAY more reasonable.
I will also be using a pullup on RS. This will save some code too.
edit,
Made hardware changes. I'm obviously doing something wrong in my ASM test. I don't know what now, I'll have to come back to this in a bit. Maybe someone can find my mistake, I'm burnt out at this point.
Thanks Kuroneko, I'll try again. Not very good @asm.
Thanks Joe! It worked perfectly(i need to read up on HEX im not familiar with it).
@Dr. Acula I bypassed the 2K resistors and the SD Card still didn't work. I tested my links they seemed fine, but my program still returned "Failed to Mount"(-1). Are there any other issues that may cause the sd not to work? I have formatted it to FAT-16 and it's a Lexar SDHC 4GB Sd card(if that helps with the diagnosis).
Thanks for your help,
Tyler
*edit*
the question I have now is on cognew formatting..
is it?
cognew(@entry, @buffer)
or?
cognew(@entry,@@buffer)
it runs. screen clears slowly, then displays wait for 50 +seconds. Then draws, and done? is there some way to start a cog faster?
*edit* PST displays this
clear, tri-stating pins
tri-stated pins, starting cog with screen buff
er address
3292
163
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
waiting
donedonedonedonedonedonedonedonedonedonedonedo
clear, tri-stating pins
tri-stated pins, starting cog with screen buff
er address
3292
163
waiting * 52 times then..
donedonedonedonedonedonedonedonedonedonedon
*edit* Fixed it..
I can be so dumb sometimes. Changed first wait to to the RIGHT one