Lab #7: Using serial communications (SPI controlling an LED driver)

This lab builds on the PWM and RGB LED work we’ve done earlier. The goal is for you to be comfortable with SPI serial communications. This particular device will be one foundation of the Simon game.

APA102 Strip

APA102 Strip.

Simon Board

Simon Board with APA102.

Part 0: Get some APA102C RGB LEDs

In the old days, students would have to cut a piece of APA102 strip. Starting in 2021, use the prefabricated Simon PCB, which has 4 LEDs arranged in a circle.

SPI control

Let’s review serial communications. Also take a look at the documentation for the APA102 device.

  1. What are the two categories that all forms of serial communication can be divided into? In which category is the APA102?
  2. What are two major differences between SPI and I2C serial communications? Which would be best for controlling a large string of LEDs?
  3. The APA102 uses a modified form of SPI to enable control of multiple LEDs without needing a separate "chip select" line for each one. Briefly describe how it does this.
  4. How big (in bytes) is the SPI message required to set the color of a single APA102? How big (in bytes) is the SPI message required to set the color of each LED in a chain of 4 devices?

Now let’s review the characteristics of the serial control hardware block in your MSP430s, the USCI.

  1. How many USCI blocks does the g2553 device have? What three protocols can be controlled by the USCI?
  2. On your launchpad, one of the serial modules is used to make a UART connection with the host computer (via USB). Which pins and which USCI module are used for this?
  3. Which pins can be used for the SPI clock and master-out-slave-in (MOSI) data?

For the lab

The Simon PCB has 4 APA102C RGB LEDs connected to a MSP430 using appropriate SPI clock and COPI lines. Three sample files are provide for you: main.c, rgb_interface.c, and rgb_interface.h. These files demonstrate configuration of the USCI module so that the SPI clock frequency is within the acceptable range for the APA102C, and the data communication clock edges are proper. These examples also serve as an example of how to do modular programing. The current interface for LED control should be abstracted at least one more level as part of this lab.

The goal for the lab is to achieve a moving, color cycling effect. You should modify the API so that the main.c function can simply call a set_temperature(int LED1_temp, int LED2_temp, int LED3_temp, int LED4_temp) function. Here, the value of “temperature” should map to a color in the RGB space in a sensible way. The wikipedia page on color temperature includes the diagram to the right. The goal is that your function makes a nice 1-dimensional mapping through 3-dimensional color space. (It doesn’t have to correspond to temperature in Kelvin or wavelength or whatever other logical things might be imagined.) This lab builds on the previous one in the sense that hopefully you already figured out some RGB values that make a nice rainbow! Special Case: The value 0 of temperature should mean the LED is off!

Then configure the logic in main.c such that each LED should cycle one step behind the previous one so that the rainbow appears to move upward. Use the _250ms watchdog timer interrupt for timing, and increment the temperature each time step. (This is already set in the current file!) To accentuate the effect of rotating colors, make one LED off (i.e., temperature 0) each time step, and have the LED which is off shift around the circle. You should implement at least 32 levels of color. BUT, the color changes should be distinctly visible. Note: We have noted that different generations of the APA102 LEDs have different color order (GRB vs BRG). Make sure that your code works for your LEDs. If you have different LEDs on your board, you can fix it programatically or by resoldering.

Optional Once you have finished the rest of the lab, come back to rgb_interface.c and convert it to use th USCI TX interrupt.

Planckian Locus of Color Space

Wikipedia Color Space.