ST AN2591 Application note

AN2591
Application note
Microcontroller input / output expander
Introduction
In certain applications, the number of input and/or output lines available in the microcontroller you have chosen may be too small and this may lead you to select another microcontroller in order to have enough I/Os to meet your application needs. In some cases this choice means you have to use a more expensive part.
However it may often be better to look for a solution that allows you to add more I/Os and still use the microcontroller you selected originally.
This application note shows how to use a simple technique to increase the number of inputs and/or outputs.
August 2007 Rev 1 1/19
www.st.com
Contents AN2591

Contents

1 Expanding the number of outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1 Using a decoder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.1.1 Expanding the number of outputs to 8 lines . . . . . . . . . . . . . . . . . . . . . . 3
1.1.2 Expanding the number of outputs to 16 lines . . . . . . . . . . . . . . . . . . . . . 3
1.2 Using a shift register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2.1 Expanding the number of outputs to 8 lines . . . . . . . . . . . . . . . . . . . . . . 4
1.2.2 Expanding the number of outputs to 16 lines . . . . . . . . . . . . . . . . . . . . . 5
2 Expanding the number of inputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Using a multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 Expanding the number of inputs to 8 lines . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.2 Expanding the number of inputs to 16 lines . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Using shift registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.1 Expanding the number of inputs to 8 lines . . . . . . . . . . . . . . . . . . . . . . . . 9
2.2.2 Expanding the number of inputs to 16 lines . . . . . . . . . . . . . . . . . . . . . . 10
3 Using a STMPE801 (I²C bus) 8-bit I/O port expander . . . . . . . . . . . . . . 11
3.1 Expanding the number of inputs/outputs to 8 lines . . . . . . . . . . . . . . . . . 11
3.2 Expanding the number of I/Os to 16 lines . . . . . . . . . . . . . . . . . . . . . . . . 12
4 Using the External Memory Interface for I/O expansion . . . . . . . . . . . 14
4.1 Expanding the number of inputs and/or outputs to 8 lines . . . . . . . . . . . . 14
4.2 Expanding the number of inputs and/or outputs to 16 lines . . . . . . . . . . . 16
5 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2/19
AN2591 Expanding the number of outputs

1 Expanding the number of outputs

This section describes how to increase the number of output lines using two techniques: by using a decoder or by using shift registers.

1.1 Using a decoder

1.1.1 Expanding the number of outputs to 8 lines

In certain applications, you may need to use several microcontroller outputs but only one of these outputs is activated at any given time. For example when you control a multiplexed display (7-segment or LCD display), only one digit at a given time is selected. This is also the case with matrix keypad management. In order to generate row signals to poll a keypad to determine which key is pressed, you have to use several microcontroller outputs.
Figure 1 shows how to reduce the number of outputs used in this type of application.
This solution uses a 3-to-8 line decoder (M74HC138) to determine which one of the outputs goes low (Y0 to Y7) by applying an address value on the three inputs A, B and C. The number of lines saved is 8 - 3 = 5 lines.
Figure 1. Expander for 8 outputs using a M74HC138 decoder
16
6
1
2
3
4
5
8
M74HC138
Vcc
G1
A
B
C
G2A
G2B
GND
3.3v
µC
GPIO0.0
GPIO0.1
GPIO0.2
Y0
Y1
Y2
Y3
Y4
Y5
Y6
Y7
15
14
13
12
11
10
9
8

1.1.2 Expanding the number of outputs to 16 lines

Sometimes, more than 8 outputs are used although only one output needs to be active at a time (for example for a multiplexed display with more than 8 digits, a matrix keypad with more than 7 rows or a row of 16 LEDs for a bargraph level display, and so on).
3/19
Expanding the number of outputs AN2591
This example uses a 4-to-16 line decoder (M74HC4514 or M74HC4515) to expand the number of outputs to 16. The number of lines saved is 16 - 5 = 11 lines.
Contrary to the solution described in Section 1.1.1, the microcontroller GPIOs connected to the decoder address lines can also be used for other application purposes. This is made possible by the decoder strobe input which stores the address of the decoder output. The decoder output values remain unchanged while ST = 0, so in this state you can change the GPIO values and you are free to use the lines (GPIO0.0 to GPIO0.3) for other application purposes. In this case, the number of lines saved is 16 - 1 (for strobe line) = 15 lines.
Figure 2. Expander for 16 outputs using a M74HC4514 or M74HC4515 decoder
Can also be used for
other application purposes
µC
GPIO0.4
GPIO0.0
GPIO0.1
GPIO0.2
GPIO0.3
Strobe
3.3v
2
3
21
22
1
23
12
24
Vcc
A
B
C
INH
GND
M74HC4514 / M74HC4515
ST
D
Y0
Y1
Y2
Y3
Y4
Y14
Y15
11
9
10
8
7
16 outputs
16
15
Note: M74HC4514 and M74HC4515 are similar and pin to pin compatible except that the latter
has inverted outputs.

1.2 Using a shift register

1.2.1 Expanding the number of outputs to 8 lines

This is another technique you can use to free up some microcontroller lines. This example uses a 74HC595 SIPO (Serial In / Parallel Out) shift register that requires only 3 microcontroller GPIOs to generate one byte of data on its outputs (Q0 to Q7) (see M74HC595 datasheet).
4/19
AN2591 Expanding the number of outputs
The shift register receives data serially from the microcontroller via the Sin input (pin 14) using synchronous transmission. The M74HC595 includes two registers. The first one is a shift register to shift in the data, the second one is a latch register to enable the data on the outputs. This register prevents the output values being disturbed while data is being shifted into the shift register.
You need to perform two steps to make the data available on the M74HC595 outputs:
1. Shift the data from the microcontroller to the shift register via the Sin line:
Shift each bit of data via the microcontroller (GPIO0.0) and
Apply a clock pulse (via SCK line) to shift this bit into the register. You need 8 clock
times to load all bits of the data byte into the shift register. At this stage the data is not yet available on the outputs (Q0 to Q7).
2. To make it available on the outputs (Q0 to Q7), you must apply a latch pulse via the RCK line to load the data into the second register.
The number of lines saved is 8 - 3 = 5. This is same amount of saving as with the M74HC138 decoder but the difference that you can activate or deactivate any of the outputs independently, unlike with the decoder when only one output can be activated at a time.
Figure 3. Expander for 8 outputs using a shift register: M74HC595
16
10
13
8
M74HC595
Vcc
SCLR
Sin
RCK
SCK
G
GND
µC
GPIO0.0
GPIO0.1
GPIO0.2
3.3v
14
12
11

1.2.2 Expanding the number of outputs to 16 lines

In this section uses the same technique as described in Section 1.2.1, but the number of outputs is expanded to 16 lines. This is done by cascading two shift registers (the same IC reference used in Section 1.2.1).
Q0
Q1
Q2
Q3
Q4
Q5
Q6
Q7
SDO
15
1
2
3
4
5
6
7
9
8 outputs
The M74HC595 SDO output is used to connect the two shift registers to allow the data flow to pass from the first register into the second one. This creates a 16-bit shift register.
5/19
Expanding the number of outputs AN2591
The availability of data on the outputs of the two M74HC595 components is controlled by the same sequence described in Section 1.2.1 but to make 16 bits of data, the process is done for 16 clock times. You have to apply the latch pulse to the two ICs at the same time to enable the data in the 16 output lines. You can expand the number of outputs even further without using any additional microcontroller GPIO lines because there are two common signals for all registers (RCK and SCK). The number of lines saved is 16 - 3 = 13.
Figure 4. Expander for 16 outputs using two shift registers: M74HC595
16
10
13
8
M74HC595
Vcc
SCLR
Sin
RCK
SCK
G
GND
Q0
Q1
Q2
Q3
Q4
Q5
Q6
Q7
SDO
15
1
2
3
4
5
6
7
9
µC
GPIO0.0
GPIO0.1
GPIO0.2
3.3v
14
12
11
3.3v
14
12
11
16
10
13
8
M74HC595
Vcc
SCLR
Sin
RCK
SCK
G
GND
Q0
Q1
Q2
Q3
Q4
Q5
Q6
Q7
SDO
15
1
2
3
4
5
6
7
9
To other registers if needed to expand to more than 16 outputs
16 outputs
6/19
Loading...
+ 13 hidden pages