Nokia LCD With PCF8833 on STM32

Tutorial on how to drive PCF8833 based LCD display with STM32.

I have two Nokia 6100 LCD displays on stock and I tried them, how they work with STM32. I must say I am dissapointed with speed. another anoying thing is that the LED backlight needs 6V. But I will let you know how to, so that the time I spent, won’t go to waste. I used STM32L476G-Discovery board for testing. Let’s start with CubeMX. We start new project and select our microcontroller. We will select microcontroller and not Discovery board, becase if we select board, all the preipherals will be selected and we don’t need that. We select STM32L476VGTx version of microcontroller and click on Start project:

First we will enable debug:

Next is SPI1 which we will use to drive external LCD display. We will configure it as master and transmit only, since this LCD has no data out pin to be read back to microcontroller:

We need to move SPI pins to PE13 and PE15 since these are conveniently at the edge of PCB. We do this by holding Ctrl and clicking and dragging pin to new position. When moving pins, alternative location colors themselves blue.

We need two more pins for CS and RESET of external LCD. We first click on PE14 and select GPIO_Output:

We do the same for PE12. Next we need to Enter User Label, for easier writing of code. We right click on pin and select Enter User Label:

Rename all four like this:

We will also enable on-board LCD for feedback:

We need to enable segments: 3-6, 8-9, 12-15, 17, 22-35.

Now select Configuration tab and click on LCD:

And enter this values and click OK:

I forgot to change clock. Go to Clock  Configuration tab now and enter 80MHz as HCLK:

It will ask you to use other sources for clock because it can’t configure 80MHz with current ones, just clik OK and it will find a solution:

Now let’s configure SPI1. Go back to Configuration tab and select SPI1 and enter these values:

All we need to do now is to select name, place and IDE for our project and generate it. Inthe menu select Project -> Generate Code. Since the data is not entered it will ask for it before it generates project:Also under Code Generator select Generate peripheral initialization as pair…:

After all is done, click on Ok and it will generate project. When finished click on Open Project it is important to click this since this automaticly imports our project into IDE:

For this project we will need my already written nlcd.h file. You can download it here, right click and Save as. Then drag this file into Inc directory on root of our project:

We also need a few files from Cube repository. First we need to create folders inside our project. Right click on folder named Drivers and Select New -> Folder:

And enter BSP as name for it nd inside this folder create two subfolders named Inc and Src:

From folder C:\Users\…\STM32Cube\Repository\STM32Cube_FW_L4_V1.11.0\Drivers\BSP\STM32L476G-Discovery copy:

  • to Drivers/BSP/Inc
    • stm32l476g_discovery.h
    • stm32l476g_discovery_glass_lcd.h
  • to Drivers/BSP/Src
    • stm32l476g_discovery.c
    • stm32l476g_discovery_glass_lcd.c

We also need to include these files in our project. To do this, we need to right click on project name and select Properties. We go to C/C++ General -> Paths and Symbols Click on Add and add the two directories you see here on screenshot and click OK.Now we add some code to main.c:

We need a few includes:

We need variable in which we tell what color we want on LCD. The colors are coded 565, this means 0xRRRRRGGGGGGBBBBB:

And quite some test code:

Now we compile and upload code to microcontroller. It paints whole LCD with red, green and blue, but it is quite slow. You will notice we didn’t use on-board LCD yet. This is because I used it for debugging, but we don’t need it anymore since I already made nlcd.h. But just for those who would like to know how to use it, here it is:

We need to include BSP files for LCD in our main.c:

And we need to add a few lines of code into main.c (two lines of code):


Thank you for reading!