Hardware Reference
In-Depth Information
The
i2cdump
utility can be used to check the MCP23017 register:
$ sudo i2cdump -y -r 0x00-0x15 1 0x20 b
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
00: ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
10: 00 00 00 00 00 00 ......
Here we have dumped out registers
0x00
to
0x15
on I2C bus 1, at peripheral address
0x20
, in byte mode. This was performed after a power-on reset, so we can check whether
the register values match the datasheet values documented. As expected,
IODIRA
(register
0x00
) and
IODIRB
(register
0x01
) have the default of all 1s (
0xFF
). This also confirms that
the registers are in
BANK=0
mode (this is discussed in the following sections). All other
MCP23017 registers default to 0 bits, which is also confirmed.
Software Configuration
The MCP23017 datasheet describes the full register complement and options available.
In this chapter, we'll concern ourselves with a subset of its functionality, which is perhaps
considered “normal use.” The extended functionality is left as an exercise for you.
For this chapter's project, we're going to do the following:
•
Configure some GPIOs as inputs
•
Configure some GPIOs as outputs
•
Configure the group A and B inputs to signal an interrupt on any
change
General Configuration
The MCP23017 peripheral has 10 registers for the GPIO-A pins, 10 registers for the
GPIO-B pins, and one shared register. In other words, there are 22 registers, with one pair
of addresses referencing a common register. These registers may be accessed in banks or
interleaved. We'll use interleaved mode in this chapter, to avoid having to reset the device.
Interleaved register addresses are shown in Table
2-1
. These are valid addresses
when the
IOCON
register value for
BANK=0
(discussed later in this section).