 Hello and welcome to the STM32L for MOOC online training. My name is Andre Barat and I will guide you through the LCD hands-on session. The LCD or liquid crystal display is made of several segments, pixels or complete symbols which can be turned visible or not. Each segment consists of a layer of liquid crystal molecules aligned between two electrodes. When applying a voltage across the liquid crystal greater than a certain threshold the segment becomes visible. The voltage applied to the segment must be alternated to avoid an electrophoresis effect in the liquid crystal which can end up degrading the display. The LCD peripheral is a digital controller and driver for a monochromatic passive liquid crystal displays featuring 8 common terminals and up to 44 segment terminals. In summary this peripheral allows to drive up to 176 or 320 LCD pixels depending on the number of common terminals used. In our case we will communicate with a low power LCD assembled on L4 Discovery Kit which has 4 common terminals and 24 segment terminals. The embedded LCD features 6 digits with 14 segments each, dots in between each digit and the bar graph with 4 segments. The main goal after proper configuration of the LCD in STM32 QBMX is split in 2 tasks. The first we will turn all visible pixels on LCD and the second we will focus on the individual work with the pixels. We will try to display a running snake on the bar segments. And to do so we will start our STM32 QBMX to configure and generate code for the LCD and necessary GPIOs. With the STM32 QBMX opened we start a new project, we type our part number and we start the project. When the new project is loaded we are going to the peripherals tab, we are going to select LCD and here we need to select with in which mode we want to operate. The dirty cycle ratio is defined as the inverse of the number of the common terminals on a given LCD. As you recall the L4 discovery board has 4 common terminals, so we need to select one fourth dirty cycle mode. As it can be seen by the highlighted pins the common lines are the PA10, PA9, PA8 and PB9. We also have to assign all segment signals to pins, unfortunately this has to be done manually, so all the 24 signals have to be selected from the tab here. I would recommend you to pause the video right now and follow the instructions that you can see on the screen. After finishing selecting all the lines we are going to our clock configuration. Here for our system clock we are going to set it as default. LSD input clock must be stable in order to obtain accurate LCD timing. In our hands-on we are going to use LSI oscillator as LSD input clock source. After clock configuration is done we are going to configuration tab, LCD and here we are going to select the right parameters. A mandatory parameter is the frame frequency. It must be selected within roughly the range of 30 Hz to 100 Hz. This is a compromise between power consumption and acceptable refresh rate. Frame frequency is obtained from the following formula. We decide to generate our frame frequency equal to 31 Hz, which means that we need to select the clock pre-scaler to 4. The divider we set as 16, the contrast control will be set to 3.26 volt. I forgot to set the bias to 1.3 and the pulse-on duration we have to set it to 4 CKPS. So after the configuration is done we just need to save our project and generate our code. Once again the toolchain has to be selected, which is system workbench for STM32. We press OK and now we are ready to generate the code. Before proceeding to the code, let's briefly describe how the architecture of the LCD display looks like. Each pixel has connected to terminals, command and segment. Considering the bar graph in focus on the second part of the hands-on, the first and third pixels are connected to the command terminal 3, yet they are separately driven. The first is driven by segment 8 and the third segment 25. Analogically, the same applies for the second and fourth pixel. This configuration topology allows easy address of single pixels on the display combining command and segment terminals. So, how do we communicate with a single pixel? Each command terminal has its own dedicated register. The content of the register corresponds to the state of each individual segment. The LCD controller is able to drive up to 44 segments, as a single register is only 32-bit long to address all the 44 segments 2 registers will be needed. Therefore, we will have LCD RAM register 0 and 1 to address the LCD COM 0. So, to set a pixel visible, it's necessary to set the corresponding bit in the related command terminal register. In case we want to make visible the first segment of the graph, we need to connect the command terminal 3 segment 8. Which means we need to write 1 on the 8th bit of the LCD RAM register 6. It is advised to use bit masking to do so as it prevents rewriting active segments. Without refreshing the LCD, the LCD controller driver will display the old data. If we don't refresh the LCD, the value displayed on the LCD will be the old data. So, every time that we successfully load new data, we need to refresh the LCD. After this introduction, let's start our system workbench for STM32 and start coding. After the code is generated by STM32 Cubemix, we can see that all peripherals have been initialized. If we wish to inspect and double check the configuration of the LCD, we just need to hold the cursor over it. For simplicity, we will rename the constants included in the header file as it makes our hands on easier to understand. The location of the embedded LCD RAM registers is drivers, HAL, include HAL LCD. In the middle of the file, we can find the registers and we need to copy the appropriate ones. Each command terminal is defined in two registers. In this case, command 0 is defined in LCD RAM register 0, and the most significant bits are defined in the LCD RAM register 1. The same is applied for the rest of the command terminals. To be sure that we are setting the proper byte, the syntax can be written as a shift of 1 byte to the 8th and 25th position. We are going to start our example by clearing all the registers contained in the LCD. In order to light up the desired segments, we need first two. Load the registers by using HAL LCD right. This function has four parameters, the pointer to the device handler, the command line we want to address, the register mask to prevent undesired writings, and finally the content to be updated. The mask we are using in this case is just once, as it is irrelevant the content stored before. Now we are going to apply the very same approach for the most significant bits of the command terminal 0. We will configure the rest of the command terminals in the same way as we configured the command terminal 0. The second step is to refresh the signals which drives the LCD. The segments will become visible according to the registers content. The update display function just uses the peripheral handler. To finalize coding our first example, we will make all segments visible for one and a half seconds and we will proceed to clear it. Now we just need to build and debug our project. We will launch our program and as you can see, all the segments are visible for one and a half seconds. The second task is focus on individual work which segments and we will display a rating stake on four bar graph. This task is also split in two moments. The first we will light up each segment step by step from down to up and then we are turning them off down to up as well. Let's start by turning on the bottom segment on the graph. We will need to write on the command terminal 3 and segment 8. The mask we are using reverts the stored value and enables us to write the desired one. Then we will proceed to refresh and add some delay. We extend the same procedure to the remaining three bars and this section of the code will light up one bar at a time. Now we will replicate the previous lines yet this time we will load the register content with the value 0. This will turn off sequentially the bar graph. To finalize the second example, we will just need to build and debug the program again. Launching the program, we will see that all the segments being turned on and then an endless running snake will be displayed on the bar graph. Thank you for your attention.