LogoLogo
  • Welcome!
  • Mission Statement
  • Contributing Guidelines
    • Embed CADs in Wiki Articles
  • VEX Worlds Livestream Archive
    • VEX U
    • V5RC High School
    • V5RC Middle School
    • VIQRC Middle School
    • VIQRC Elementary School
    • JROTC
  • ⚙️Hardware
    • Design Fundamentals
      • Gear Ratios
      • Internal Forces (Stress)
      • Torque
      • RPM
      • Center of Mass
    • Introduction to VEX Parts
      • Structure
        • C-Channels and Angles
        • Fasteners
        • Retainers
        • Gussets and Brackets
        • Bearings
        • Plate Metal and Flat Bars
      • Motion
        • High Strength Components
        • Gears and Sprockets
        • Traction Wheels
        • Mecanum Wheels
        • Omnidirectional Wheels
        • Flex Wheels
    • Robot Decorations
      • Part Dyeing
      • Metal Coloring
      • License Plate Holders
    • Lifts
      • Double Reverse Four Bar (DR4B or RD4B)
      • Four Bar
      • Scissor Lift
      • Six Bar
      • Other Lifts
      • Best Practices
    • Shooting Mechanisms
      • Catapult
      • Flywheel
      • Linear Puncher
    • Drivetrains
      • Tank Drive
      • Mecanum Drive
      • Holonomic Drive
      • Designing a Drivetrain
      • Best Practices
    • Pivots & Joints
    • Pneumatics
      • Best Practices - Pneumatics
    • Intakes
    • Flip Out Mechanisms
    • Defensive Mechanisms
    • Misc. Building Techniques
    • VexU
      • Common Manufacturing Techniques
        • 3D Printing
        • Laser Cutting
      • Custom Manufactured Parts Library
      • Commercial Off The Shelf Parts Library
  • 👑Team Administration
    • New Team Resources
      • Creating The Team
      • Gaining Interest for Robotics Teams
      • Attending Competitions
        • Elimination Bracket
    • Team Dynamics
      • Organization Structure and Longevity
      • Member Allocation and Management
      • How *Not* To Run a Team
    • Team Finances
      • One-Year Team Financial Breakdown
      • Funding Your Teams
    • Hosting Competitions
      • Live Streaming
      • Tournament Manager
        • Competition Electronics
        • Creating a Tournament
        • Tools
          • Field Set Control
          • Connecting Mobile Devices
          • Connecting Raspberry Pis
        • Match Control
          • Inputting Match Scores
          • Inputting Skills Scores
          • Inputting Scores on TM Mobile
        • Displays
        • Alliance Selection
      • Additional Event Partner Resources
    • VexU Organization Management
      • Getting Started in VexU
      • Team / Personnel Management
      • Volunteering At Local Events
  • 📚The Judging Process
    • The Engineering Design Process
      • Test and Refine
    • The Engineering Notebook
      • Segments of the Notebook
      • BLRS2 '23-'24 Engineering Notebook
      • Integrating Inventor Models into Documentation
      • Engineering Notebook Rubric Breakdown
    • The Interview
      • Interview Rubric Breakdown
    • Using Notion for an Engineering Notebook
      • How to Setup a Notebook
      • How to Create Entries
      • How to Export a Notebook
      • Purdue SIGBots Notion Template
        • Game Analysis
        • Identify The Problem
        • Brainstorm Solution
        • Select Best Approach & Plan
        • Build Log
        • Programming Log
        • Testing Solution
        • Tournament Recap
        • Innovative Feature
  • 🖥️VEX CAD
    • CAD Programs
      • Inventor
      • Fusion 360
      • Solidworks
      • OnShape
      • Protobot
    • Making a Chassis
      • Inventor Chassis: The Basics
        • Installation
        • User Interface Overview
        • Dark Mode
        • Assemblies
        • Placing Parts
        • Navigating CAD
        • Changing Visual Style
        • Grounding
        • Connecting Two C-Channels
        • Modifying Existing Constraints
        • Toggling Visibility on Existing Parts
        • Completing Half of the Chassis
          • Inner Drive Channel
          • Bearing Flats
          • Motors
          • Wheels
          • Sprockets
          • Spacers, Washers and Standoffs
          • Spacers Cont.
        • Creating Mid-Plane
        • Mirroring
      • Inventor Chassis: Best Practices
        • File Structure
        • Subassemblies
        • Wheel Subassembly
        • Origin Planes
        • Cross Brace
        • Drive Channels
        • Simple Motor iMates
        • Replacing Simple Electronics
        • Completing Half of the Drive
          • Bearing Flats (Best Practice)
          • Wheels
          • Powered Gear
          • Spacer Boxing
          • Spacers, Washers and Standoffs (Best Practice)
        • Model Browser Folders
        • Mirroring (Best Practice)
        • Model Browser Folder (Right)
        • Main Assembly
      • Fusion 360 Chassis
      • Solidworks Chassis, Chain, and Custom Plastic
    • Remembering The Best
      • 62A Skyrise
      • 400X Nothing But Net
      • 2587Z Nothing But Net
      • 365X Starstruck
      • 62A In The Zone
      • 202Z In The Zone
      • 5225A In The Zone
      • 169A Turning Point
      • 929U Turning Point
      • 7K Tower Takeover
      • 5225A Tower Takeover
      • 62A Change Up
    • Scuff Controller
  • 💻Software
    • Odometry
    • Path Planning
    • Robotics Basics
      • Arcade Drive
      • Tank Drive
      • Joystick Deadzones
      • Curvature (Cheesy) Drive
      • Subsystem Toggling
    • Organizing Code
      • Code Style
      • Code Styling Guide
      • Writing Good Comments
      • Version Control
    • Control Algorithms
      • Bang Bang
      • PID Controller
      • Basic Pure Pursuit
      • Flywheel Velocity Control
      • Kalman Filter
      • Take Back Half (TBH) Controller
      • RAMSETE Controller
    • Competition Specific
      • Operator Control
      • Autonomous Control
    • C++ Basics for VEX Robotics
      • Basic Control Flow
      • Enumerations
      • Namespaces (::)
      • Multiple Files (C/C++)
    • VEX Programming Software
      • PROS
        • OkapiLib
      • vexide
      • Robot Mesh Studio (RMS)
      • EasyC
      • RobotC
      • VEXcode
      • Midnight C
    • General
      • Stall Detection
      • Register Programming
      • Sensors and Odometry in Autonomous
      • Embedded Programming Tips
      • Debugging
      • Bit Shift
      • Bit Mask
      • Autoformatting
      • Finite State Machine
      • Data Logging
    • Object Recognition
      • Red Green Buoy
      • AMS
      • OpenCV
      • OpenNI
    • 🤖AI in VRC: Pac-Man Pete
  • ⚡VEX Electronics
    • V5 ESD Protection Board
    • VEX Electronics
      • VEX V5 Brain
        • V5 Electronics Observations and Issues
      • VEX Controller
      • VEXnet and V5 Robot Radio
      • VEX Battery
      • VEX Motors
    • VEX Sensors
      • 3-Pin / ADI Sensors
        • Encoder
        • Potentiometer
        • Limit Switch
        • Bumper Switch
        • Accelerometer
        • Gyroscope
        • Ultrasonic
        • Line Tracker
        • LED Indicator
      • Smart Port Sensors
        • GPS Sensor
        • Rotation Sensor
        • Vision Sensor
        • Optical Sensor
        • Distance Sensor
        • Inertial Sensor (IMU)
        • 3-Wire Expander
    • V5 Brain Wiring Guide
    • Legacy
      • VEX Cortex
      • Power Expander
      • VEX Motor Controller
      • VEX Cortex Wiring Guide
  • General Electronics
    • General Topics
      • External Boards
        • ASUS Tinker Board S
        • Arduino
        • Beagleboard
        • Leaflabs Maple
        • LattePanda
        • Meadow F7 Micro
        • Netduino
        • ODROID-XU4
        • Pandaboard
        • Raspberry Pi
      • Analog-Digital Converter (ADC)
      • Bit-Bang
      • GPIO
      • I2C
      • Jitter
      • Line Noise
      • List of Tools
      • Output Drive
      • Power Consumption
      • Radius Array
      • Resettable Fuse (PTC)
      • SPI
      • Slew Rate
      • Stalling
      • USART
      • UART
      • 5 Volt Tolerant
      • DC Motor Basics
Powered by GitBook
LogoLogo

This work is licensed under a Attribution-ShareAlike 2.0 Generic License

On this page
  • Operation
  • Transmissions
  • Writing data
  • Reading data
  • End of transmission
  • Example usage

Was this helpful?

Edit on GitHub
Export as PDF
  1. General Electronics
  2. General Topics

I2C

An Inter-Integrated Circuit interface, or I2C interface for short, is a two-wire bidirectional synchronous serial protocol connecting a master and one or more slaves.

PreviousGPIONextJitter

Last updated 4 years ago

Was this helpful?

Operation

A typical I2C transaction showing both data reads and data writes

An I2C bus consists of two wires: SDA (serial data) and SCL (serial clock). The clock line allows for synchronous transmission, so I2C can achieve higher transmission speeds than an equivalent and does not require clock recovery. However, I2C peripherals are less common and harder to implement than a simple serial interface.

Both wires of an I2C bus are normally in the logic high state, held there by a tolerant of the highest voltage in use.

I2C buses can have up to 126 devices, of which only one can be the master at any given time (but multiple masters may transmit non-concurrently on the same bus). The master is responsible for starting and ending all communications. Each device has an address, a 7-bit number from 0x01 to 0x7F. Many devices can have their addresses configured to one of several available possibilities in this range.

Transmissions

A transmission begins with a start condition, when the SDA line is pulled low by the master while the SCL line is high. This causes all devices on the bus to begin listening. The master next transmits the address of the desired slave on the SDA line, with the data being shifted out most significant bit first on the rising edge of SCL. While SCL is high, the data on SDA may not change during a transmission, except for start and stop conditions.

If the master wants to read from the slave, the address is followed by a '1' bit; to write to the slave, the address is followed by a '0' bit. Slaves whose addresses do not match will disconnect and await the next transmission indicated by a START condition; the matching slave (if any) will respond with an ACK condition by pulling SDA low after the address has been transmitted.

Writing data

Communication can proceed in one of two ways. If the master indicated a request to write data, the master will continue to transmit data bytes in the same way that it transmitted the slave address. After each byte, the master will wait until the slave acknowledges before transmitting the next byte. The first byte transferred usually indicates a register address on the slave where further data will be stored. The next data byte will be stored at that address, and each subsequent data byte is often stored at the next register address, as the slave usually auto-increments the current address after each byte is received and stored. If only the address is transmitted, the slave will remember the address but will not write any data, which is useful for setting a register position for reading.

Reading data

If the master indicated a request to read data, the master will control the SCL line while reading data values on SDA. On each high-to-low transition on SCL, the slave will either pull SDA down or let it float high depending on the bit to be transferred; on the next low-to-high transition of SCL, the master will sample the bit. Bytes are shifted out of the slave starting with the current address, which is usually the last address written. The master will now acknowledge after each byte transferred, and will issue a no-acknowledge (NAK) after the last desired byte is read. After each byte is transmitted, the receiver will usually increment its register address, just like when writing data.

I2C is used by computer peripherals to communicate on the System Management Bus (SMBus)

End of transmission

After the end of a communication sequence with a particular slave, the master will issue a STOP condition by allowing SDA to float from low to high after releasing SCL, which causes all devices on the bus to begin monitoring once again for the next START condition.

The System Management Bus (SMBus) protocol developed by Intel, used to manage simple peripherals such as power supplies and fans in modern computers, uses a slower protocol that is otherwise nearly identical to I2C.

Example usage

  • i2cReadRegister(address, register, *value, count) - Accepts an address, register number, and data array, and reads count values from the device register into the array value passed by reference. Most devices automatically increment the register number after each read, allowing a block of registers to be read at once.

The i2cRead and i2cWrite functions may also be useful for more unusual slave devices; see the API documentation for more details.

Teams Contributed to this Article:

Pull-up resistors have slow , limiting the speed available for long wires; the I2C specification explicitly limits I2C buffer chip. I2C typically operates at clock speeds from 100 KHz to 400 KHz, resulting in real data transmission rates of approximately 80 Kbps to 350 Kbps. I2C is therefore slower than but faster than most UARTs. Due to the moderate data transmission rate, the and slew rate of the controlling devices themselves is generally not important.

Errors can occur during an I2C transmission, most of which the master can intelligently detect; errors such as , fighting between multiple masters, disobedient slaves pulling a signal low at incorrect times, and framing errors with the returned data are often indicated by flags in the master's I2C registers.

For the with , I2C is implemented in the core library. Since the vast majority of devices use an 8-bit register architecture, the most useful functions are:

i2cWriteRegister(address, register, value) - Accepts an address, register number, and value, and writes the value into the specified device register. This function only writes one register at a time. The address must be in the same format as that used by the (right-aligned in the seven least significant bits)

(Purdue SIGBots)

slew rates
SPI
output drive
noisy signals
VEX Cortex
PROS
Arduino
BLRS
UART