Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LCD SPI projects.

Status
Not open for further replies.
Hi Eric, I ordered some 18F26K22's as I wanted 28 pin and lot's of memory, they seem nice little chips.

As far as SD goes, I got mine working this weekend, using a 24F (but the 18F26K22 should be fine as well) - I'm using an ST7735 display with SD socket on board, and displaying BMP pictures (of the correct size) from the card to the screen.

I'm using FatFs from here:
 
I didn't think you could have more than 512 bytes array in oshonsoft!! If I use :-
dim buffer(1024) as byte will it work.... I just assumed his page writes is as assembler? I have never actually checked..
 
I didn't think you could have more than 512 bytes array in oshonsoft!! If I use :-
dim buffer(1024) as byte will it work.... I just assumed his page writes is as assembler? I have never actually checked..
I have not tested it, but from the manual max array size is 1024 bytes.
 
I did a tiny hardware SPI function for Oshonsoft... I tested to 2mhz on a 25c320 SPI memory chip!!

Hi Ian,
In your program I am assuming that you are using PORTC.2 = ss for selection of the memory chip.??
I have slowed the HW SPI down to div by 16, still cannot get a simple screen fill on the TFT.
Checked the wiring by using Oshonsoft SPI to drive the TFT, works OK.

Using your SPI subr calling a dummy Proc, I can scope all the signals, all appear OK, very puzzling.??

E
 
I have slowed the HW SPI down to div by 16, still cannot get a simple screen fill on the TFT.
Are you doing any reads? I haven't tested reads... What speed is your clock.... The IlI9225 should be able to go to the max...

P.S. I may buy a 2.8 serial screen ( I need it for something else ) An test it!!
 
hi Ian,
Tried the clock polarity, no success.
Now fitted an active level shifter, drives the TFT OK using Oshonsoft SPI, using same PIC pin out as HW SPI. No success with HW SPI.
Scoping the four SPI controls signals when PIC programmed with Oshonsoft SW SPI or a HW SPI program shows identical waveforms, timing approx the same. [ HW SPI clk/16]
Tried three different 9225 modules.

E
 
hi Ian,
Tried the clock polarity, no success.
Now fitted an active level shifter, drives the TFT OK using Oshonsoft SPI, using same PIC pin out as HW SPI. No success with HW SPI.
Scoping the four SPI controls signals when PIC programmed with Oshonsoft SW SPI or a HW SPI program shows identical waveforms, timing approx the same. [ HW SPI clk/16]
Tried three different 9225 modules.

E
I'll try and see if I can get it to work on a ILI9341 tonight ( the only one I have..) My is set up for 8 bit parallel but it will do 4 wire SPI... I'll let you know how it goes..

Just for clarity!! Try fosc_64 SSPCON1 = 0x23.. See if it works at the slowest speed...
 
I just run the hardware SPI on the sim and it didn't work.... Changed the CKP to 1 and it works... I have a 4Mhz clock and I'm running the SPI at 1Mhz....

I have run it up on ISIS first ( so I could debug it)... This is on a nokia 5110... It seems to run pretty dam quick!!!

Here is the basic code... Just to let you know, this is exactly the same code I use in C... Just ported it to basic.

Code:
Define CONFIG1L = 0x00
Define CONFIG1H = 0x08
Define CONFIG2L = 0x1e
Define CONFIG2H = 0x00
Define CONFIG3L = 0x00
Define CONFIG3H = 0x83
Define CONFIG4L = 0x80
Define CONFIG4H = 0x00
Define CONFIG5L = 0x0f
Define CONFIG5H = 0xc0
Define CONFIG6L = 0x0f
Define CONFIG6H = 0xe0
Define CONFIG7L = 0x0f
Define CONFIG7H = 0x40
Symbol ss = LATC.2
Symbol d_c = LATC.1
Symbol rst = LATC.0
TRISC = 0x10
Dim x As Word
Dim ret As Byte
OSCCON = 0x70
ADCON1 = 0xf
Call spi_init()
TRISA.5 = 0
LATA.5 = 0
WaitMs 10
Call initscreen()
loop:
 Call clearscreen(0xf0)
 WaitMs 50
 Call clearscreen(0x0f)
 WaitMs 50
 Goto loop
End                                               
'----------------------------------------
Proc spi_init()
 TRISC.5 = 0
 TRISC.2 = 0
 TRISC.4 = 1
 TRISC.3 = 0
 ss = 1
 SSPSTAT = 0
 'SSPSTAT.CKE = 1  'clock edge un remark for trailing edge
 SSPCON1 = 0x20  'full whack... at 8mhz 2mhz operation no SS control
      '00 = fosc/4.. 01 = fosc /16
      '10 = fosc/64.. 11 contolled by timer2.
 SSPCON1.CKP = 1  'clock polarity unremark for high polarity
End Proc                                          
'----------------------------------------
Function do_spi_8(data As Byte) As Byte
 do_spi_8 = SSPBUF
 SSPBUF = data
 While Not SSPSTAT.BF
 Wend
 
End Function                                      
'----------------------------------------
Proc initscreen()
 rst = 0
 WaitMs 100
 rst = 1
 Call sendcommand(0x21)
 Call sendcommand(0x13)
 Call sendcommand(0x07)
 Call sendcommand(0xc0)
 Call sendcommand(0x20)
 Call sendcommand(0x0c)
End Proc                                          
'----------------------------------------
Proc clearscreen(sc As Byte)
  d_c = 1
  ss = 0
  For x = 0 To 504
   ret = do_spi_8(sc)
  Next x
  ss = 1
End Proc                                          
'----------------------------------------
Proc sendcommand(cmd As Byte)
  d_c = 0
  ss = 0
  ret = do_spi_8(cmd)
  ss = 1
End Proc                                          
'----------------------------------------
Proc senddata(data As Byte)
  d_c = 1
  ss = 0
  ret = do_spi_8(data)
  ss = 1
End Proc
 
Morning Ian,
Downloaded your 5110 program, where do you have the 'ss' line connected on the 5110 PCB.?
When all 4 control lines are connected to the SPI line.?
Symbol ss = LATC.2
Symbol d_c = LATC.1 'cmd or data
Symbol rst = LATC.0 ' reset
----------------------
TRISC.5 = 0' sdo
TRISC.2 = 0 'ce
TRISC.4 = 1 ' sdi not used
TRISC.3 = 0 'sck
ss = 1 .???

I would have thought that the HW SPI would control ss/ce, is it required that the ss/cs line be also controlled by the program code
Am I missing something.?:)
Eric
Same question for the 9225 TFT.?
 

Attachments

  • 5110pin.gif
    5110pin.gif
    76.3 KB · Views: 331
I would have thought that the HW SPI would control ss/ce, is it required that the ss/cs line be also controlled by the program code
Am I missing something.?:)

CS (or CE) is entirely independent of the SPI port, and isn't actually needed at all - as long as you only have one item connected to the port.

It's also pretty important it is independent, if it was controlled by the SPI hardware it would greatly restrict SPI operation.
 
CS (or CE) is entirely independent of the SPI port, and isn't actually needed at all - as long as you only have one item connected to the port.
Not necessarily true.... Some devices use the CS as a latch the ILI9225 datasheet said it uses the CS rising to latch data..

Most eeproms need it..

Eric... SS is serial select... Most use CS and yes its on PORTC2 Nokia call it CSE
It's also pretty important it is independent, if it was controlled by the SPI hardware it would greatly restrict SPI operation.
True!!! Imagine trying to shift 24 bit data, address and command... It will cause havoc.. If you notice the clear screen routine CS = 0 then 504 bytes then CS = 0...
 
Last edited:
The CE ( SS) on the ILI9225 is needed as the serial packet has a start byte but no end byte... The CS denotes the end of transmission..
datasheet said:
The SPI interface operation enables from the falling edge
of nCS and ends of data transfer on the rising edge
of nCS. The start byte is transferred to start the SPI
interface and the read/write operation and RS information
are also included in the start byte. When the start byte
is matched, the subsequent data is received by
ILI9225B.
 
hi guys,
Thanks for the feedback, will give 'ss' a go later.

E


Update:
Able to get TFT screen fill control, this is the working spi-init code.
Note: fosc/4 and remmed SSPSTAT.CKE.
I would say that it is now comparable with Arduino UNO lcd fill speed usingHW SPI.
tried 'full whack' mode, no output.
Next step is to edit/paste the other graphics Proc and the text..

Proc spi_init()
TRISC.5 = 0 'sdo to 9225
TRISC.2 = 0 'TRISC.2 = 0 'ss
TRISC.4 = 1 'sdi not used on TFT
TRISC.3 = 0 'clk
ss = 1
SSPSTAT = 0

'SSPSTAT.CKE = 1 'clock edge un remark for trailing edge
'SSPCON1 = 0x10 'full whack... at 8mhz 2mhz operation no SS control
SSPCON1 = %00100000
'00 = fosc/4.. 01 = fosc /16
'10 = fosc/64.. 11 contolled by timer2.
SSPCON1.CKP = 1 'clock polarity unremark for high polarity
End Proc
 
Last edited:
hi,
Increased the PIC clock to 20MHz , external xtal, 18F4520, using no added delays in the SPI Proc's, running at fosc/4 rate, its fast.!
E
 
5Mhz SPI... Wow you are nearly at the limit.... I think most devices ( LCD's) are okay up to 10Mhz

Just for reference.. CKE ( clock edge 0= rising. 1 = trailing )
CKP ( clock polarity 0 = low. 1 = high )

My remarks were not clear enough.. Looking back even I think it sounds gibberish!!
 
Status
Not open for further replies.
Back
Top