You are on page 1of 21

Cu lc b Nghin cu Khoa hc Khoa in in t

IC (Inter-Integrated Circuit) [Eye-to-see]


RPULL-UP: 1.8 k 47 k 1K8 4K7 10K + 5V + 3.3V
VCC

I2C BUS

Rp

Rp

BUT: 16 reserved addresses maximum 112 nodes canEEPROM MCU Sensor ADC Master Slave Slave Slave communicate on the same bus

Serial Clock SCL SDA Serial Data Line

MCU Slave

Device address: 7-bit or 10-bit addressing


1 Master 128 devices

127 Slaves

IC (Inter-Integrated Circuit)
MODE SPEED Standard mode: 100 kbit/s

One Master One Slave One Master Multi-slave Multi-master Multi-slave

Low-speed mode: 10kbit/s Fast mode: Fast mode plus: 400 kbit/s 1 Mbit/s

High Speed mode: 3.4 Mbit/s

IC (Inter-Integrated Circuit)

Idle Status

Timing diagram Idle Status

Transper data
Start sequence

Stop sequence

IC (Inter-Integrated Circuit) Read 1 byte Start sequence

ReStart sequence

Stop sequence

Write

Read

NAK

AK
AK NAK

AK
= 0 = 1

AK

(ACK) : Acknowledge (NACK) : Not Acknowledge

IC (Inter-Integrated Circuit) Read multi-byte Stop sequence

AK

AK

AK

NAK

IC (Inter-Integrated Circuit) Start sequence Write 1 byte Stop sequence

Write

AK

AK

AK

IC (Inter-Integrated Circuit) Write multi-byte Stop sequence

IC (Inter-Integrated Circuit)

Real-Time Clock DS1307 Module

IC (Inter-Integrated Circuit)

TRIAC Module

IC (Inter-Integrated Circuit) In PIC 16F887 MASTER SYNCHRONOUS SERIAL PORT (MSSP) MODULE MCU can be Master or Slave on I2C Bus 7-bit and 10-bit addressing

DS1307 Slave address: 0x68

IC (Inter-Integrated Circuit) I2C functions in i2c.h (Hi-tech PIC)

// Send Start sequence to Slave void i2c_start(); // Send Stop sequence to Slave void i2c_stop(); // Initialize i2c module void i2c_init(); unsigned char i2c_read(unsigned char ack); // ack = 1: Not Acknowledge // ack = 0: Acknowledge unsigned char i2c_write(unsigned char d); // d: 8-bit data

IC (Inter-Integrated Circuit) i2c_init function in i2c.c (Hi-tech PIC) void i2c_init() { RC3 = 1; RC4 = 1; TRISC3 = 1; TRISC4 = 1; //control by MSSP SSPADD = 9;// Baudrate = Fosc/4/(SSPADDR+1) SMP = 1; // slew rate control disabled for 100KHz baudrate SSPCON2 = 0; SSPCON = 0x28; //I2C Master Hardware mode }

IC (Inter-Integrated Circuit) #include i2c.h How to write Hi-tech C code for I2C module

// DS1307 7-bit address = 0b 110 1000 = 0x68 #define SLAVE_ADD 0x68 #define READ 1 #define WRITE 0 void main() { i2c_init(); }

IC (Inter-Integrated Circuit) How to write Hi-tech C code for I2C module Example: Read multi-byte //Send Start condition i2c_start(); //Send Slave address + WRITE command i2c_write((SLAVE_ADD<<1)|WRITE)); // ((SLAVE_ADD<<1)| WRITE) = ((0x68<<1)|0) = 0xD0 //Send register address (register of Slave the first register need to read data) i2c_write(0x00); //ReStart condition i2c_stop(); i2c_start();

IC (Inter-Integrated Circuit) How to write Hi-tech C code for I2C module Example: Read multi-byte <cont.> //Send Slave address + READ command i2c_write((SLAVE_ADD<<1)|READ)); // ((SLAVE_ADD<<1)| READ) = ((0x68<<1)|1) = 0xD1 //read data //unsigned char i2c_read(unsigned char ack); data_array[0] = i2c_read(0); //1st byte and ACK data_array[1] = i2c_read(0); //2nd byte and ACK data_array[2] = i2c_read(1); //3rd byte and NACK

//Send Stop condition i2c_stop();

TC74: Serial Digital Thermal Sensor


Digital Temperature Sensing in SOT23-5 or TO-220 Packages Outputs Temperature as an 8-Bit Digital Word Simple SMBus/I2C Serial Port Interface Supply Voltage of 2.7V to 5.5V

TC74: Serial Digital Thermal Sensor

TC74: Serial Digital Thermal Sensor

You might also like