Fork me on GitHub

Project Notes

#216 OSHChip/LEDx16Module

Driving an SPI LED module with the OSHChip.



How easy is SPI with the OSHChip? I thought I’d find out by first controlling a module that has a very basic SPI-ish slave interface.

I’m using the LEDx16Module that I designed in the KiCad like a Pro course from Tech Explorations. It has dual 74HC595 shift registers that can be driven with SPI to control 16 onboard LEDs.

SPI Driver Options

It seems there’s at least three options:

  • use the SPI class that is part of the mbed standard library
  • go direct to registers for SPI control
  • pick one of the other SPI libraries out there, for example SPI_Demo_Nano that implements an SPI class very similar to the Arduino SPI library.

I’m going to code this one with the mbed online compiler, so I’ll start with the first option.

Configuring and Using SPI

I’ll probably publish my project on mbed, but for now the source is all here. The demo code is largely copied from the LEDx16Module demo.

It sets SPI for an 8 bit data frame, spi mode 0, 1MHz clock rate:

// Setup spi: 8 bit data frame, spi mode 0, 1MHz clock rate
spi.format(8, 0);

And 16-bits worth of data (for the two shift registers) is sent in two write operations:

led_module_cs = 0;
spi.write(data >> 8);
led_module_cs = 1;

Two quirks that I still don’t fully understand:

  • I thought IO should be able to set a 16-bit frame with format(16, 0) but I couldn’t get it to work.
  • even though SPI.write takes an “int”, it still only sends the 8 lower bits, hence the transfer in two calls

Also note I haven’t resorted to bulk transfers using the transfer method in this case, since I’m not sending large quantities of data, and not expecting any reply.


There’s not much to the build. Basically hook together three modules:




Credits and References

Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.