Using Dual MCP23S17 I/O Expander Chips with the Tiva LaunchPad

In a blog post a few weeks ago I showed how I had been using an I/O expander chip with the Texas Instruments Tiva LaunchPad to provide eight additional inputs using a single serial connection. I've managed to increase this to 32 inputs.

Tiva LaunchPad and Dual MCP23S17 Chips Annotated

I did this by using dual MCP23S17 I/O expander chips as shown in the screenshot above. Each chip provides 16 inputs. They can be paired without using any additional GPIO pins on the Tiva LaunchPad than I used with the single 8 bit I/O expander.

Here's a circuit diagram I've drawn up to show how this works:

Tiva LaunchPad and Dual MCP23S17 Chips Circuit Diagram

I've written a small C program (download link below) showing how to configure and query the I/O expander chips with the Tiva LaunchPad. The software configures both I/O expander chips as input and then continually reads their values.

The input values are read as a single byte at a time. This single byte corresponds to a set of 8 input pins. Pin GPA0 corresponds to the first bit, GPA1 corresponds to second bit, GPA2 corresponds to third bit, and so forth.

As an example, if GPA2 and GPA5 both have an input voltage applied, with the remaining inputs grounded, the value read for GPA will be 36 (00100100 binary). This is shown graphically below.

I use Texas Instruments' Code Composer Studio for development. I found a good way of testing is to set a breakpoint after the values are read off the chips. The variables used to store these values can easily be added to a watch window. Configuring the breakpoint to update all windows, instead of halting, gives you instant feedback on the current value of the pins on each chip.

MCP23S17 Chip and Code Composer Watch Window 1

As you switch inputs from ground to power you'll see the corresponding values in the watch window change:

MCP23S17 Chip and Code Composer Watch Window 2

If you're interested in taking a look at this program, feel free to download the source here. As mentioned, I used TI's Code Composer Studio for development and debugging, but the code can be easily viewed with any text editor.

So... This is great, but what's the point?

I know what you're thinking: "This is awesome! But, why do you need this?!". Happy to explain.

One of the projects I've been working towards is to design a simple synth with an ARM Cortex-M chip at the heart of it. If you've been following my past projects you might recall that I have a 16 bit audio output DAC working with my Tiva LaunchPad. Since then, I've been focusing on inputs. I want the synth to have at least a two octave keyboard.

A two octave keyboard has 25 keys. This means 25 input lines just for it. The Tiva LaunchPad exposes 43 GPIO pins of its ARM Cortex-M4 processor. Considering 25 pins for the keyboard, four for the DAC output and additional pins for input knobs and switches I'd quickly be approaching the 43 pin limit. Not to mention, I'd prefer to leave my options open for expanding the number of keyboard octaves.

The Tiva LaunchPad interfaces with these MCP23S17 I/O expander chips using only 4 GPIO pins. I'm only using two 16 pin chips, but the three bit addressing these chips provide should allow me to use as many as eight I/O expanders, giving me 128 inputs without using any additional Tiva LaunchPad GPIO pins.

As mentioned, I want at least a two octave keyboard for my ARM Cortex synth project. I recently purchased a broken Rock Band 3 Pro Keyboard from EBay for a sweet $12.99 in hopes of using the keyboard parts of it for my synth project. I've started working on this.

Rock Band 3 Pro Keyboard Disassembled

I hope to have more to report on hooking up a keyboard to these I/O expander chips soon, and making progress on my synth.

Date: March 1st, 2017 at 8:43pm
Author: Terence Darwen
Tags: Embedded, Tiva LaunchPad, TM4C123G, ARM Cortex-M4, Microchip MCP23S17, I/O Expander, Synth Project, Sabbatical

Previous Next