I2C Calculator – SCL Timing, TWBR Register, t_HIGH/t_LOW for AVR, STM32, ESP32

Calculate I2C SCL timing parameters (t_HIGH, t_LOW, t_r, t_f) for Standard, Fast, Fast-plus, and High-speed modes. Compute AVR TWBR register value, actual SCL frequency, and error% for all 4 I2C speed modes with prescaler selection. Runs in your browser.

What is I2C?

I2C (Inter-Integrated Circuit, sometimes written I²C) is a synchronous half-duplex serial communication protocol developed by Philips Semiconductors (now NXP) in 1982. It uses only two bidirectional wires — SDA (Serial Data) and SCL (Serial Clock) — making it one of the most compact bus protocols in embedded systems. Both lines are open-drain: devices can only pull the lines LOW, and external pull-up resistors return the lines to HIGH when no device is pulling them down. This open-drain topology allows multiple masters and multiple slaves to share the same two-wire bus without dedicated arbiter hardware.

I2C is found on virtually every modern microcontroller and is used to connect sensors, EEPROMs, real-time clocks, DACs, ADCs, display controllers, and more. A single MCU can control dozens of peripherals with just two GPIO pins, with each slave identified by a unique 7-bit (or 10-bit) address. The trade-off is lower throughput and higher protocol overhead compared to SPI — but for configuration registers, sensor readings, and similar low-bandwidth tasks, I2C is the industry standard.

I2C Frame Structure

Every I2C transaction is framed by a START condition and a STOP condition generated by the master. In between, data is transferred in 8-bit bytes, each followed by a 1-bit acknowledgement from the receiver.

  • START condition — SDA falls while SCL is HIGH. This signals all slaves to listen for their address.
  • Address byte — 7-bit slave address (MSB first) followed by a R/W̅ bit: 0 for write, 1 for read.
  • ACK/NACK — After each byte, the receiver pulls SDA LOW (ACK) or leaves it HIGH (NACK) during the 9th clock pulse. A NACK after the address means no slave responded.
  • Data bytes — One or more 8-bit data bytes, each followed by an ACK.
  • STOP condition — SDA rises while SCL is HIGH. This releases the bus.
  • Repeated START — A master can issue a new START without a STOP to change direction (write then read) without releasing the bus.
S | ADDR[6:0] | R/W | ACK | DATA[7:0] | ACK | ... | P
  |← 7 bits →|  1  |  1  |← 8 bits →|  1  |     |

How to Use This Calculator

SCL Timing Calculator

The first tab calculates I2C bus timing parameters for a selected speed mode. Choose Standard (100 kHz), Fast (400 kHz), Fast-plus (1 MHz), High-speed (3.4 MHz), or enter a custom SCL frequency. The result panel shows SCL frequency and period, minimum t_HIGH and t_LOW required by the I2C specification, theoretical bit time, and maximum bus throughput. A frame diagram illustrates the byte structure with a 7-bit address, R/W bit, ACK, and data byte. The timing spec note below the diagram shows the exact limits from the I2C specification for the selected mode.

TWBR Register Calculator

The second tab computes the TWBR (TWI Bit Rate Register) value for AVR microcontrollers (ATmega, ATtiny with hardware TWI). Select your MCU clock, prescaler (TWPS bits in TWSR), and target I2C speed mode. The result card shows the TWBR value to write, the actual SCL frequency achieved, and the error percentage. A comparison table below shows all four I2C speed modes with their TWBR values and errors for the selected MCU clock and prescaler.

I2C Speed Modes and Timing Specification

ModeMax SCLt_HIGH mint_LOW mint_r maxt_f max
Standard (Sm)100 kHz4.0 µs4.7 µs1000 ns300 ns
Fast (Fm)400 kHz0.6 µs1.3 µs300 ns300 ns
Fast-plus (Fm+)1 MHz260 ns500 ns120 ns120 ns
High-speed (Hs)3.4 MHz60 ns160 ns40 ns40 ns

Rise time (t_r) is limited by the RC time constant of the pull-up resistor and bus capacitance. For a 400 pF bus with a 4.7 kΩ pull-up: t_r ≈ 0.8473 × R × C ≈ 1590 ns — too slow for Fast mode. Reducing to 1 kΩ: t_r ≈ 338 ns — within Fast-mode spec. Pull-up selection is a key design step when using Fast or Fast-plus modes.

AVR TWBR Register Formula

AVR microcontrollers (ATmega328P, ATmega2560, etc.) implement I2C as TWI (Two-Wire Interface). The SCL frequency is determined by the CPU clock, TWBR value, and the prescaler set by TWPS[1:0] bits in TWSR:

TWBR = (f_cpu / f_scl − 16) / (2 × prescaler)
f_scl = f_cpu / (16 + 2 × TWBR × prescaler)

TWBR must be in the range 0–255 (8-bit register). The prescaler multiplies the divisor: TWPS=00 gives ×1, TWPS=01 gives ×4, TWPS=10 gives ×16, TWPS=11 gives ×64. For 16 MHz CPU and 100 kHz I2C with prescaler ×1: TWBR = (16,000,000 / 100,000 − 16) / (2 × 1) = 72. Write TWBR = 72 and clear both TWPS bits in TWSR.

The I2C specification allows a wider error tolerance than UART because the master drives the clock and both sides share the same SCL signal. There is no accumulated error over a frame — the receiver samples SDA on each SCL edge. In practice, errors below ±5% are acceptable for all I2C modes.

Frequently Asked Questions

What is I2C and how does it work?

I2C is a two-wire synchronous serial protocol (SDA + SCL) with open-drain bus topology and pull-up resistors. The master generates the clock and a START condition, then sends a 7-bit slave address with R/W bit. Each byte is acknowledged by the receiver. The master ends with a STOP condition.

What is the difference between I2C Standard, Fast, Fast-plus, and High-speed modes?

Standard: 100 kHz, t_HIGH ≥ 4 µs, t_LOW ≥ 4.7 µs. Fast: 400 kHz, t_HIGH ≥ 0.6 µs. Fast-plus: 1 MHz, t_HIGH ≥ 260 ns, requires stronger drive current. High-speed: 3.4 MHz, requires a master code handshake and current-source pull-ups. Most devices support Standard and Fast.

How is the TWBR register calculated for AVR microcontrollers?

TWBR = (f_cpu / f_scl − 16) / (2 × prescaler). The prescaler is set by TWPS bits in TWSR: 1, 4, 16, or 64. For 16 MHz / 100 kHz / prescaler 1: TWBR = (160 − 16) / 2 = 72.

What are pull-up resistors and why does I2C need them?

I2C uses open-drain outputs — devices can only pull lines LOW. External pull-up resistors pull lines HIGH when released. The resistor value is a speed vs. power trade-off: 4.7 kΩ for Standard, 1–2.2 kΩ for Fast. Too high a value and the rise time (t_r) exceeds the spec limit for the mode.

What is the difference between 7-bit and 10-bit I2C addressing?

7-bit addressing gives 128 addresses (16 reserved). 10-bit extends to 1024 addresses using a two-byte prefix sequence (11110xx + 8-bit LSBs). Most devices use 7-bit addressing. Both modes can coexist on the same bus.

What is clock stretching in I2C?

A slave can hold SCL LOW to pause the transaction when it needs more time to process data. Since both SDA and SCL are open-drain, the slave just holds SCL LOW after the master releases it. Not all slaves implement clock stretching, and some masters (especially bit-banged ones) do not handle it.

What is an ACK and NACK in I2C?

After each 8-bit byte, the receiver drives SDA LOW during the 9th clock pulse (ACK = accepted) or leaves it HIGH (NACK = rejected or end of read). A NACK after the address byte means no device at that address responded.

Can I2C be used for long-distance communication?

I2C is designed for on-board use — bus capacitance is limited to 400 pF (Standard/Fast), restricting cable length to roughly 1–2 m. For longer distances use RS-485, CAN, or LIN. Bus extenders like PCA9600 can increase range by resetting the capacitance.

Related Tools

  • Bezier Curve Editor - Interactive cubic Bezier curve editor with real-time animation preview, 35 easing presets, side-by-side comparison, and code export for CSS, Unity C#, C++, and JavaScript.
  • SPI Calculator - Calculate SPI clock frequency from MCU clock and divider, transfer time, throughput, and bit/word periods. Browse all 8 clock dividers in a single table with speed class indicators. Supports SPI Mode 0–3 (CPOL/CPHA), MSB/LSB first, and word sizes of 8/16/32 bits. Runs in your browser.
  • Bit Mask Calculator - Build bitmasks visually on an 8/16/32/64-bit grid, generate C #define macros, and apply SET, CLEAR, TOGGLE, or READ operations to register values with bit layout visualization and C code output.
  • Drone Calculator - Calculate drone thrust, TWR, hover throttle, flight time, and battery C-rating safety. Compare up to 4 motor/battery/propeller configurations side by side.
  • Robot Arm FK/IK Calculator - Robot arm kinematics for learning & practice: FK/IK, DH tables, Jacobian—aligned with cobots, industrial robots, humanoid arms, and AI robotics workflows. Robot programming friendly (CSV export). 2–6 DOF, SCARA, UR/KUKA-style presets, 3D visualization. Runs in your browser.

SCL Timing Settings

SCL Timing
100.0 kHz — Standard (Sm) — 100 kHz
SCL Frequency
100.0 kHz
SCL Period
10.000 μs
t_HIGH (min)
4.000 μs
t_LOW (min)
4.700 μs
Bit Time
8.700 μs
Max Throughput
88.9 kbps
Frame Diagram
IDLE
S
A6
A5
A4
A3
A2
A1
A0
R/W
ACK
D7
D6
D5
D4
D3
D2
D1
D0
ACK
P
IDLE
IDLESTART / STOPAddressR/WACKData
Standard (Sm): t_HIGH ≥ 4.000 μs | t_LOW ≥ 4.700 μs | t_r ≤ 1.000 μs | t_f ≤ 300.0 ns
Many I2C sensors (BME280, AHT20, SMBus devices) use CRC-8 for data integrity. Use the CRC Calculator to compute CRC-8 checksums for your I2C data frames.