AN 494: GPIO Pin Expansion Using I2C Bus Interface in Altera MAX Series
GPIO Pin Expansion Using I2C Bus Interface in Altera MAX Series
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.
GPIO Pin Expansion and I2C
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.
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 time.
I2C Interface
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.
Signal | Purpose | Direction |
---|---|---|
SCL | I2C Clock | Output |
SDA | I2C Serial Data | Bidirectional |
GPIO Interface
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.
Signal | Purpose | Direction |
---|---|---|
8-bit Input | General | In |
8-bit Output | General | Out |
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.
Signal | Pin | Signal | Pin |
---|---|---|---|
SCLK | pin 39 | SDA | pin 40 |
GPIO_output[0] | pin 69 | GPIO_output[1] | pin 70 |
GPIO_output[2] | pin 71 | GPIO_output[3] | pin 72 |
GPIO_output[4] | pin 73 | GPIO_output[5] | pin 74 |
GPIO_output[6] | pin 75 | GPIO_output[7] | pin 76 |
GPIO_input[0] | pin 55 | GPIO_input[1] | pin 56 |
GPIO_input[2] | pin 57 | GPIO_input[3] | pin 58 |
GPIO_input[4] | pin 61 | GPIO_input[5] | pin 66 |
GPIO_input[6] | pin 67 | GPIO_input[7] | pin 68 |
Design Demonstration on the MDN-B2 Demo Board
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 port utility.
- 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.
Acknowledgments
Design example adapted for Altera MAX 10 FPGAs by:
Orchid Technologies Engineering and Consulting, Inc.
Maynard, Massachusetts 01754
TEL: 978-461-2000
WEB: www.orchid-tech.com
EMAIL: info@orchid-tech.com
Document Revision History
Date | Version | Changes |
---|---|---|
September 2014 | 2014.09.22 |
|
December 2007 | 1.0 | Initial release. |