15. Arduino for Production!! How to Interface an LCD on the ARM Microcontroller Part 1
Share
This page is reserved for the beginning of the LCD Tutorial.
So far, we have only delved into the GPIO side of microcontroller circuits and programming. Hang on, because we are going to delve in deeper, but not more complicated. We will connect an LCD to the ARM microcontroller. LCD communication is no more complex than lighting up LEDs and testing button presses.
The only difference to turning on and off an LED and displaying information on an LCD is the way to turn on and off the pins. That is not to say we wont get into some complicated topics, but it's nothing we cant handle.
The LCD that I will use is of the standard flavor: 5 volt, 16 characters x 2 lines which contains 7 data pins, an enable pin, a read/write pin and a register select pin. The LCD can be used in either 8-bit mode, or 4-bit mode. In 4-bit mode, only 4 of the data pins are needed, freeing up four potentially important microcontroller pins that you could use later on.
But how are you going to use a 5 volt LCD? I thought the STM32 ARM microcontroller uses a 3.3 volt level! That's a great question, but not a show stopper. First, the ST-Link programmer has a 3.3 volt output as well as a 5 volt output. Additionally, the STM32 microcontrollers have GPIO pins that can tolerate 5 volts, but be careful, they need to be setup correctly (don't use the internal pull up/down resistors).
Let's get into the most complicated subject, delivering a byte (a character to communicate to the LCD to show on the LCD's screen) to disparate pins and ports. Unfortunately, the STM32 has functions on each pin that I will need later, and the 5 volt tolerant pins are all over the place, so we will need to scavenge pins that are not in order. In a typical scenario, we would be able to simply deliver a byte to a port that contained 8 bits that assigned to pins from 0 to 7, where each pin of the port in question would receive the byte. As you should already know, a byte, of standard character, has 8 bits. For example, the uppercase letter "A" has a character code (ASCII) of 65 in decimal, or 01000001 in binary notation. Each 1 or 0 is a bit. If we had a set of pins from 0 to 7 on a specific port, it would be almost as easy as saying: PORTC = BYTE. Don't fret, by learning this new technique, you will have quite a "bit" of power when doing bit manipulation and nothing will get in your way.
Identify 5v Tolerant Pins
Now we know where in deep with this disparate pin and port thing, lets take a look at the ARM STM32 microcontroller and see what pins we can use. First, we need to identify all of the pins that are 5v tolerant. Generally, we will be outputting from the pins to the LCD (sending characters, etc), but we will need to read from those pins to determine if the LCD is not busy (this is not actually necessary, but it is good practice).
We can find these pins on the on the STM32F030 Datasheet. Page 27 lists the abbreviation that will be shown next to the pin. The abbreviation we are looking for is FT and FTf. FT is 5 volt tolerant and FTf is 5 volt tolerant and FM+ capable. FM+ just means Fast Mode Plus and is capable of bit rates of 1 Mbits/s. That is to say, with the FM+ configuration, that pin can turn on and off one million times in a second. This aside is rather important to discuss now because you may need these FM+ pins for another purpose, so we will make sure not to identify those pins at the moment.
Back to the 5v tolerant pins. This is where you are going to get really familiar with the I/O pins on the STM32 ARM microcontroller. The table of the pins and their respective functions starts on page 28 and ends on page 33 of the STM32F030 Datasheet. All of the STM32F030 packages are listed on this table and show the pin number in that package's column. A package is the form factor of the chip and how many pins it contains. We will be concerned with the LQFP64 chip in this video and this is the general outline of the chip that I am using in the video. Since we are proper designers and developers of circuits, we can work off the bare chip. The breakout that I use for prototyping is simply this chip soldered onto a PCB that breaks each pin to a header that is easily plugged into a breadboard.. If you are working with a different chip, just make sure you are looking at the correct column. I will mark the 5v tolerant pins.
Right off the bat, we see that pins 5 and 6 are labeled FT. Those pin belong to PF0 and PF1 and also serve as the the first I2C. The next FT pins 18 and 19, belonging to PF4 and PF5 are found on page 29. The next pages, page 30, 31 and 32, we see a whole slew of 5v tolerant pins. Remember, we are only focusing on the FT, not the FTf for the moment. On page 30, pins 28 to 38, are 5v tolerant with the exception of pins 31 and 32 which are power pins. These pins correspond mainly to Port B and a couple to Port C with PB2, PB10, PB11, PB12 PB13, PB14, PB15, PC6 and PC7. The main alternate functions for these pins are timers, USART (3rd USARD specifically), SPI 1 and 2, I2C 1 and 2 and a couple of EVENTOUTs. On page 31, all of the pins 39 to 50 are 5v tolerant GPIO except for pin 47, reserved for Ground/VSS. These pins fall into the Ports C, A and F and are PC8, PC9, PA8, PA9, PA10, PA11, PA12, PA13 (SWDIO), PF6, PF7, PA14 (SWCLK) and PA15. We want to steer clear of the programming pins SWDIO and SWCLK. These pins have alternate functions of USART 1, 2 and 4, I2C 1 and 2, some timers, and a few EVENTOUTs. And finally on page 32, pins 51 through 57 are 5v tolerant and are mainly on Port B, Port C and Port D. Specifically, they are PC10, PC11, PC12, PD2, PB3, PB4 and PB5. The alternate functions for these pins are the upper USARTs 3, 4 and 5, more timers, SPI 1 and I2C 1.
As you can see, the ports and their pins are all over the place. Fortunately, we have a couple of things on our side, the knowledge to deliver bits where we want, and the alternate functions are very versatile. So lets pick the pins that we will plug into the LCD data connections.
[[TUTORIALMENU(tutorial-arm" frameborder="0" allowfullscreen>