User Tools

Site Tools


the_i2c_bus

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
the_i2c_bus [2020/01/15 22:58] – [I²C in FRC] tellthe_i2c_bus [2022/02/03 09:06] (current) tell
Line 8: Line 8:
 Those two wires are called "SCL" and "SDA, for "serial clock" and "serial data." Those two wires are called "SCL" and "SDA, for "serial clock" and "serial data."
  
-Some basic facts aboutI²C+Some basic facts about I²C
-* It was originally intended to stay on the same PC board, but works over a few feet of cable +  * It was originally intended to stay on the same PC board, but works over a few feet of cable 
-* It runs at 100Kbps or 400Kbps +  * It runs at 100Kbps or 400Kbps 
-* Each "slave" device has an address, and each slave on the bus must have a unique address +  * Devices only pull SDA and SCL low 
-* Some devices have pins that can chose from several addresses.  Others are limited to one per bus because the address can't be changed.+  * Pullup resistors are required on SDA and SCL, but most boards have the installed already. 
 +  * Each "slave" device has an address, and each slave on the bus must have a unique address. 
 +  * Addresses are 7 bits long, therefore there are only 128 possible addresses. 
 +  * Some devices have pins that can chose from several addresses.  Others are limited to one per bus because their address can't be changed.
  
 +
 +====== I²C Protocol ======
 +
 +The I²C standard defines the basic signaling on the two wires for sending data back and forth to the device.  The primitives available are:
 +  * Claim the bus and start a transaction: pull SDA low while leaving SCL high
 +  * Stop and release the bus: release SDA to go high, while leaving SCL high
 +  * Send a byte (and get an acknowlegement)
 +  * Read a byte
 +  
 +This figure shows the basic idea: start, write one byte, acknowledge, stop:
 +
 +{{ :i2c-protocol.png |}}
 +
 +All transfers start as shown here, with the master sending one byte onto the bus containing the 7 bit address and one bit that indicates whether the next byte will be a write (master to slave) or a read (slave sends to master).
 +
 +A good, relatively simple explanation of data transfer is https://i2c.info/i2c-bus-specification
 +
 +These get combined in various ways depending on the device.  Reading the datasheet is a must while writing software for an I2C device.
  
 ====== I²C in FRC ====== ====== I²C in FRC ======
 {{ :roborio-i2c.png|}} {{ :roborio-i2c.png|}}
-Since the introduction of the RoboRio, there has been an easy way to use I²C for FIRST robots.  The connector on the Rio looks like this.  The connector has four pins.  In addition to SCL and SDA, there is a pin for 3.3v power, and a pin for the common ground for signal and power.  This means that no external power source is needed or recommended for attaching an I2C device.+Since the introduction of the RoboRio, there has been an easy way to use I²C for FIRST robots.  The connector on the Rio looks like this.  The connector has four pins, but otherwise looks like the common "PWM" connectors. 
 +It uses the same housings and headers that hold pins on 0.1 inch centers. 
 + 
 +In addition to SCL and SDA, there is a pin for 3.3v power, and a pin for the common ground for signal and power.  This means that no external power source is needed or recommended for attaching an I2C device.
  
 Around 2018-2019 we started to see packaged color and distance sensors from Rev Robotics and others. Around 2018-2019 we started to see packaged color and distance sensors from Rev Robotics and others.
Line 28: Line 52:
  
 Nearly every I²C device has unique requirements from the software to communicate with it. Fortunately, the success of the Arduino family of microcontroller boards means that almost every interesting I²C device has example code ready to use with the arduino board and software. Nearly every I²C device has unique requirements from the software to communicate with it. Fortunately, the success of the Arduino family of microcontroller boards means that almost every interesting I²C device has example code ready to use with the arduino board and software.
-This is often the best place to find such examples.  
- 
  
 +This is often the best place to find such examples.  Reading the sample code can help you understand the part's datasheet.
  
 +By 2021 there appeared FRC Java libraries for some of the I²C sensors that we've used.  But going back to the Arduino C code is necessary for some of the interesting ones that are less common in FRC.
  
  
 ====== I²C in other maker/hobby wiring ====== ====== I²C in other maker/hobby wiring ======
 +
  
 ===== QWIIC ===== ===== QWIIC =====
Line 40: Line 65:
 [[http://sparkfun.com | Sparkfun]] has many sensor boards and controllers that use a tiny 4-pin connector they call [[http://sparkfun.com/qwiic|QWIIC]].  It carries the SDA and SCL signals, ground, and +3.3v power. [[http://sparkfun.com | Sparkfun]] has many sensor boards and controllers that use a tiny 4-pin connector they call [[http://sparkfun.com/qwiic|QWIIC]].  It carries the SDA and SCL signals, ground, and +3.3v power.
  
-(picture)+{{ :quicc-board-cable.png |}}
  
 Adafruit wants to call the same thing [[https://learn.adafruit.com/introducing-adafruit-stemma-qt|STEMMA-QT.]] Adafruit wants to call the same thing [[https://learn.adafruit.com/introducing-adafruit-stemma-qt|STEMMA-QT.]]
 +
 +===== Eastbots I2C Tester =====
 +
 +In 2019 we had some flaky i2c operation, so we built this wiring tester
 +[[testing_i2c_wiring]]
 +
 +
the_i2c_bus.1579147101.txt.gz · Last modified: 2020/01/15 22:58 by tell