Hardware Reference
In-Depth Information
Program mcp23017.c is shown here:
1 /
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
2
mcp23017.c : Interface with MCP23017 I/O Extender Chip
3
4
This code assumes the following :
5
6
1. MCP23017 is configured for address 0x20
7
2. RPi's GPIO 17 (GEN0) will be used for sensing interrupts
8
3. Assumed there is a pull up on GPIO 17.
9
4. MCP23017 GPA4-7 and GPB4-7 will be inputs, with pull-ups.
10
5. MCP23017 GPA0-3 and GPB0-3 will be ouputs.
11
6. MCP23017 signals interrupt active low.
12
7. MCP23017 operating in non-banked register mode.
13
14
Inputs sensed will be copied to outputs :
15
1. GPA4-7 copied to GPA0-3
16
2. GPB4-7 copied to GPB0-3
17
18
/
∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <fcntl.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <signal.h>
27 #include <assert.h>
28 #include <sys/ioctl.h>
29 #include <sys/poll.h>
30 #include <linux/i2c.h>
31 #include <linux/i2c-dev.h>
32
33 #include "i2c_funcs.c" /
I2C routines
/
34
35 /
Change to i2c 0 if using early Raspberry Pi
/
36 static const char
node = "/dev/i2c-1";
37
38 #define GPIOA 0
39 #define GPIOB 1
40
41 #define IODIR 0
42 #define IPOL 1
43 #define GPINTEN 2
44 #define DEFVAL 3
45 #define INTCON 4
46 #define IOCON 5
Search WWH ::




Custom Search