Adding pins to processors

01 June 2007

Configuration of a device using a port expander
Configuration of a device using a port expander

In an embedded design, using port expander devices to increase design flexibility avoids the problem of running out of pins on a processor just short of reaching completion

The most sensible choice is to select a processor for what it is good for (processing, peripheral mix) and augment the I/O needs with port expanders (external, expansion devices that drop onto a bus). Reserving two pins for a standard I2C communications bus in exchange for almost any number of extra pins, added as late as necessary, with little impact on hardware or software, summarises the appeal of the I2C port expander.

Functionality
A port expander is any of a class of devices, almost always slave devices, that sit on a communication bus that are sent serial commands to read from or write to I/O pins. The main processor (the one running out of pins) is the communications bus master and does not necessarily require special silicon functionality, although the presence of an I2C peripheral block simplifies the job.

There are simple port expanders and more complex ones with various optional features, but the basic operation is the same. The slave device address is adjusted by strapping pins high or low and then configured by the master, writing commands over the communication bus to define which pins are inputs and which are outputs. During operation, the master writes commands to change the output pins as desired or read the current state of the input pins. In many cases, a change on an input pin can be configured to drive an interrupt line to get the bus master’s attention.

The pins of the port expander act like satellite pins for the processor (master) extending its reach to interact with a front panel or enable/disable other devices in the system. It can also provide additional security features, like continuously monitoring switches connected to the outside of a case and raising an alarm if they are opened. Pins can be added as needed. Alternatively, a device can be put on the board at the beginning, hanging off the I2C bus, which, if the design does not need it, is not installed.

Options and features
While the concept of a port expander is simple, the selection and features offered by the various vendors go beyond the basic pin. The number of I/O pins available for expansion is one variable, but since each device on the I2C bus has to have a unique address (seven bits, with an eighth bit indicating reading or writing) the more possible addresses a singe device can assume, the more of them can be hung on the bus when needed. For every address line, a potential I/O pin is sacrificed. In the offerings of the vendors of I2C port expanders, the range of I/O pins goes from eight I/Os up to 60 on a single device. Most vendors’ devices have at least one or two address lines, while some provide a scheme that offers up to seven address bits, letting unused address lines operate as I/Os.

The choices of drive mode of the I/O pins also differ from device to device. High impedance inputs may offer the option of selecting an internal 4.7kÙ pull-up or pulldown resistor on the input. For the outputs, an open-drain/open-collector option common to all devices may be supplemented with a strong 10mA source/25mA sink option or internal pull-up and pull-down resistors.

Another convenient feature for driving LEDs is a pulse-width-modulator (PWM). Basic port expanders do not have this, but nearly all vendors have one or more device with a few PWMs with support for up to 16 in a single device. The advantage of a PWM is that an LED can be driven with a highfrequency PWM where the duty cycle sets the LED’s light intensity (the higher the percentage duty cycle, the more time the LED is on, and the brighter it looks). The other use of the PWM is to blink an LED with low frequency PWM (0.5Hz to 4Hz). Lastly, if the configuration options support it and the oscillator is sufficiently accurate, a PWM could be configured to provide a timing signal to another device.

Configuration
Some devices provide a chunk of EEPROM that is serially addressable. This replaces an otherwise extra function/extra device in the system, helpful for board identification or other configuration information. The size of this memory is rarely sufficient for data logging.

Another important factor to consider is how the device is configured. For the majority of devices and vendors, the port expander’s configuration (port direction, output state, PWM) is volatile. Every time power is removed and re-applied the device must be set up, i.e the bus master must send the configuration data again. More advanced devices can store the configuration in non-volatile memory in the port expander device and automatically restore it at power-up. A power-on configuration state written into the device, different from the current state, without disturbing the current state can define a failsafe state, with the device remaining in that state until the bus master/processor updates the device.

Design benefits
There are three ways to use port expanders to get maximum benefit: add an I2C port expander to a design for early prototyping and test/debug support with a plan to drop it from the final product; add I2C port expanders to a design without a defined need, as an insurance policy that can be cancelled at any time; aggressively reduce processor pin needs by using I2C port expanders wherever possible.

In the early stages of a project, the application software to monitor and control the different devices in a system is, at best, scant or completely missing. An I2C port expander, with an externally available bus connection, can be used in lieu of a processor (and software) to drive logic lines or monitor the state of logic lines. With this simple device on a board and a relatively inexpensive PC-connected I2C master, a range of debug and verification of hardware can proceed very early in a design. Alternatively, a port expander on the board can serve as a test driver for the hardware, allowing the system to operate in an otherwise normal state while fault states are induced externally through the port expander using the PC-connected I2C master. In either case, when the system is in its final form and it has served its usefulness, the port expander can be dropped from the design.

In the case of getting to the end of a project and running out of pins on the chosen processor, the option of adding a port expander requires a board re-layout. Instead, a port expander with I2C bus connections could be dropped into the board at the start. This might take a square centimetre of space, which is easy to come by if planned for at the beginning.

When connecting the device to I2C, putting in 0Ω resistors on these connections can be useful, especially if I2C bus devices will be included in the final product. An addresssetting capability can be provided by installing various combinations of resistors, and connections to the I/O pins can be jumper-wired-in later. If the project never needs the port expander, it and the resistors can be dropped.

JON PEARSON is product marketing director, Cypress Semiconductor


Contact Details and Archive...

Print this page | E-mail this page