Fork me on GitHub

Project Notes

#216 OSHChip/LEDx16Module

Driving an SPI LED module with the OSHChip.

LEDx16Module_build

Notes

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);
spi.frequency(1000000);

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

led_module_cs = 0;
spi.write(data);
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.

Construction

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

LEDx16Module_bb

LEDx16Module_schematic

LEDx16Module_build

Credits and References

About LEAP#216 OSHChipSPI
Project Source on GitHub Return to the LEAP Catalog

LEAP is just 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.

Projects are often inspired by things found wild on the net, or ideas from the many great electronics 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.

For a while I have also included various scale modelling projects here too, but I've now split those off into a new repository. Check out LittleModelArt if you are looking for the modelling projects!

Project Gallery Notebook LittleCodingKata LittleModelArt More on my blog