Hardware Reference
In-Depth Information
the peripheral). This means that the absolute maximum number of interrupts per second
that can be processed will be 6,600.
To estimate the effects of the IC2 bus, let's do some additional simplified
calculations. The I2C bus operates at 100 kHz on the Raspberry Pi (for more information,
see Chapter 12 of Raspberry Pi Hardware Reference [Apress, 2014]). A single byte requires
8 data bits and an acknowledgment bit. This requires about 90 μs per byte. To read one
MCP23017 register requires the following:
1.
The peripheral's address byte to be sent (1 byte).
2.
The MCP23017 register address to be sent (1 byte).
3.
The MCP23017 responds back with 1 byte.
This requires 3 × 90 = 270 μs, just to read one register. Add to this the following:
Both interrupt flag registers INTFA and INTFB must be read.
1.
Both GPIOA and GPIOB registers must be read, to clear the
interrupt.
2.
So, ignoring the start and stop bits, this requires 4 × 270 = 1.08 ms to respond to one
input level change. (This also ignores the effect of multiple peripherals on the bus.) This,
added to the minimum of about 150 μs overhead for poll(2) , leads to the minimum
response time of about 1.08 + 0.150 = 1.23 ms . This results in a practical limit of about 800
signal changes per second.
Because of the response-time limitations, it is recommended that the INTCAPx
register values be ignored. By the time the application can respond to a signal change, it
may have changed back again. This is why the program presented uses the values read in
GPIOA and GPIOB , rather than the captured values in the INTCAPx . But if your application
needs to know the state at the time of the event, the INTCAPx register values are available.
Some reduced I2C overhead can be attained by tuning the I/O operations. For
example, with use of the auto-increment address feature of the MCP23017, it is possible
to read both INTFx flags and GPIOx registers in one ioctl(2) call:
Tt t
=+ +
t
+
t
+
t
+
t
+
t
addr
register
INTFAINTFB
register
GPIOA PIOB
=790
0 630
= . ms
That approach reduces the I2C time to approximately 7-byte times. The total
turnaround time can then be reduced to about 0 . 63 + 0 . 150 = 0 . 78 ms .
 
Search WWH ::




Custom Search