Acknowledgments |
|
xvii | |
Introduction |
|
xix | |
|
PART I LOW-LEVEL PROTOCOLS AND HARDWARE |
|
|
1 | (90) |
|
|
3 | (12) |
|
|
4 | (1) |
|
1.2 Open-Drain (Open-Collector) Logic and Four-Wire Mode |
|
|
5 | (2) |
|
|
7 | (1) |
|
|
7 | (1) |
|
1.4 Choosing Pullup Resistor Sizes |
|
|
8 | (1) |
|
1.5 Bus Capacitance and Pullup Resistor Values |
|
|
8 | (1) |
|
1.5.1 What If the Bus Capacitance Is Too High? |
|
|
9 | (1) |
|
|
9 | (1) |
|
1.7 Multicontroller l2C Bus Clock Synchronization |
|
|
10 | (2) |
|
1.8 Multicontroller l2C Bus Arbitration |
|
|
12 | (1) |
|
|
13 | (1) |
|
|
13 | (1) |
|
|
14 | (1) |
|
|
15 | (16) |
|
|
16 | (3) |
|
2.2 I2C Addresses and Read/Write Control |
|
|
19 | (1) |
|
2.3 Repeated Start Conditions |
|
|
19 | (1) |
|
|
20 | (1) |
|
|
21 | (5) |
|
2.5.1 The General Call Address |
|
|
21 | (2) |
|
2.5.2 Hardware General Calls |
|
|
23 | (1) |
|
|
23 | (1) |
|
2.5.4 CBUS and Reserved Addresses |
|
|
24 | (1) |
|
2.5.5 High-Speed Mode Controller Code |
|
|
24 | (1) |
|
2.5.6 10-Bit Peripheral Addressing |
|
|
24 | (1) |
|
|
25 | (1) |
|
2.6 Resetting the I2C Bus |
|
|
26 | (1) |
|
2.7 Detecting I2C Peripherals on the Bus |
|
|
26 | (2) |
|
2.8 Creating Custom Devices |
|
|
28 | (1) |
|
|
28 | (3) |
|
3 A Software Implementation Of The I2C BUS |
|
|
31 | (36) |
|
3.1 A Software I2C Implementation on the Teensy 3.2 |
|
|
32 | (32) |
|
3.1.1 A Software-Based I2C Controller for the Teensy 3.2 |
|
|
32 | (20) |
|
3.1.2 A Software-Based I2C Peripheral for the Teensy 3.2 |
|
|
52 | (12) |
|
3.1.3 Some Final Comments on the Teensy 3.2 Software I2C Code |
|
|
64 | (1) |
|
3.2 Basic ATtiny84 and ATtiny85 Hardware |
|
|
64 | (2) |
|
3.2.1 Atto84 Software-Based I2C Peripheral |
|
|
65 | (1) |
|
|
66 | (1) |
|
4 Tools For Analyzing And Debugging I2C Transmissions |
|
|
67 | (14) |
|
4.1 Generic Hardware Testing and Debugging Tools |
|
|
68 | (2) |
|
|
70 | (2) |
|
|
72 | (3) |
|
|
75 | (1) |
|
4.5 The Saleae Logic Analyzers |
|
|
75 | (3) |
|
4.6 A Final Comment on I2C Monitors and Logic Analyzers |
|
|
78 | (1) |
|
|
78 | (3) |
|
|
81 | (10) |
|
|
82 | (7) |
|
5.1.1 Differences Between SMBus and Standard I2C |
|
|
82 | (1) |
|
5.1.2 SMBus Electrical Specifications |
|
|
83 | (1) |
|
5.1.3 SMBus Reserved Addresses |
|
|
83 | (1) |
|
5.1.4 SMBus Protocol Commands |
|
|
84 | (5) |
|
|
89 | (1) |
|
|
89 | (1) |
|
5.4 Two-Wire Interface and Two-Wire Serial Interface |
|
|
89 | (1) |
|
|
90 | (1) |
|
PART II HARDWARE IMPLEMENTATIONS |
|
|
91 | (38) |
|
6 I2C On Common Single-Board Computers |
|
|
93 | (22) |
|
|
94 | (7) |
|
6.1.1 The Arduino Uno Rev3 and Leonardo |
|
|
95 | (1) |
|
|
96 | (1) |
|
|
97 | (1) |
|
6.1.4 The Arduino Nano Every |
|
|
98 | (1) |
|
6.1.5 The Arduino Mega 2560 Rev3 |
|
|
98 | (2) |
|
|
100 | (1) |
|
|
100 | (1) |
|
6.1.8 Other Arduino-Brand Single-Board Computers |
|
|
101 | (1) |
|
6.2 Adafruit Single-Board Computers |
|
|
101 | (2) |
|
6.3 SparkFun Single-Board Computers |
|
|
103 | (1) |
|
|
104 | (1) |
|
6.5 Other Arduino-Compatible Single-Board Computers |
|
|
105 | (1) |
|
|
105 | (2) |
|
6.7 The Raspberry Pi Pico |
|
|
107 | (1) |
|
|
108 | (1) |
|
6.9 The PINE A64 and ROCKPro64 |
|
|
109 | (1) |
|
|
109 | (1) |
|
6.11 The STM32 Single-Board Computer Family |
|
|
110 | (1) |
|
6.11.1 STM32F767/Nucleo-144 |
|
|
111 | (1) |
|
|
111 | (1) |
|
6.1 1.3 STM32 Boards Galore |
|
|
111 | (1) |
|
6.12 The NetBurnerMOD54415 |
|
|
111 | (1) |
|
6.13 I2C on the Personal Computer |
|
|
112 | (1) |
|
|
112 | (3) |
|
|
115 | (14) |
|
7.1 The Adafruit Feather Bus |
|
|
116 | (6) |
|
7.1.1 Feather Bus Pinouts |
|
|
118 | (1) |
|
7.1.2 L2C on the Feather Bus |
|
|
119 | (1) |
|
7.1.3 Multicontroller Operation |
|
|
120 | (1) |
|
7.1.4 Feathers and FeatherWings |
|
|
120 | (2) |
|
7.2 L2C on the SparkFun Qwiic Bus |
|
|
122 | (1) |
|
7.3 Qwiic Bus Peripherals |
|
|
123 | (2) |
|
7.4 L2C on the Seeed Studio Grove Bus |
|
|
125 | (1) |
|
|
126 | (3) |
|
PART III PROGRAMMING THE I2C BUS |
|
|
129 | (122) |
|
8 Arduino I2C Programming |
|
|
131 | (16) |
|
8.1 Basic I2C Programming |
|
|
133 | (1) |
|
8.2 Basic Wire Programming |
|
|
134 | (3) |
|
8.2.1 Wire Utility Functions |
|
|
134 | (1) |
|
8.2.2 Wire Read Operations |
|
|
135 | (1) |
|
8.2.3 Wire Write Operations |
|
|
136 | (1) |
|
8.2.4 Wire Peripheral Functions |
|
|
137 | (1) |
|
8.3 Arduino I2C Write Example |
|
|
137 | (3) |
|
8.4 Arduino I2C Read Example |
|
|
140 | (2) |
|
8.5 Arduino I2C Peripheral Example |
|
|
142 | (2) |
|
8.6 Multiple I2C Port Programming |
|
|
144 | (1) |
|
|
145 | (2) |
|
9 Raspberry PI (And Linux) I2C Programming |
|
|
147 | (28) |
|
9.1 The I2C Bus Pins on the Pi General-Purpose Input/Output Header |
|
|
148 | (3) |
|
9.2 Manually Activating the I2C Buses |
|
|
151 | (1) |
|
9.3 Changing the I2C Clock Frequency |
|
|
152 | (1) |
|
9.4 I2C Clock Stretching Issues and Solutions |
|
|
153 | (1) |
|
9.5 Raspberry Pi OS (Linux) I2C Utilities |
|
|
154 | (4) |
|
9.6 Reading and Writing I2C Data |
|
|
158 | (4) |
|
9.7 Advanced I2C Kernel Calls |
|
|
162 | (9) |
|
9.7.1 The I2c-dev Functions |
|
|
163 | (1) |
|
9.7.2 The I2c smbus write quick Function |
|
|
164 | (1) |
|
9.7.3 The I2c smbus read byte Function |
|
|
165 | (1) |
|
9.7.4 The I2c smbus write byte() Function |
|
|
166 | (1) |
|
9.7.5 The I2c smbus read byte data() Function |
|
|
166 | (2) |
|
9.7.6 The I2c smbus write byte data() Function |
|
|
168 | (1) |
|
9.7.7 The I2c smbus read word data() Function |
|
|
168 | (1) |
|
9.7.8 The I2c smbus write word data() Function |
|
|
169 | (1) |
|
9.7.9 The I2c smbus read block data() Function |
|
|
169 | (1) |
|
9.7.10 The I2c smbus write block data() Function |
|
|
170 | (1) |
|
9.7.11 Miscellaneous Functions |
|
|
171 | (1) |
|
9.8 Reentrancy Issues with I2C Operations |
|
|
171 | (1) |
|
9.9 Multicontroller Operation Under Linux |
|
|
171 | (1) |
|
|
171 | (1) |
|
9.10.1 PINE A64 and ROCKPro64 |
|
|
172 | (1) |
|
|
172 | (1) |
|
|
172 | (1) |
|
9.11 Using the Raspberry Pi as an I2C Peripheral Device |
|
|
172 | (1) |
|
|
173 | (2) |
|
10 I2C Programming In Real-Time Operating Systems |
|
|
175 | (32) |
|
10.1 Real-Time Operating System Basics |
|
|
176 | (4) |
|
10.1.1 Processes and Threads |
|
|
177 | (1) |
|
10.1.2 Multithreading and Multitasking |
|
|
177 | (1) |
|
|
178 | (1) |
|
|
179 | (1) |
|
10.1.5 Safety Critical Systems |
|
|
179 | (1) |
|
10.2 Real-Time Operating System I2C Programming |
|
|
180 | (23) |
|
|
180 | (9) |
|
10.2.2 FreeRTOS I2C Programming |
|
|
189 | (5) |
|
10.2.3 Teensy Threads I2C Programming |
|
|
194 | (5) |
|
10.2.4 Mbed I2C Programming |
|
|
199 | (4) |
|
10.3 Other Real-Time Operating System I2C Programming |
|
|
203 | (1) |
|
|
204 | (3) |
|
11 Bare-Metal I2C Controller Programming |
|
|
207 | (44) |
|
11.1 Teensy 4.x Controller Programming |
|
|
208 | (40) |
|
11.1.1 I.MX RT1062 l2C Registers |
|
|
209 | (6) |
|
11.1.2 Teensy 4.x Wire Code |
|
|
215 | (19) |
|
11.2 A Ttiny Controller Programming |
|
|
234 | (2) |
|
11.2.1 The Atto84 Triangle Wave Demonstration Program |
|
|
236 | (12) |
|
|
248 | (3) |
|
PART IV I2C PERIPHERAL PROGRAMMING EXAMPLES |
|
|
251 | (132) |
|
12 The TCA9548A I2C Bus Expander |
|
|
253 | (8) |
|
12.1 The TCA9548A I2C Multiplexer |
|
|
254 | (4) |
|
12.1.1 Upstream and Downstream Devices |
|
|
254 | (1) |
|
12.1.2 The TCA9548A Selection Register |
|
|
255 | (1) |
|
12.1.3 TCA9548A Address and Reset Lines |
|
|
255 | (1) |
|
12.1.4 The TCA9548A Power Supply, Pullups, and Level Shifting |
|
|
256 | (1) |
|
12.1.5 Reducing Bus Loading and Bus Speed |
|
|
256 | (1) |
|
12.1.6 Switching Between Buses |
|
|
257 | (1) |
|
12.1.7 Cascading TCA9548A Multiplexers |
|
|
257 | (1) |
|
12.2 The Adafruit TCA9548A I2C Expander |
|
|
258 | (1) |
|
12.3 The SparkFun I2C Mux |
|
|
259 | (1) |
|
|
260 | (1) |
|
13 THE MCP23017 AND MCP23008 Gpio Expanders |
|
|
261 | (38) |
|
13.1 The MCP23017 and MCP23008 Pinouts |
|
|
262 | (2) |
|
|
264 | (11) |
|
13.2.1 Accessing MCP230xx Registers |
|
|
266 | (1) |
|
13.2.2 MCP230xx Initialization |
|
|
266 | (2) |
|
13.2.3 Programming the Data Direction |
|
|
268 | (1) |
|
13.2.4 Programming Input Pullup Resistors |
|
|
269 | (1) |
|
13.2.5 Programming the Input Polarity |
|
|
270 | (1) |
|
13.2.6 Sequential Register Operations |
|
|
271 | (2) |
|
|
273 | (1) |
|
13.2.8 Reading General-Purpose Input/Output Pins on the MCP230xx |
|
|
274 | (1) |
|
13.3 Writing General-Purpose Input/Output Pins on the MCP230xx |
|
|
275 | (1) |
|
13.4 Demonstrating Input/Output on an MCP23017 |
|
|
276 | (4) |
|
13.5 Interrupts on the MCP230xx |
|
|
280 | (6) |
|
13.5.1 Interrupt Actions on the MCP230xx |
|
|
280 | (1) |
|
13.5.2 Interrupt Service Routines |
|
|
281 | (2) |
|
13.5.3 Mirroring INTx Pins (MCP23017 Only) |
|
|
283 | (1) |
|
13.5.4 Open-Drain INTx Output |
|
|
283 | (1) |
|
13.5.5 Enabling Interrupts on the MCP230xx |
|
|
284 | (1) |
|
13.5.6 Testing and Clearing Interrupts |
|
|
285 | (1) |
|
13.6 A Sample Interrupt-Driven MCP230xx |
|
|
286 | (9) |
|
13.7 MCP230xx Library Code |
|
|
295 | (1) |
|
|
295 | (1) |
|
|
296 | (1) |
|
|
296 | (3) |
|
14 THE ADS1015 AND ADS1115 Analog-To-Digital Converters |
|
|
299 | (42) |
|
14.1 Analog-to-Digital Converter Specifications |
|
|
300 | (5) |
|
14.1.1 Analog-to-Digital Converter Resolution |
|
|
301 | (1) |
|
14.1.2 Analog-to-Digital Converter Channel Count |
|
|
301 | (1) |
|
14.1.3 Analog-to-Digital Converter Polarity |
|
|
302 | (1) |
|
14.1.4 Analog-to-Digital Converter Range |
|
|
302 | (1) |
|
14.1.5 Differential vs. Single-Ended Modes |
|
|
303 | (1) |
|
|
304 | (1) |
|
14.1.7 Miscellaneous ADS1 × 15 Features |
|
|
305 | (1) |
|
|
305 | (4) |
|
14.3 ADS1 × 15 Analog-to-Digital Converter Registers |
|
|
309 | (7) |
|
14.3.1 The Conversion Register |
|
|
310 | (1) |
|
14.3.2 The Configuration Register |
|
|
310 | (5) |
|
14.3.3 The Low and High Threshold Registers |
|
|
315 | (1) |
|
14.4 The Adafruit ADS1 × 15 Breakout Boards |
|
|
316 | (2) |
|
14.5 An ADS1 × 15 Programming Example |
|
|
318 | (5) |
|
14.6 Improving Polling Performance |
|
|
323 | (4) |
|
14.7 Improving Performance Using Continuous Scanning |
|
|
327 | (3) |
|
14.8 Interrupts and the ADS1 &tiems; 15 |
|
|
330 | (1) |
|
|
331 | (7) |
|
14.9.1 Computing Means and Medians |
|
|
331 | (7) |
|
|
338 | (3) |
|
15 THE MCP4725 DIGITAL-TO-ANALOG CONVERTER |
|
|
341 | (8) |
|
|
342 | (2) |
|
15.2 The Fast Write Command |
|
|
344 | (1) |
|
|
344 | (1) |
|
|
345 | (1) |
|
|
346 | (1) |
|
|
347 | (2) |
|
16 Bare-Metal Peripheral Programming |
|
|
349 | (34) |
|
16.1 The A Ttiny as an I2C Peripheral |
|
|
350 | (1) |
|
16.2 Introducing the Memory Peripheral |
|
|
351 | (2) |
|
16.3 The Memory Peripheral Software Architecture |
|
|
353 | (28) |
|
|
354 | (5) |
|
16.3.2 The Interrupt Service Routine Library |
|
|
359 | (21) |
|
16.3.3 A Sample Controller Application |
|
|
380 | (1) |
|
|
381 | (2) |
Epilogue |
|
383 | (2) |
A The Adafruit I2C Address Compilation |
|
385 | (8) |
B Online Chapters |
|
393 | (4) |
Glossary |
|
397 | (6) |
Index |
|
403 | |