Hardware Reference
In-Depth Information
Value
R/W
GPIOx Bit Value
0
R
Current input pin state is low
W
Write 0 to OLATx and output pin
1
R
Current input pin state is high
W
Write 1 to OLATx and output pin
Main Program
Here are some change notes for the main program:
1.
If you have a pre-revision 2.0 Raspberry Pi, change line 36 to
use /dev/i2c-0 .
2.
Change line 55 if your MCP23017 chip is using a different I2C
address than 0x20 (A2, A1, and A0 grounded).
3.
Change line 56 if you use a different Raspberry Pi GPIO for
your interrupt sense pin.
The main program is fairly straightforward. Here are the basic overall steps:
A signal handler is registered in line 180, so ^C will cause the
program to exit cleanly.
1.
Routine i2c_init() is called to open the I2C driver and
initialize.
2.
Routine mcp23017_init() is called to initialize and configure
the MCP23017 device on the bus (only one is currently
supported).
3.
Routine gpio_open_edge() is called to open /sys/class/
gpio17/value , so changes on the interrupt line can be sensed.
This is discussed in more detail later.
4.
5.
Finally, the main program enters a loop in lines 190 to 200,
looping until ^C is entered.
Once inside the main loop, the following events occur:
Execution stalls when gpio_poll() is called. This blocks until
the interrupt on GPIO 17 transitions from a high to a low.
1.
The interrupt flags are read using routine mcp23017_
interrupts() . They're only reported and otherwise not used.
2.
Routine mcp23017_captured() is used to read the INTCAPA
and INTCAPB registers in order to clear the interrupt.
3.
Finally, the routine post_outputs() reads the real-time input
values and sends the bits to the outputs.
4.
 
 
Search WWH ::




Custom Search