-
Notifications
You must be signed in to change notification settings - Fork 5
MichaelMeissner edited this page Mar 12, 2020
·
29 revisions
- I2C is a shared bus system that allows multiple devices to be hooked to a microprocessor using short wires.
- Devices can either be the I2C master or slave.
- Each I2C slave has an address it listens to. On some devices there are solder pads or pins that allow you to configure which I2C address is used. Other devices have an I2C command that allows you to change the I2C address. Other I2C devices just have a single I2C address.
- There are I2C multiplexers out there that allow you to connect multiple I2C devices that have the same address. One such multiplexer is the Adafruit TCA9548A board (https://www.adafruit.com/product/2717) that allows you to split an I2C bus into 8 separate I2C buses.
- An older Arduino I2C tutorial is at: (http://www.gammon.com.au/i2c).
- I2C has 4 pins: Power, ground, SDA, and SCL.
- The main I2C library is in
#include <Wire.h>
(https://www.pjrc.com/teensy/td_libs_Wire.html) - An alternative I2C library for Teensy LC & 3.2/3.5/3.6 is
#include <i2c_t3.h>
(https://github.com/nox771/i2c_t3) - Unfortunately, i2c_t3.h has not yet been ported to the Teensy 4.0.
- On ARM based systems (Teensy LC, 3.2, 3.5, 3.6, and 4.0) you need to have 2 pull-up resistors on the I2C bus.
- One resistor goes between the SDA pin and 3.3v power in parallel to the data connection(s).
- One resistor goes between the SCL pin and 3.3v power in parallel to the data connection(s).
- On I2C buses that support 5 volts, a common value for the pull-up resistors is 4.7K ohms. On I2C buses that are 3.3 volts only, a common value for the pull-up resistors is 2.2K ohms. However, complex I2C buses can need different values for the resistors.
- Many I2C devices provide their own pull-up resistors.
- You can have multiple pull-up resistors on the I2C bus, and generally they will work together. However, having multiple pull-up resistors can mean the devices might not be able to handle faster I2C bus speeds.
- If no devices have pull-up resistors, I2C requests may hang.
Teensy is a PJRC trademark. Notes here are for reference and will typically refer to the ARM variants unless noted.