Summary of I2C Protocol

Source: Internet
Author: User
Tags ack
I2C ProtocolTwo-line serial protocol (SCL, SDA), master-slave mode, support multiple master, but at the same time only one Master address composition: 7bit address array +1bit read-write bit, a total of 8bit. Address range 0~127, 0 address is broadcast address. Send 8bit data at a time, the data format is big-endian mode. Rate: Standard mode 100Kbps, fast mode 400Kbps, high speed mode 3.4Mbps. Bus Interconnect

Note that both the SDA and the SCL require pull up.
Bus sequence Diagram The SCL is provided by Master, and only master can control both the SCL and the SDA SCL at low power times to change the data, the SCL is high power, and the data is valid. Starting condition: When the SCL is high, master pulls down SDA and the bus enters the start state. End condition: When SCL is high, master pulls high SDA, bus goes to stop state. Whether it's sending an address or data, it's followed by a ack/nack. When Master writes the data, ACK and Nack are provided by slave. In master read data, ACK and NACK are provided by master. The following is a master Write data example: ACK: In the 9th CLK cycle, slave pulls down SDA, sends an ACK NACK: in the 9th CLK cycle, Slave keeps SDA high, sending a NACK one time can transmit multiple bytes until master sends start/ Stop If the slave device is too late to process data, it can keep the SCL low, forcing master to enter the wait state.

I2C Master Sample code (GPIO simulation)

can refer to: STM32 under the simulation I2C C language implementation I2C slave Example

I2C slave implementation should be more difficult than I2C master, the implementation of a different SCM I2C slave need hardware support, so the specific implementation code may be different, the following to Atmel SCM for example.

The following is the interface design for the Tinywires library:

The use code for the Tinywires class is as follows:

#define I2C_SLAVE_ADDRESS 0x4//Address of the SLAVE

#include <TinyWireS.h>

int i=0;

void Setup ()
{
    tinywires.begin (i2c_slave_address);//Join I2C network
    tinywires.onrequest (requestevent );
    Turn on the LED when the program starts
    pinmode (1, OUTPUT);
    Digitalwrite (1, high);
}

void Loop ()
{
    //This needs to is here
    Tinywires_stop_check ();
}

Gets called when the Attiny receives a I2C request
void Requestevent ()
{
    tinywires.send (i);
    i++;
}

Tinywires State machine:

Code address: The difference between Https://github.com/rambo/TinyWire.git I2C and SMBus

Clock Speed Comparison

Item I2C SMBus
Minimum None Ten KHz
Maximum KHz (Standard mode) 100KHz
KHz (Fast mode)
2 MHz (High Speed mode
Timeout None Ms

Electrical characteristics Comparison

item i2c smbus
vhigh Fixed voltage:3.0 to Vdd_max + 0.5V 2.1V to VDD
VDD relative:0.7 to Vdd_max + 0.5V
Vlow Fixed Voltage: -0.5v to 1.5V to 0.8V
VDD relative: -0.5 to 0.3VDD
Max Current 3 MA 350µa

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.