Hardware Reference
In-Depth Information
95 polls.fd = fd; /
/sys/class/gpio17/value
/
96 polls.events = POLLPRI; /
Exceptions
/
97
98 do {
99 rc = poll(&polls,1,-1); /
Block
/
100 if ( is_signaled )
101 return -1; /
Exit if ^Creceived
/
102 } while ( rc < 0 && errno == EINTR );
103
104 (void)read(fd,buf,sizeof buf); /
Clear interrupt
/
105 return 0;
106 }
107
108 /
End sysgpio.c
/
Example Run
The first time you run the program, you might encounter an error:
$ ./mcp23017
Opening /dev/i2s−1: No such file or directory
Check that the i2c−dev & i2c−bcm2708 kernel modules are loaded.
Aborted
$
As the program states in the error message, it is unable to open the I2C driver,
because the I2C kernel modules have not been loaded. See Chapter 12 of Raspberry Pi
Hardware Reference (Apress, 2014) for modprobe information.
The following is a successful session. After the program is started, the program
pauses after issuing the message “Monitoring for MCP23017 input changes.” At this point,
the program is in the poll(2) system call, waiting to be notified of an interrupt from the
MCP23017 peripheral. If you open another session, you can confirm that little or no CPU
resource is consumed by this.
$ sudo ./mcp23017
Monitoring for MCP23017 input changes :
Outputs : 0F0F
Input change : flags 8000 values 70F0
Outputs : 070F
Input change : flags 8000 values F0F0
Outputs : 070F
Input change : flags 8000 values F0F0
Outputs : 070F
Input change : flags 8000 values F0F0
Outputs : 070F
 
Search WWH ::




Custom Search