Hardware Reference
In-Depth Information
141 mcp23017_write_both(DEFVAL,0x00); /
Clear default value
/
142 mcp23017_write_both(OLAT,0x00); /
OLATx=0
/
143 mcp23017_write_both(GPPU,0b11110000); /
4-7 are pull up
/
144 mcp23017_write_both(IPOL,0b00000000); /
No inverted polarity
/
/
4-7 inputs, 0-3 outputs
/
145 mcp23017_write_both(IODIR,0b11110000);
146 mcp23017_write_both(INTCON,0b00000000); /
Cmp to previous
/
147 mcp23017_write_both(GPINTEN,0b11110000); /
Int on changes
/
148
149 /
150
Loop until all interrupts are cleared:
151
/
152 do {
153 int_flags = mcp23017_interrupts();
154 if ( int_flags != 0 ) {
155 v = mcp23017_captured();
156 printf(" Got change %04X values %04X\n",int_
flags,v);
157 }
158 } while ( int_flags != 0x0000 && !is_signaled );
159 }
160
161 /
162
Copy input bit settings to outputs :
163
/
164 static void
165 post_outputs(void) {
166 int inbits = mcp23017_inputs(); /
Read inputs
/
167 int outbits = inbits >> 4; /
Shift to output bits
/
168 mcp23017_outputs(outbits); /
Copy inputs to outputs
/
169 printf (" Outputs: %04X\n",outbits);
170 }
171
172 /
173
Main program :
174
/
175 int
176 main(int argc,char
argv) {
177 int int_flags, v;
178 int fd;
179
180 signal(SIGINT,sigint_handler); /
∗∗
Trap on SIGINT
/
181
182 i2c_init(node); /
Initialize for I2C
/
183 mcp23017_init(); /
Configure MCP23017 @ 20
/
184
185 fd = gpio_open_edge(gpio_inta); /
Configure INTA pin
/
186
Search WWH ::




Custom Search