I ran out of I/O pins on my microcontroller. How can I get more?
Submitted By: Gary Peek FAQ Last Modified: 10/12/06
- Port expander chips are available, however, they may not be the best thing to use. Textbooks still use the Intel 8255 as an example, but this chip may be hard to obtain, and may not have the speed or output capability required.
(If you are using them to learn about how to interface to an 8051 family microcontroller, then fine. But if you are trying to design a practical circuit you will probably want to avoid them.)
Inexpensive "shift register" chips can be used to provide additional input and output pins. Some examples of this are on the web page: http://www.8052.com/users/garypeek/
Even newer are some specialized chips that provide not only the "shift register" portion of the circuit, but the "source" and "sink" current part of the circuit as well.
For example, if you need to drive multiple relays or sink/source current with LED's, the MICREL MIC5821YN or ALLEGRO A6821SA-T (sink driver) and the MICREL MIC5891YN or ALLEGRO UDN2981A-T (source driver) chips are quite handy.
Any other options?
Submitted By: Jan Waclawek FAQ Last Modified: 10/12/06
- The options for on-board expansion of plain inputs and outputs - not covering any other requirements on output current/voltage - fall into 4 groups:
- Spare existing pins
- if P0/P2/P3.6/P3.7 would be used for external memory interfacing, use a derivative which has all the needed resources (ROM/FLASH, RAM, peripherals) integrated, that would leave those 18 pins free
- consider using methods which spare pins, e.g. matrices for inputs
- if P0/P2/P3.6/P3.7 would be used for external memory interfacing, use a derivative which has all the needed resources (ROM/FLASH, RAM, peripherals) integrated, that would leave those 18 pins free
- Use a derivative which has the needed number of pins
- there is a number of derivatives available with extended number of ports - browse the chiplist
- Use parallel interfaced circuits
- style of interface:
- external memory - like
- address latch needed
- glue logic (address decoder) is most probably needed
- uses up to 18 pins (although if only MOVX @Rx is used, 10 is enough)
- fast access - as fast as a memory cycle
- fast strobe - requires the devices to comply with the processor's timing, which might be tight for faster derivatives (this is mainly why 8255 is not recommended)
- for more devices consider bus drivers to comply with specified fan-outs
- good option if there is already an external memory attached
- address latch needed
- directly connected to port pins, which are "manually" manipulated
- any ports/pins can be used, which might simplify PCB layout
- no latch nor glue logic (address decoder) needed
- arbitrarily long strobe pulses (given by software)
- slower access (more instructions to accomplish a read/write cycle)
- any ports/pins can be used, which might simplify PCB layout
- external memory - like
- solutions
- 74xx: parallel latch (e.g. 74xx573) or set of addressable latches (e.g. 74xx259) for output
- 74xx: parallel tristateable bus driver (e.g. 74xx245) or set of tristateable multiplexers (e.g. 74xx251) for input
- similar to those above in CMOS (40xx/45xx)
- CPLD/FPGA
- the controversial 8255
- small el cheapo slave processor
- 74xx: parallel latch (e.g. 74xx573) or set of addressable latches (e.g. 74xx259) for output
- style of interface:
- Use serially interfaced circuits
- slower than any other solution, but requires less pins/lines and very often the performance is satisfactory enough. Generally, these interfaces can be bit-banged in software. Some derivatives do have support for I2C/SPI in hardware, that's faster but not compatible through various derivatives.
- interfaces used
- SPI and like (basically covered in the first FAQ)
- I2C
- UART-interfaced
- SPI and like (basically covered in the first FAQ)
- solutions:
- MSI (74xxx shift registers - see Gary's post)/LSI (e.g. I2C I/O ICs)
- CPLD/FPGA
- a small el cheapo slave processor
- MSI (74xxx shift registers - see Gary's post)/LSI (e.g. I2C I/O ICs)
- slower than any other solution, but requires less pins/lines and very often the performance is satisfactory enough. Generally, these interfaces can be bit-banged in software. Some derivatives do have support for I2C/SPI in hardware, that's faster but not compatible through various derivatives.
The choice of appropriate solution is of course given by the requirements of the particular application.
Add Information to this FAQ: If you have additional information or alternative solutions to this question, you may add to this FAQ by clicking here.