Skip to content

Rishaan-code/ECE319K-Lab6-SPI-LCD-Display

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

ECE319K Lab 6 — SPI LCD Graphics and String Conversion

Overview

This project implements SPI communication with an ST7735 LCD display on the MSPM0G3507 and builds a custom integer-to-string conversion library in ARM assembly. The system renders text, bitmap images, and fixed-point numbers directly to the 128x160 16-bit color LCD using register-level SPI configuration.

This lab was the foundation for the SPI display pipeline used in Lab 7 and Lab 8, where the same ST7735 driver displayed real-time ADC measurements and UART-received position data.

How It Works

SPI Communication

The ST7735 LCD communicates over SPI using PB8 (clock) and PB9 (data). Every pixel on the display is a 16-bit color value sent as two sequential SPI bytes. Drawing a single character requires outputting 40 pixels (5 wide x 8 tall), meaning 80 SPI byte transfers per character. This was verified with a dual-trace oscilloscope on PB8 and PB9 in main4.

Dec2String — Integer to String Conversion

A custom Dec2String function converts unsigned 32-bit integers to ASCII strings without using any standard library functions. This was implemented using integer division and modulo arithmetic, with the division optimized using a custom udivby10 routine written directly in ARM assembly (StringConversion.s). The assembly implementation avoids the overhead of the compiler's generic division routine.

Tested against these values: 0, 7, 99, 100, 654, 999, 1000, 5009, 9999, 10000, 20806, 65535

LCD Demo Sequence

The final main demonstrates three display modes triggered by button press:

Screen 1: Text rendering with special characters "Lab 6 Spring 2026" "¡Hola!" "Bienvenida al EE319K"

Screen 2: Bitmap rendering A 40x160 pixel logo bitmap stored in images.h gets drawn using ST7735_DrawBitmap. The bitmap is stored as a const uint16_t array of 16-bit RGB565 color values in flash memory.

Screen 3: Fixed-point number display Integer values get displayed alongside their fixed-point representation in X.XXX format, demonstrating the same formatting used in Lab 7 for distance measurements:

printf("%u",TestData[i]);
printf("d=%1u.%.3u cm", TestData[i]/1000, TestData[i]%1000);

Hardware Configuration

Component Detail
Microcontroller TI MSPM0G3507 (80 MHz)
Display ST7735 LCD, 128x160, 16-bit color
Interface SPI, PB8 (clock), PB9 (data)
Color format RGB565, 16 bits per pixel
Button LaunchPad S2 for screen transitions

SPI Timing

Measured with oscilloscope on PB8/PB9: One character = 40 pixels = 80 SPI bytes Each SPI byte transfer visible on scope SPI clock frequency set by CLKDIV register Drawing one character takes approximately 8µs at 80 MHz

This measurement directly answered the Lab 8 deliverable question comparing SPI speed to UART -- SPI transfers one byte in microseconds while UART at 2000 bps takes 5ms per byte, making SPI roughly 5000x faster for this specific configuration.

Files

File Description
Lab6Main.c SPI demo, bitmap display, string output
images.h Bitmap data stored as RGB565 uint16_t array
StringConversion.h Dec2String function prototype

Test Structure

  • main0 -- tested udivby10 assembly routine in isolation
  • main1 -- ran Lab6Grader to verify SPIOutCommand, SPIOutData, Dec2String
  • main2 -- tested Dec2String output over UART terminal
  • main3 -- full LCD demo with text, bitmap, and fixed-point display
  • main4 -- oscilloscope measurement of SPI timing per character

What I Learned

The most interesting part of this lab was measuring how long it actually takes to draw one character to the LCD. Every character is 40 pixels and every pixel is two SPI bytes, so what feels instantaneous is actually dozens of hardware transfers happening in sequence. Seeing that on the oscilloscope made the SPI protocol feel real rather than abstract.

Writing Dec2String also gave me a much better feel for how string formatting actually works under the hood. Printf feels like magic until you implement the integer-to-ASCII conversion yourself and realize it is just repeated division and modulo.

The SPI knowledge from this lab fed directly into Lab 7 and Lab 8 where the same display driver showed real-time ADC data and UART-received position measurements from another microcontroller.

About

SPI communication and ST7735 LCD graphics on MSPM0G3507 | Register-level SPI configuration | Bitmap rendering | C | Embedded Systems

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors