Jump to content

Hardware SPI working with the Nokia 5110 LCD

Recommended Posts

I got hardware SPI working with the Nokia 5110 LCD.

I used a GPIO for the chip enable, and an interrupt for bringing CE high after transmission.

I've attached the code below and a small graphics library that I put together from various sources on the web.


One thing I found confusing was there seems to be no interrupt flag set when the SPITXBUF empties.

So in the situation like this one where the Rx of the SPI is not even being used, to get the interrupt to work

you still use the Rx ISR.


Here is my interpretation: Write data to SPITXBUF data shifts through SPIDAT and is transmitted out SPISIMO,

simultaneously the same data is shifted into SPIRXBUF and SPI INT FLAG is set. Then you use the Rx ISR to read

the SPIRXBUF and that clears the SPI INT FLAG.


Is this correct?

Also the documentation on the FIFO is somewhat vague for the inexperienced.

How would I go about using the FIFO for this example?


Here is a short video:





Link to post
Share on other sites
  • 1 year later...

I am a newbie. Trying to get the Nokia 5110 lcd to display text on the C2000. When I tried using this code I kept getting the error, "unresolved symbol _SPI_write8, first referenced in ./nokia5110.obj". Any idea why this would be? Thanks for posting your code. Hopefully I can get it to work!

Link to post
Share on other sites
  • 2 weeks later...



You need to make sure the spi.h header file you are linking to contains the SPI_write8 function.

If you look in your controlSUITE install the device support folder for the f2820x devices , latest version v220, f2802x_common,

than the includes file, the spi.h file in there has the function you need. Either copy the function into the file you are linking to or replace 

the file with the newer one, then you should be good. I think the earlier contolSUITE was missing the SPI_write8 function for some reason.


As far as the wiring look in the nokia5110.h file and the pin out is in the 1st few lines of code:

#define nokiaVcc     GPIO_Number_28    //connect to pin  J1_3 on c2000 LP board
#define nokiaSce     GPIO_Number_34    //connect to pin  J1_5 on c2000 LP board
#define nokiaRst     GPIO_Number_29    //connect to pin  J1_4 on c2000 LP board
#define nokiaDc      GPIO_Number_4     //connect to pin  J6_5 on c2000 LP board
#define nokiaBlight  GPIO_Number_5     //connect to pin  J6_6 on on c2000 LP board
#define nokiaMosi    GPIO_Number_16    //connect to pin  J6_7 on on c2000 LP board SPISIMOA
#define nokiaClk     GPIO_Number_18    //connect to pin  J1_7 on on c2000 LP board SPICLK

Hope this helps


Link to post
Share on other sites

Thank you for sending a very thoughtful response. Unfortunately even after I went through your comments I continued to have the error. Additionally, the warning says, "SPI_write8 declared implicitly." Do you think that I need to predefine a symbol (Project -> properties -> Build -> C2000 Compiler -> Advanced Options -> Predefined Symbols)? I read another post that used this tactic (http://www.forum.c2kcentral.com/topic/153-c2000-launchpad-timer0-problem/). Not certain what I would define it as. Any idea?

Link to post
Share on other sites

Finally after going through and changing each spi.h file to the updated version...so that each one included the following lines of code at the bottom:


//! \brief       Writes a byte of data to the serial peripheral interface (SPI)
//! \param[in] spiHandle  The serial peripheral interface (SPI) object handle
//! \param[in] data        The data value
inline void SPI_write8(SPI_Handle spiHandle,const uint16_t data)
    SPI_Obj *spi = (SPI_Obj *)spiHandle;

    // set the bits
    spi->SPITXBUF = (data & 0xFF) << 8;


} // end of SPI_write() function


I eliminated the SPI_Write8 error! Thanks a million Tim. However, I haven't seen the LCD come to life yet. Still troubleshooting. I will keep you posted.

Link to post
Share on other sites

My apologies for posting to the other thread. I will stick to this one.


I realized after doing another tutorial (http://fortytwoandnow.blogspot.com/2012/08/c2000-piccolo-blinking-led.html)%C2'> I was missing one important component. I had deleted the 28027_RAM_lnk.cmd which made my LCD turn off as soon as I pressed "resume."


This is an important based on the following lines of code:

#ifdef _FLASH
    memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);


However, after adding this command file back in I am now getting errors related to having available memory. I have attempted to eliminate unnecessary header files, but I think I am down to what is necessary. In addition to the default settings I have added:


Project ->  Properties -> Build -> C2000 Compiler -> Include Options
Project -> Properties -> Build -> C2000 Linker -> File Search Path


After reading the RAM cmd file I also tried adding the header linker command file (<base>\DSP2802x_headers\cmd) directly to the project, but that didn't seem to work. Ideas?

Link to post
Share on other sites

Are you running this out of Flash or RAM?


Project -> Properties -> Build configuration Flash [Active].


You need this linker cmd file: F2802x_generic_flash.cmd


Browse to it from the Project CCS General tab at the bottom where it says linker command file.


In ControlSUITE -> Development Kits -> C2000 Launchpad -> f2802x_common -> cmd


fingers are crossed.


Link to post
Share on other sites

I checked Project -> Properties -> Build, but only found two options for configuration: “Debug” and “Release”. I am currently using Debug. I tried using "Release", but this action caused the include file "C:\ti\controlSUITE\device_support\f2802x\v210" in the Project Explorer to be removed, causing errors.

I added F2802x_generic_flash.cmd into the Project Explorer  (with the 28027_RAM_lnk.cmd simultaneously being in the Project Explorer). After pressing debug I received many errors, such as


"#10263 BEGIN memory range has been exceeded"

"#10264 #10264 ROM memory range overlaps"


Based on the second error it occurred to me that maybe the 28027_RAM_lnk.cmd should be deleted and replaced with the F2802x_generic_flash.cmd. I did this and it debugged without error. However, when I pressed “resume” the backlight turned off and I also received a message,


‘Can't find a source file at “C:/controlsuite_gitorious_dev/device_support/f2802x/version/f2802x_common/source/F2802x_DefaultIsr.c"  Locate the file or edit the source lookup path to include its location.'


This is the exact same thing that was happening in the past when I deleted the “28027_RAM_lnk.cmd” from the Project Explorer, which makes me think that it is necessary to keep this file.


I tried clicking "Locate File" and added a source folder to my desktop with the F2802x_DefaultIsr.c code inside. This didn’t do anything.

Is F2802x_generic_flash.cmd necessary? I didn't use it in the simple blinking light example problem (http://fortytwoandnow.blogspot.com/2012/08/c2000-piccolo-blinking-led.html). Not really certain where to go from here. I might try deleting header files again. Any suggestions?

Link to post
Share on other sites

AHA! Tim you were right again. After arduously trying to reduce the size by going through each header file...without success....I then decided to replace the 28027_RAM_lnk.cmd with F28028.cmd from C:\ti\controlSUITE\device_support\f2802x\v210\f2802x_common\cmd. Why this one works and the other doesn't....I don't know. But I'm going with it. I now have scrambling letters on my screen, but I am just happy to see something! Now to get that scrambled mess into a message. Will keep you posted.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...