Lecture 3 - GPIO Review, LCD Screen

Note that for A1, use HAL_Delay(ms) since it's calibrated to actually count time accurately based on its internal clock.

Further, you may just want to use the SYSCLK for now. There's certain clocks that slow down/speed up based on the temperature of the device.

One thing too is that don't use RCC_MSIRANGE_11 (at least for now), since it requires an overvoltage of the clocking mechanism.

Using the LCD Screen

Use [[HD44780.pdf]] and [[NHD-C0220AA-FSW-FTW.pdf]] for using the LCD screen:

Check out [[NHD-C0220AA-FSW-FTW.pdf#pages=5]] for what we cover here. Some tidbits:

How do we write to this thing? See [[NHD-C0220AA-FSW-FTW.pdf#pages=8]]. Essentially, you need to set RS, R/W, ... as described before for the timings described in the chart. You can see the timings in the bottom chart.

We recommend that, at first, you build it slowly, by adding HAL_Delay in many instruction spots in your code. This allows you to try to see if the logic works in a larger timeframe, and then you can slowly remove delays to see where things start to break.

Example

Let's use PA4 as RS, PA5 as R/W, PA6 as E, and PC7:0 as DB:

GPIOA->ODR &= ~(0x3 << 4); //clear both PA4 and PA5, RS RW are low
// can HAL_Delay if we don't meet the t_AS
GPIOA->ODR |= (0x1 << 6); // set PA6 as 1, E high
// potential HAL_Delay for t_{RE}
GPIOA->ODR &= ~(0xFF); // clears the bottom 8 bits
GPIOA->ODR |= (0xFF & DATA); // DATA is some 8 bit quantity
// wait more until t_{DS}, a total of t_{WHE} total from setting our E bit
GPIOA->ODR &= ~(0x1 << 6); // reset the value of PA6 as 0, E low
// maybe delay, either t_{AH} times

Okay we know how to write to it, now what do we write in the DATA part?

See the [[NHD-C0220AA-FSW-FTW.pdf#pages=11]]. Here:

For instance, for 0x30 is 00110000, which says DB5 and DB4 are the only ones high. Use the instruction code if we are sending a command, and the bottom row if we are sending DATA:

So #TODO: