Skip to main content

How to Assign Roles to imp Pins

Make the best use of the imp pin mux

Editor’s Note This article was written with the imp001 and imp002 in mind. Neither are now available for commercial use. Their replacements in commercial products, the imp003, imp004m and imp005 modules, offer a far more extensive array of pins and therefore require little in the way of pin assignment planning as outlined below.

Every one of the imp’s pins is a user-configurable GPIO, but most of them do much more than just toggle on and off. Before you start laying out the schematic for your connected device, it’s important to decide on what job or jobs each of the imp’s pins will do. Start by reviewing the imp pin mux for your chosen imp type.

While all of the imp’s pins are very capable, certain functions (Wake, DAC) are less available than others (ADC, PWM), so it’s important to prioritize the jobs you assign to your pins. Here’s a good step-by-step approach:

1. If you need to wake on an external event, assign that job to the Wake pin first

Each imp has only one pin that can be assigned to allow a hardware event to wake the imp from deep sleep. On the imp001 and imp002, pin 1 does this job. On the imp003, imp004m and imp005, the Wake pin is pin W. In order to function as a wake source, the Wake pin must be configured in Squirrel. The imp will wake when the Wake pin is high, and can’t sleep again until the Wake pin goes low. If you need multiple interrupt sources to drive the Wake pin, a simple diode-OR circuit can be very helpful:


An interrupt OR Circuit from the Nora reference design

Note Your imp firmware will be completely reloaded and re-run when the imp wakes from a deep sleep state. Variables do not persist through deep sleep, but you can preserve data by using the nv table (on those imps which support it; not all do), or by passing the data to the device’s agent, which can utilize the method server.save().

2. If you need a DAC, you have limited pins to choose from, so assign this job next

On the imp001 and imp002, pins 1 and 5 can be configured as a DAC. If you’re already using pin 1 as a wake source, the choice is very simple: it has to be pin 5. On imp003, pins A and C can serve as a DAC. The imp004m and imp005 have no DAC support.

3. If you need a SPI interface, assign those pins next

If you’re using SPI, you will almost certainly need an extra pin, for Chip Select, so keep another GPIO pin available.

The SPI pins on all imp hardware versions are always capable of several other jobs; sometimes, these jobs will collide. For instance, if you’re using Wake, DAC and SPI on the same imp002-based design, you’ll need some additional circuitry to allow pin 1 to switch jobs when the imp goes to sleep. Take a look at the Lala reference design for one method of solving this design challenge.

4. If you’re using an I²C bus, assign two pins for this next

Each version of the imp hardware has several I²C interfaces available for your use, on pins that are less contested than some of the other possible roles. Remember that multiple I²C devices can connect on the same bus provided they have distinct I²C addresses.

5. If you need PWM outputs, pick these next

6. If you need ADCs, assign them now

Remember that ADCs can be used for single readings, or to run the sampler to record waveforms.

Notes

  • On the imp001 and imp002, if you’re using pins 1 or 2 for a high-speed digital interface (SPI, I²C, or UART), it is recommended that you not use the other for analog IO (ADC or DAC). Pins 1 and 2 are internally routed as a differential pair, and this combination is vulnerable to crosstalk and noise.

  • On the imp003, the same recommendation applies to pins A and B.

7. UART comes next

The imp001 has three UART interfaces. The imp002 has four-and-a-half UARTs: there’s an RX-only interface available on pin B. On the imp003, you have five UART interfaces to choose from, two of which are capable of hardware flow control.

8. Assign GPIOs last

Since any pin can be used as a GPIO, these are the lowest priority. Note that on the imp003, not all pins are capable of triggering a state-change callback; the imp pin mux has the details. On the imp001 and imp002, every pin can trigger a callback on a state-change event.

9. If you’re out of pins, but not out of jobs, there are still options

Very complex devices may need more IO than your imp module has available, but you can still use the imp as the brains of the operation. Here are some options:

  • If you need more GPIOs, consider a shift register. A shift register is the most inexpensive and straightforward way to get more IO on your available pins. Data is clocked into the shift register on a serial line and used to set the states of the output channels in the shift register. Most shift registers can be daisy-chained to get even more channels for the same number of pins. Take a look at the Jane reference design to see an example which uses a shift register to toggle the state of several relays.

  • If you need more PWM channels or GPIOs with state-change callbacks, consider an I²C IO Expander. There are a wide variety of IO Expander parts available which can provide you with additional eight or 16 channels of PWM or GPIO, and talk to the imp over I²C. Take a look at the IO Expander on the Hannah reference design to see how this works.

  • If you need to squeeze many analog signals into a single ADC, consider an analog multiplexer. These parts allow you to use two to four GPIO pins to switch which channel a single ADC is connected to. For example, a device which reads and reports levels from up to eight analog particle sensors might use a single ADC to take readings, and three GPIOs to select each sensor in turn.