
The Book of I²C: A Guide for Adventurers
- Length: 440 pages
- Edition: 1
- Language: English
- Publisher: No Starch Press
- Publication Date: 2022-10-11
- ISBN-10: 171850246X
- ISBN-13: 9781718502468
- Sales Rank: #2459467 (See Top 100 Books)
An extensive practical guide to connecting real-world devices to microcontrollers with the popular I2C bus.
If you work with embedded systems, you’re bound to encounter the ubiquitous Inter-Integrated Circuit bus (IIC or I2C) – a serial protocol for connecting integrated circuits in a computer system. In The Book of I2C, the first comprehensive guide to this bus, bestselling author Randall Hyde draws on 40 years of industry experience to get you started designing and programming I2C systems.
Aided by over 100 detailed figures and annotated source-code listings, you’ll learn the I2C implementations of systems like Arduino, Teensy, and Raspberry Pi, as well as variants of the I2C and common I2C peripheral ICs complete with programming examples. For hardware hackers, electronics hobbyists, and software engineers of every skill level, the extensive coverage in this book will make it a go-to reference when it comes to connecting real-world devices to I2C microcontrollers.
Cover Title Page Copyright Dedication About the Author Acknowledgments Introduction Expectations and Prerequisites Source Code in This Book Typography and Pedantry A Note About Terminology Organization Part I: Low-Level Protocols and Hardware Chapter 1: I2C Low-Level Hardware 1.1 I2C Overview 1.2 Open-Drain (Open-Collector) Logic and Four-Wire Mode 1.3 I2C Signal Levels 1.3.1 Level Shifting 1.4 Choosing Pullup Resistor Sizes 1.5 Bus Capacitance and Pullup Resistor Values 1.5.1 What If the Bus Capacitance Is Too High? 1.6 I2C Bus Speeds 1.7 Multicontroller I2C Bus Clock Synchronization 1.8 Multicontroller I2C Bus Arbitration 1.9 Clock Stretching 1.10 Cross Talk 1.11 Chapter Summary Chapter 2: I2C Protocol 2.1 Data on the I2C Bus 2.2 I2C Addresses and Read/Write Control 2.3 Repeated Start Conditions 2.4 Clock Stretching 2.5 Special Addresses 2.5.1 The General Call Address 2.5.2 Hardware General Calls 2.5.3 Start Byte 2.5.4 CBUS and Reserved Addresses 2.5.5 High-Speed Mode Controller Code 2.5.6 10-Bit Peripheral Addressing 2.5.7 Device ID 2.6 Resetting the I2C Bus 2.7 Detecting I2C Peripherals on the Bus 2.8 Creating Custom Devices 2.9 Chapter Summary Chapter 3: A Software Implementation of the I2C Bus 3.1 A Software I2C Implementation on the Teensy 3.2 3.1.1 A Software-Based I2C Controller for the Teensy 3.2 3.1.2 A Software-Based I2C Peripheral for the Teensy 3.2 3.1.3 Some Final Comments on the Teensy 3.2 Software I2C Code 3.2 Basic ATtiny84 and ATtiny85 Hardware 3.2.1 Atto84 Software-Based I2C Peripheral 3.3 Chapter Summary Chapter 4: Tools for Analyzing and Debugging I2C Transmissions 4.1 Generic Hardware Testing and Debugging Tools 4.2 Logic Analyzers 4.3 The I2C Driver 4.4 The Bus Pirate 4.5 The Saleae Logic Analyzers 4.6 A Final Comment on I2C Monitors and Logic Analyzers 4.7 Chapter Summary Chapter 5: I2C Variants 5.1 SMBus 5.1.1 Differences Between SMBus and Standard I2C 5.1.2 SMBus Electrical Specifications 5.1.3 SMBus Reserved Addresses 5.1.4 SMBus Protocol Commands 5.2 VESA DDC and E-DDC 5.3 ACCESS.bus 5.4 Two-Wire Interface and Two-Wire Serial Interface 5.5 Chapter Summary Part II: Hardware Implementations Chapter 6: I2C On Common Single-Board Computers 6.1 The Arduino Family 6.1.1 The Arduino Uno Rev3 and Leonardo 6.1.2 The Arduino Nano 6.1.3 The Arduino Micro 6.1.4 The Arduino Nano Every 6.1.5 The Arduino Mega 2560 Rev3 6.1.6 The Arduino Zero 6.1.7 The Arduino Due 6.1.8 Other Arduino-Brand Single-Board Computers 6.2 Adafruit Single-Board Computers 6.3 SparkFun Single-Board Computers 6.4 The Teensy Family 6.5 Other Arduino-Compatible Single-Board Computers 6.6 The Raspberry Pi 6.7 The Raspberry Pi Pico 6.8 The BeagleBone Black 6.9 The PINE A64 and ROCKPro64 6.10 The Onion Omega 6.11 The STM32 Single-Board Computer Family 6.11.1 STM32F767/Nucleo-144 6.11.2 STM32F746G-Disco 6.11.3 STM32 Boards Galore 6.12 The NetBurner MOD54415 6.13 I2C on the Personal Computer 6.14 Chapter Summary Chapter 7: I2C On Vendor Buses 7.1 The Adafruit Feather Bus 7.1.1 Feather Bus Pinouts 7.1.2 I2C on the Feather Bus 7.1.3 Multicontroller Operation 7.1.4 Feathers and FeatherWings 7.2 I2C on the SparkFun Qwiic Bus 7.3 Qwiic Bus Peripherals 7.4 I2C on the Seeed Studio Grove Bus 7.5 Chapter Summary Part III: Programming the I2c Bus Chapter 8: Arduino I2C Programming 8.1 Basic I2C Programming 8.2 Basic Wire Programming 8.2.1 Wire Utility Functions 8.2.2 Wire Read Operations 8.2.3 Wire Write Operations 8.2.4 Wire Peripheral Functions 8.3 Arduino I2C Write Example 8.4 Arduino I2C Read Example 8.5 Arduino I2C Peripheral Example 8.6 Multiple I2C Port Programming 8.7 Chapter Summary Chapter 9: Raspberry Pi (and Linux) I2C Programming 9.1 The I2C Bus Pins on the Pi General-Purpose Input/Output Header 9.2 Manually Activating the I2C Buses 9.3 Changing the I2C Clock Frequency 9.4 I2C Clock Stretching Issues and Solutions 9.5 Raspberry Pi OS (Linux) I2C Utilities 9.6 Reading and Writing I2C Data 9.7 Advanced I2C Kernel Calls 9.7.1 The i2c-dev Functions 9.7.2 The i2c_smbus_write_quick Function 9.7.3 The i2c_smbus_read_byte Function 9.7.4 The i2c_smbus_write_byte() Function 9.7.5 The i2c_smbus_read_byte_data() Function 9.7.6 The i2c_smbus_write_byte_data() Function 9.7.7 The i2c_smbus_read_word_data() Function 9.7.8 The i2c_smbus_write_word_data() Function 9.7.9 The i2c_smbus_read_block_data() Function 9.7.10 The i2c_smbus_write_block_data() Function 9.7.11 Miscellaneous Functions 9.8 Reentrancy Issues with I2C Operations 9.9 Multicontroller Operation Under Linux 9.10 Other Linux Systems 9.10.1 PINE A64 and ROCKPro64 9.10.2 BeagleBone Black 9.10.3 Onion Omega2+ 9.11 Using the Raspberry Pi as an I2C Peripheral Device 9.12 Chapter Summary Chapter 10: I2C Programming in Real-Time Operating Systems 10.1 Real-Time Operating System Basics 10.1.1 Processes and Threads 10.1.2 Multithreading and Multitasking 10.1.3 Reentrancy 10.1.4 Synchronization 10.1.5 Safety Critical Systems 10.2 Real-Time Operating System I2C Programming 10.2.1 µC/OS 10.2.2 FreeRTOS I2C Programming 10.2.3 Teensy Threads I2C Programming 10.2.4 Mbed I2C Programming 10.3 Other Real-Time Operating System I2C Programming 10.4 Chapter Summary Chapter 11: Bare-Metal I2C Controller Programming 11.1 Teensy 4.x Controller Programming 11.1.1 i.MX RT1062 I2C Registers 11.1.2 Teensy 4.x Wire Code 11.2 ATtiny Controller Programming 11.2.1 The Atto84 Triangle Wave Demonstration Program 11.3 Chapter Summary Part IV: I2c Peripheral Programming Examples Chapter 12: The TCA9548A I2C Bus Expander 12.1 The TCA9548A I2C Multiplexer 12.1.1 Upstream and Downstream Devices 12.1.2 The TCA9548A Selection Register 12.1.3 TCA9548A Address and Reset Lines 12.1.4 The TCA9548A Power Supply, Pullups, and Level Shifting 12.1.5 Reducing Bus Loading and Bus Speed 12.1.6 Switching Between Buses 12.1.7 Cascading TCA9548A Multiplexers 12.2 The Adafruit TCA9548A I2C Expander 12.3 The SparkFun I2C Mux 12.4 Chapter Summary Chapter 13: The MCP23017 and MCP23008 GPIO Expanders 13.1 The MCP23017 and MCP23008 Pinouts 13.2 MCP230xx Registers 13.2.1 Accessing MCP230xx Registers 13.2.2 MCP230xx Initialization 13.2.3 Programming the Data Direction 13.2.4 Programming Input Pullup Resistors 13.2.5 Programming the Input Polarity 13.2.6 Sequential Register Operations 13.2.7 Slew Rate Control 13.2.8 Reading General-Purpose Input/Output Pins on the MCP230xx 13.3 Writing General-Purpose Input/Output Pins on the MCP230xx 13.4 Demonstrating Input/Output on an MCP23017 13.5 Interrupts on the MCP230xx 13.5.1 Interrupt Actions on the MCP230xx 13.5.2 Interrupt Service Routines 13.5.3 Mirroring INTx Pins (MCP23017 Only) 13.5.4 Open-Drain INTx Output 13.5.5 Enabling Interrupts on the MCP230xx 13.5.6 Testing and Clearing Interrupts 13.6 A Sample Interrupt-Driven MCP230xx 13.7 MCP230xx Library Code 13.8 I2C Performance 13.9 MCP23Sxx Parts 13.10 Chapter Summary Chapter 14: The ADS1015 and ADS1115 Analog-to-Digital Converters 14.1 Analog-to-Digital Converter Specifications 14.1.1 Analog-to-Digital Converter Resolution 14.1.2 Analog-to-Digital Converter Channel Count 14.1.3 Analog-to-Digital Converter Polarity 14.1.4 Analog-to-Digital Converter Range 14.1.5 Differential vs. Single-Ended Modes 14.1.6 Sample Frequency 14.1.7 Miscellaneous ADS1x15 Features 14.2 Analog Conditioning 14.3 ADS1x15 Analog-to-Digital Converter Registers 14.3.1 The Conversion Register 14.3.2 The Configuration Register 14.3.3 The Low and High Threshold Registers 14.4 The Adafruit ADS1x15 Breakout Boards 14.5 An ADS1x15 Programming Example 14.6 Improving Polling Performance 14.7 Improving Performance Using Continuous Scanning 14.8 Interrupts and the ADS1x15 14.9 Filtering Noise 14.9.1 Computing Means and Medians 14.10 Chapter Summary Chapter 15: The MCP4725 Digital-to-Analog Converter 15.1 MCP4275 Overview 15.2 The Fast Write Command 15.3 The Write Command 15.4 Power-Down Modes 15.5 The Read Command 15.6 Chapter Summary Chapter 16: Bare-Metal Peripheral Programming 16.1 The ATtiny as an I2C Peripheral 16.2 Introducing the Memory Peripheral 16.3 The Memory Peripheral Software Architecture 16.3.1 The Main File 16.3.2 The Interrupt Service Routine Library 16.3.3 A Sample Controller Application 16.4 Chapter Summary Epilogue Appendix A: The Adafruit I2C Address Compilation Appendix B: Online Chapters Glossary A B C D E F G H I J L M O P R S T U Index
How to download source code?
1. Go to: https://nostarch.com/
2. Search the book title: The Book of I²C: A Guide for Adventurers
, sometime you may not get the results, please search the main title
3. Click the book title in the search results
3. Download the Source Code.
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.