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

About LEAP#216 OSHChipSPI
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 my personal collection of electronics projects, 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 (IMHO!).

The projects are usually inspired by things found wild on the net, or ideas from the sources such as:

Feel free to borrow liberally, and if you spot any issues do let me know. See the individual projects for credits where due. There are even now a few projects contributed by others - send your own over in a pull request if you would also like to add to this collection.