Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Cell phone LCD screen/SPI problem
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
superbrad

Bascom Member



Joined: 18 Sep 2005
Posts: 62

usa.gif
PostPosted: Wed Feb 22, 2006 10:12 am    Post subject: Cell phone LCD screen/SPI problem Reply with quote

Hi all, I've spent the last week pulling my hair out trying to work this one out:

I've been working on interfacing a Nokia 6100 LCD screen knock-off to my Mega128. $20 for a color LCD (128x128 pixels, 4096 colors) is too much for me to resist trying out! But I can't quite get it to work (obviously else I'd be posting working code Wink. I bought it from Sparkfun.com with the breakout board (http://www.sparkfun.com/commerce/product_info.php?products_id=569). They provide source code for an ARM processor in C, and I ported it (as best I could) to BASCOM. But the screen remains blank after initialization, it seems to me like the problem is with the SPI communication.

Tricky part with this LCD is it has a 9 bit serial interface, so I can't just use SPIOUT to send it commands/data, I have to Shiftout or bit bang it. I've tried both these methods and neither seem to work. Can someone take a look at my code and tell me what's wrong?

A few details:
- First bit: 0 = Command, 1 = Data, followed by 8 bits.
- Mega128 (running in M128 mode) using 4MHz internal oscillator.
- Pins are connected to HW SPI pins.
- The source code I ported from uses SPI w/ CPHA = 1, CPOL = 1 settings (reads on rising edge, msb first).
- The LCD driver chip is an S1D15G10. The datasheet can be found at Sparkfun (follow the above link).



I'm pretty sure the problem is in the communication routines, so I'll just post them to start with. Cs, Mosi, and Clk are all aliases.


*** Shiftout Method ***

Code:
Sub Snd_cmd(byval Lcdcmd As Byte)
  Cs = 0
  Clk = 0
  Mosi = 1                                                  'Commands = 1
  Clk = 1
  Shiftout Mosi , Clk , Lcdcmd , 1
  Cs = 1
End Sub

Sub Snd_data(byval Lcddata As byte)
  Cs = 0
  Clk = 0
  Mosi = 0                                                  'Data = 0
  Clk = 1
  Shiftout Mosi , Clk , Lcddata , 1
  Cs = 1
End Sub




*** Bit Bang Method ***

Code:
Sub Snd_cmd(byval Lcdcmd As Byte)
  Cs = 0
  Clk = 0
  Mosi = 1                                                  'Commands = 1
  Clk = 1
  Shiftbits Lcdcmd
  Cs = 1
End Sub

'************************************************************

Sub Snd_data(byval Lcddata As byte)
  Cs = 0
  Clk = 0
  Mosi = 0                                                  'Data = 0
  Clk = 1
  Shiftbits Lcddata
  Cs = 1
End Sub

'************************************************************

Sub Shiftbits(dab As Byte)
  Clk = 0
  Mosi = Dab.7
  Clk = 1

  Clk = 0
  Mosi = Dab.6
  Clk = 1

  Clk = 0
  Mosi = Dab.5
  Clk = 1

  Clk = 0
  Mosi = Dab.4
  Clk = 1

  Clk = 0
  Mosi = Dab.3
  Clk = 1

  Clk = 0
  Mosi = Dab.2
  Clk = 1

  Clk = 0
  Mosi = Dab.1
  Clk = 1

  Clk = 0
  Mosi = Dab.0
  Clk = 1
End Sub



Neither one (along with many variants of both) have worked. I attached the entire code in case any one wants to see the rest. I'm really a beginner in over my head if you can't tell. I might borrow an oscilloscope from work and see if I can learn any more about what's actually getting sent out on the pins ...

Any help is greatly appreciated! I don't have much more hair left to lose before I start looking like my dad ...

Brad

"You can gauge a man's ambition by whether he considers his alarm clock his best friend or his worst enemy." - Emerson
Back to top
View user's profile AIM Address Yahoo Messenger MSN Messenger
bfdegraaff

Bascom Member



Joined: 15 Nov 2005
Posts: 72
Location: Brazil

brazil.gif
PostPosted: Wed Feb 22, 2006 1:11 pm    Post subject: Reply with quote

Dear Superbrad,

It looks to me that you are using a display with an SPI interface,
Bascom has routines to do that, so the only you need to do is
send the right commands to initialize. (See datasheet)

Try searching SPI in the Bascom Help, also see this commands:
SPIOUT, SPIIN , SPIINIT , CONFIG SPI , SPIMOVE

Regards, Barry de Graaff

_________________
______

Barry de Graaff is a micro electronics student,
formerly on work emplacement at MCS Electronics.

www.barrydegraaff.tk/edb
Back to top
View user's profile Visit poster's website
superbrad

Bascom Member



Joined: 18 Sep 2005
Posts: 62

usa.gif
PostPosted: Wed Feb 22, 2006 10:10 pm    Post subject: Reply with quote

Quote:
It looks to me that you are using a display with an SPI interface,
Bascom has routines to do that, so the only you need to do is
send the right commands to initialize. (See datasheet)


I've looked at the Bascom routines, but how can I configure it to work with a 9 bit SPI interface? I'm fairly certain the initialization commands I'm trying to send are the correct ones as I've taken them from a couple of versions of source code and the datasheet confirms that they should work.

Is there a way to use hardware SPI to communicate with 9 bits?

I'll take another look at those commands and see if I can get them to work with it.

Thanks,
Brad

"The creation of a thousand forests lies within a single acorn." - Emerson
Back to top
View user's profile AIM Address Yahoo Messenger MSN Messenger
DToolan

Bascom Member



Joined: 14 Aug 2004
Posts: 1384
Location: Dallas / Fort Worth, Texas (USA)

blank.gif
PostPosted: Wed Feb 22, 2006 10:50 pm    Post subject: Reply with quote

Quote:
Is there a way to use hardware SPI to communicate with 9 bits?

No. The AVR SPI hardware is designed for byte (and multiples thereof) transmission. Investigate the use of SHIFTOUT instead.
Back to top
View user's profile Yahoo Messenger
ATIU

Bascom Member



Joined: 15 Oct 2004
Posts: 528

philippines.gif
PostPosted: Wed Feb 22, 2006 11:42 pm    Post subject: Reply with quote

Sub SPI_idle 'Idle Mode of the pins
Cs = 1
Mosi = 1
Clk = 1
End Sub


Sub Snd_cmd(byval Lcdcmd As Byte)
Cs = 0
Clk = 0
Nop:Nop
Mosi = 1
Nop:Nop 'Commands = 1
Clk = 1
Shiftbits Lcdcmd
SPI_idle
End Sub

'************************************************************

Sub Snd_data(byval Lcddata As byte)
Cs = 0
Clk = 0
Nop:Nop
Mosi = 0
Nop:Nop 'Data = 0
Clk = 1
Shiftbits Lcddata
SPI_idle
End Sub

'************************************************************

Sub Shiftbits(dab As Byte)
Local X As Byte
For X = 1 to 8
Clk = 0
Mosi = Dab.7
Clk = 1
Shift Dab, Left, 1
Next X
End Sub


Try this, have not tested this but this should work. Added NOP for some delays, you also need to call on SPI_idle at the start of your program to make sure the SPI pins are on the correct state. Look at the datasheet serial waveforms of the LCD controller for details.
Back to top
View user's profile
ATIU

Bascom Member



Joined: 15 Oct 2004
Posts: 528

philippines.gif
PostPosted: Thu Feb 23, 2006 5:58 am    Post subject: Reply with quote

This should be simpler and smaller

Dim Cmd As bit 'Cmd = 1 if command, else Cmd = 0, set before calling Snd_lcd
Dim Lcddata As byte

Cs = 1 'Set the pin correctly
Mosi = 1
Clk = 1

'************************************************************

Sub Snd_lcd(byval Lcddata As byte)
Local X As byte
Cs = 0
For X = 1 to 9
Clk = 0
If X = 1 Then Mosi = Cmd Else Mosi = Lcddata.7
Clk = 1
Shift Lcddata, Left, 1
Next X
Mosi = 1
Cs = 1
End Sub
Back to top
View user's profile
superbrad

Bascom Member



Joined: 18 Sep 2005
Posts: 62

usa.gif
PostPosted: Thu Feb 23, 2006 8:45 am    Post subject: Reply with quote

I tried it ... No response at all from the LCD, same as my other attempts. I attached a JPEG of the SPI serial waveform from the datasheet. Maybe it'll shed some light on the problem?

Thanks for the suggestion though ATIU, I like your algorhythm a lot more than mine, it's a lot cleaner. It looks like it should work, but ... who knows. Maybe the LCD is bad?

Brad

"If you ever get the chance to choose between regular heaven and pie heaven, choose pie heaven. It may be a joke, but if not, mmm boy!" - Jack Handy
Back to top
View user's profile AIM Address Yahoo Messenger MSN Messenger
dbvanhorn

Bascom Member



Joined: 24 Feb 2006
Posts: 2

blank.gif
PostPosted: Fri Feb 24, 2006 4:37 pm    Post subject: Reply with quote

You also have to observe the timing requirements, which may not be completely documented.

I would do a couple of things here:
1: write your own SPI-like function. The output is pretty simple, put the data on the data pin, then take clock from low to high, and back to low.
Having written that, insert maybe 100uS delays between events.

2: insert 10mS delays between every byte sent.

LCDs are fun this way, if you go too fast, or you miss something in the init, then usually all you get is a blank screen. The docs are usually pretty "sketchy" as well.

I recently finished a project where I was using a larger 15 bit color display to play video with the AVR driving. Coded in assembler though, and even that had to be pushed pretty hard. It's pretty impressive though, watching the thing play videos Smile
Back to top
View user's profile
superbrad

Bascom Member



Joined: 18 Sep 2005
Posts: 62

usa.gif
PostPosted: Fri Feb 24, 2006 6:06 pm    Post subject: Reply with quote

Hi guys, thanks for the replies. I was up until 1 AM last night trying to get it to print out anything and I DID!

But it was in AVR-GCC using somebody else's code. It took me forever, 24 megabytes doesn't download very quick on a dialup connection. And I hate C, so it's not a very permanent solution.

But now I know that the LCD does work (it's not broken).

SO ... Thanks for the suggestions, I will try to revamp my code ... again ...

Brad

"A lie can make it half way around the world before the truth can even get its pants on." - Winston Churchill.
Back to top
View user's profile AIM Address Yahoo Messenger MSN Messenger
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Feb 24, 2006 6:08 pm    Post subject: Graphical display.... Reply with quote

www.achatz.nl is selling the same display and it is running with Bascom-AVR on a STK500.

If you want to have a look at it check http://members.home.nl/bzijlstra
and go to the bottom of the WebTiger tutorial

Have fun
Ben Zijlstra
Back to top
View user's profile Visit poster's website
superbrad

Bascom Member



Joined: 18 Sep 2005
Posts: 62

usa.gif
PostPosted: Fri Feb 24, 2006 10:17 pm    Post subject: Reply with quote

Hey Ben, that's flippin' sweet! Is the source code available anywhere?
Back to top
View user's profile AIM Address Yahoo Messenger MSN Messenger
123ralle

Bascom Member



Joined: 20 May 2005
Posts: 7

PostPosted: Mon Feb 27, 2006 5:18 pm    Post subject: Reply with quote

@Ben

I can't find the display on their website.
Do you now, when it will be in stock ?

regards,
Ralf
Back to top
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Mon Feb 27, 2006 10:19 pm    Post subject: Display www.achatz.nl Reply with quote

Think you have to wait a few days.

Or a mail to info@achatz.nl

Have fun
Ben Zijlstra

BTW I changed the picture in the WebTiger-tutorial....
Back to top
View user's profile Visit poster's website
superbrad

Bascom Member



Joined: 18 Sep 2005
Posts: 62

usa.gif
PostPosted: Wed Mar 01, 2006 6:29 pm    Post subject: Reply with quote

All right guys, here's the scoop:

I finally got the LCD to initialize correctly. The problem I finally found after hours and hours of hitting my head on the corner of a brick wall was that I needed to initialize the SPI pins correctly on LCD powerup. It's still all bit banged.

I really want to thank everyone that helped on the forum. You guys are awesome.

And on to the next part of the show: Bitmaps! I've connected an MMC card to the hardware SPI and batta bing! Ok, it actually took me a long time to get this part working as well (I worked on this project from dawn til dusk last Saturday), but it can read a 24 bit color bitmap and display it on the LCD screen. I'm still having a few palette problems (the images come up very blue) but the picture is clear and I'm very happy with it. $20 for the LCD, $18 for the M128 and breakout board, and $13 for the MMC card ... Very pleased with the outcome for a measly $50!

I still haven't set up any routines to implement text on the screen. Ben sent me some ideas and I'll be looking into a good way to do this.

I'll post some pictures tonight (I'm posting this from work ... i know, tsk tsk ...), and if anyone wants the code I'd be willing to upload it to the forum as well. I'm probably going to start a web site to post my projects on pretty soon.

Brad

To an engineer, the glass is never half empty. It isn't ever half full either. It was simply just made twice as big as it needed to be.
Back to top
View user's profile AIM Address Yahoo Messenger MSN Messenger
123ralle

Bascom Member



Joined: 20 May 2005
Posts: 7

PostPosted: Thu Mar 02, 2006 4:35 pm    Post subject: Reply with quote

Hello,

i'am interested in the code.

regards,
Ralf
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum