GPIO Pin Expansion Using I2C Bus Interface in Altera MAX Series
This design example shows the capability of Altera® MAX® II, MAX V and MAX 10 to provide general purpose I/O (GPIO) pin expansion via an industry standard I2C bus.
To reduce package size and pin count, the number of general purpose I/Os are limited in many microprocessor-based systems.
However, if the system has an I2C interface, this design example shows how to add additional GPIO pins via the I2C bus.
The supported Altera devices are an excellent
choice to implement industry standard interfaces, such as the I2C. Their
low power, easy power-on feature, and internal oscillator make them
ideal programmable logic devices to implement applications such as I2C
interfaces to provide GPIO pin expansion.
In some cases, it may be required to have access to the GPIO pins from a relatively long PCB trace path within the system
(such as in the two different parts of a clamshell cell phone). Because the I2C interface is a two-wire system, the design provides multiple input and output pins at the remote end with just a common
two-wire trace. This provides increased design flexibility and also adds to the physical compactness of the entire system.
It also enables smaller packaging and a reduced pin count.
Devices such as fan controllers, LED status displays, and status indicators can be easily connected and controlled via the
general purpose output pins. Similarly, devices such as reset pins and push button switches can be easily coupled to the general
purpose inputs provided on the device to serve various applications.
Figure 1. GPIO Pin Expansion via an I2C Bus
I2C Interface for GPIO Pin Expansion
The supported Altera device acts as a slave on the I2C bus and has two pins on its I2C interface: the I2C clock SCL and the I2C data line SDA. The host system, which acts as an I2C master, communicates with the device (which acts as an I2C slave). The device presents eight general purpose input ports and eight general purpose output ports to the host. Data,
which is transmitted serially over the I2C bus, is received in parallel at the GPIO pins. This way, all eight general purpose I/Os can be read or written at the same
For the I2C interface, the device (I2C slave) has a built-in 7-bit address and follows the general I2C protocol. The start signal is sent by the master, followed by the 7-bit address and an R/W bit. When the address broadcast
on the I2C bus matches a slave device's address, an ACK (acknowledge) signal is sent by the device followed by data according to the read or write signal sent by the master. This
is then followed by another ACK signal. The exchange of data continues in this manner until the Stop (P) signal is sent by the master.
Table 1. I2C Interface Pin Description
I2C Serial Data
Figure 2. I2C Signal Format
Whenever the master issues a write condition (R/W=0), the data received on the I2C bus is used to update the general purpose output pins until a stop or a repeat start condition is encountered. Similarly,
when the I2C master issues a read condition (R/W = 1), the values at the general purpose input pins are sampled at the ACK bit and transmitted serially over the I2C bus. This process continues until the master issues a stop or repeat start.
Table 2. GPIO Pin Description
GPIO Pin Expansion Using I2C Bus Interface Using MAX II Devices
The detailed description of the implementation is based on the MAX II devices. This application can also be implemented in
MAX V and MAX 10 devices.
Implementation involves using this design example source code and allocating I2C bus lines and GPIO pin expansion inputs and outputs to MAX II GPIOs. GPIO pin expansion is demonstrated on the MDN-B2 demo
board with the help of an I2C simulator that is created using a PC parallel port and interfacing hardware to create an I2C compliant two-wire bus.
Details about setting up an I2C environment is described in the Dallas Semiconductor's Maxim application note AN3230. This utility program uses the parallel
port and its interfacing hardware to interact with the MAX II device and provides the SDA and SCL connections, as required
on an I2C two-wire system. When implemented, this design allows inputs from the MDN-B2 demo board (set via DIP switches) to reach
the I2C master. Similarly, data sent by the I2C master is available on the GPIO output ports (connected to LEDs on the demo board) of the MAX II device. The I2C master in this demonstration is the user interface on the PC running the parallel port I2C software.
The following details the implementation of this design example on the MDN-B2 demo board.
Table 3. EPM240G Pin Assignments
Note: Assign unused pins As input-tristated in the Quartus® II software. You must also enable the Auto Open-Drain setting on the SCLK and SDA pins. To do this, on the Assignments menu, click Settings and then select Analysis and Synthesis Settings to enable the Auto Open-Drain setting. These settings are followed by a compilation cycle.
To demonstrate this design on the MDN-B2 demo board, perform the following steps:
Turn on the power to the demo board using the slide switch SW1.
Download the design to the device through the JTAG header JP5 on the demo board and a conventional programming cable (ByteBlaster™
II or USB-Blaster™).
Keep SW4 on the demo board pressed before and during the start of the programming process. After programming, turn off the
power and remove the JTAG connector.
To set up a parallel port driven I2C environment on your PC, perform the following:
Download a software utility, such as the Maxim parallel port utility, to communicate with the slave in the I2C defined protocol. Install the parallel port software. (The ParDS2W.exe program downloaded from parallel port software from
Direct-IO is used in this example.)
You must install a parallel port driver to enable access to the parallel port in Windows XP or Windows 2000 for this parallel
After installation, you must configure the Direct-IO program. Open the Windows control panel and click the Direct IO icon.
Enter the Begin and End addresses of your parallel port (normally, this is 378 through 37F; however, confirm your PC's parallel port address by looking
at the settings in Control Panel/System/Hardware/Device Manager/Ports/ECP Printer port (LPT)/Resources
Configure the parallel port to ECP by changing the BIOS settings when you start up your PC.
Next, select the Security tab of the Direct IO control panel and browse to the directory path of the ParDS2W.exe program. Click Open and then click Add to add the program. The path of this utility is shown in the Allowed Processes field. Click OK.
Attach the parallel port I2C dongle that is supplied along with the MDN-B2 demo board. Use an extension chord, if necessary, to extend the parallel port
connection closer to your demo board.
Attach the 4-pin socket on the pig tail of the I2C parallel port dongle to the I2C header (JP3) of the demo board so that the red mark on the socket meets pin 1 on the JP3 header.
Open the ParDS2W program, select the appropriate parallel port address of your PC (as seen when configuring Direct IO) and
set the 2-Wire Device Address to 00h.
Finally, you can test the I2C setup on the Test Circuit tab to see if you have a Test PASS message in the Status window. If you do, the I2C environment is set.
With the parallel port utility you can now perform write and read operations in I2C using the 2-Wire Functions.
To perform a write I2C operation, click Start and then click Write Byte. Enter a hex byte in the field adjacent to Write Data and click Write Data. Observe the corresponding value on the eight red LEDs. Click Stop after each write operation.
Similarly, a read operation is performed by clicking Start and then Read Byte. The Read window displays the settings on the SW5 dip switch on the demo board. Click Stop after each read operation.