I2C and RTC Chapter 18 Sepehr Naimi www.NicerLand.com.

Slides:



Advertisements
Similar presentations
I2C bus Inter Integrated Circuits bus by Philips Semiconductors
Advertisements

Embedded Systems I2CI2C. Feature 3 wire GND SCL(clock) SDA(data) All devices share the same bus wire Using wire and, each device gain access to bus (become.
Serial Interfaces, Part Deux -I 2 C and SPI December 4, 2002 Presented by Eugene Ho.
Lecture 8: Serial Interfaces
SPI on the ATmega SS’ line only used in Slave mode SPDR
Serial Communication Buses: I 2 C and SPI By Brody Dunn.
I2CI2C CS-423 Dick Steflik. Inter-Integrated Circuit Developed and patented by Philips for connecting low speed peripherals to a motherboard, embedded.
Two Wire Interface Another popular serial peripheral interface bus -More flexible than SPI -Master and slave modes supported -7-bit slave address -400khz.
Lecture 27: LM3S9B96 Microcontroller – Inter- Integrated Circuit (I 2 C) Interface.
Haptic Belt team Informational Presentation.  I 2 C is a form of control bus (multi-master) which allows communication between multiple integrated circuits.
1 © Unitec New Zealand I2C Lecture 10 Date: - 2 Nov, 2011 Embedded Hardware ETEC 6416.
I2C UNIT 23 로봇 SW 교육원 조용수. 학습 목표 I2C I2C Protocol 구조 N051 I2C 동작 I2C Register 2.
Basic PIC-C I2C Communication
7/23 Inter-chip Serial Communication: SPI and I 2 C Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee.
DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK
1 Synchronous Serial IO Send a separate clock line with data –SPI (serial peripheral interface) protocol –I 2 C (or I2C) protocol Encode a clock with data.
Microprocessor. Interrupts The processor has 5 interrupts. CALL instruction (3 byte instruction). The processor calls the subroutine, address of which.
©2008 R. Gupta, UCSD COSMOS Summer 2008 Peripheral Interfaces Rajesh K. Gupta Computer Science and Engineering University of California, San Diego.
S4525A Peripherals & Enhanced FLASH 1 © 1999 Microchip Technology Incorporated. All Rights Reserved. S4525A Peripherals & Enhanced FLASH 1 Peripherals.
Essentials of Communication This simple model requires many guarantees. Sender Receiver Communication Link Data.
Communicating. The ATmega16 communicates through one of the following ways: Serial Peripheral Interface (SPI) Universal Synchronous and Asynchronous serial.
BIRLA VISHVAKARMA MAHAVIDYALAY SUBJECT: SPI PROTOCOL & MAX7221 DISPLAY INTERFACING SUBMITTED BY: KISHAN AVASTHI( ) MANSI CHANDEGARA( )
میکرو کنترلرهای AVR Serial Interfaces, I2C and SPI
As a part of ALA in the subject of MCI ( ) subject faculty:Hiren Patel Sir Presentation on rtc interfacing with atmega32 using ds1307 By:selva kumar.r.
Lab 9 Multiprocessor, Buses, SPI, I2C. Multiprocessors Why multiprocessors? The structure of multiprocessors. Elements of multiprocessors: – Processing.
 The LPC2xxx devices currently have two on- chip UARTS.  Except UART1 has additional modem support.
Computer Organization
UNIT 24 I2C Test 로봇 SW 교육원 조용수.
Serial Communication Originally created by Anurag Dwidedi and Rudra Pratap Suman.
Serial mode of data transfer
Outline Analog to digital conversion (ADC) of NuMaker TRIO
I2C Protocol and RTC Interfacing
Serial Communication Buses: I2C and SPI
The I2C Bus.
Two Wire Interface Another popular serial peripheral interface bus
MGITER,NAVSARI. AVR MICROCONTROLLER AND INTERFACING
Inter-IC Bus (I C) 2.
Chapter 11: Inter-Integrated Circuit (I2C) Interface
I/O Memory Interface Topics:
(Inter-IC bus) By Tejaswini Gadicherla
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Two Wire Interface (TWI)
EE 107 Fall 2017 Lecture 7 Serial Buses – I2C Direct Memory Access
Basic PIC-C I2C Communication
I2C Synchronous Serial Two wire communications (plus ground)
Dr. Michael Nasief Lecture 2
I2C Protocol and RTC Interfacing
I2C PROTOCOL SPECIFICATION
Communication Lines Fundamentals.
8259 Chip The Intel 8259 is a family of Programmable Interrupt Controllers (PIC) designed and developed for use with the Intel 8085 and Intel 8086 microprocessors.
An Introduction to Microprocessor Architecture using intel 8085 as a classic processor
BJ Furman ME 106 Fundamentals of Mechatronics 15NOV2012
EEPROM Comparison – Parallel or Serial
Computer Organization and Design
NetSilicon & Digi Confidential
Instruction cycle Instruction: A command given to the microprocessor to perform an operation Program : A set of instructions given in a sequential.
Serial Communication Interface: Using 8251
Serial EEPROM (Atmel 24C-512)
Interrupts Interrupt is a process where an external device can get the attention of the microprocessor. The process starts from the I/O device The process.
SPI Protocol and DAC Interfacing
UART Protocol Chapter 11 Sepehr Naimi
I2C Protocol and RTC Interfacing
Преглед Начин функционисања Имплементације
SPI Protocol Sepehr Naimi
8259 Programmable Interrupt Controller
Principles of Computers 20th Lecture
UNIT 24 I2C Test 로봇 SW 교육원 조용수.
I2C Protocol and RTC Interfacing
Another Physical Layer – I2C
Serial Communication 19th Han Seung Uk.
Presentation transcript:

I2C and RTC Chapter 18 Sepehr Naimi www.NicerLand.com

I2C History IIC: Inter-Integrated Circuit Philips 1982 Aim: connecting many devices (around 128 devices) to the PC using two wires

Connecting devices using I2C SDA: Serial Data SCL: Serial Clock Open-collector devices (Wire AND)

Sending bits of data The SDA values changes when SCL is low. The receiver reads SDA on the falling edge of SCL.

Start and Stop conditions

Packet Format Each packet is 9 bits long. First 8 bits are put on SDA by the transmitter The 9th bit is an acknowledge by the receiver NACK (leave high) or ACK (pull down)

Master vs. Slave Master Slave Begins the communication Chooses the slave Makes clock Sends or receives data Slave Responds to the master Each slave has a unique 7-bit address

Master vs. Slave (Cont.) There might be more than 1 master on an I2C bus Each device can be both Master and Slave

Steps of a communication Start Address Send or Receive (Write or read) Acknowledge Send/receive a byte of data Stop

Sending a byte Sending 19 to device 25.

Receiving a byte from Device 9

Repeated start A new Start condition before the Stop condition

I2C (TWI) Unit in AVR Bus Interface Unit detects and generates START, REPEATED START and STOP conditions. detects arbitration controls sending or receiving ACK transfers packets of data or address. Bit Rate Generation Unit controls the frequency of the system clock (SCL) when operating in a master mode Address Match Unit Compares the received address byte with the 7-bit address in TWI address register and informs the control unit upon an address match. Control Unit controls the TWI module and generates responses according to settings in the TWI control register sets the contents of the status register according to current state.

TWSR (TWI Status Register)

TWBR (TWI Bit Rate) Register TWSR:

TWCR TWINT: TWI Interrupt flag TWEA: TWI Enable Acknowledge bit 1:ACK, 0:NACK TWSTA: TWI Start condition bit TWSTO: TWI Stop condition bit TWWC: TWI Write Collision flag TWEN: TWI Enable bit TWIE: TWI Interrupt Enable TWCR:

TWI Control Register

TWAR (TWI Address Register) TWA6-0 (TWI slave Address) TWGCE (TWI General Call Recognition Enable bit) 1: Answer to general call TWAR:

TWDR (TWI Data Register)

TWI, Master Mode programming Initializing Set the TWI module clock frequency by setting the values of the TWBR register and the TWPS bits in the TWSR register. Set the TWEN bit in TWCR to one to enable the TWI module Transmit START condition Set TWEN, TWSTA, and TWINT bits of TWCR to one.

TWI, Master Mode programming Send Data Copy the data byte to the TWDR Set the TWEN and TWINT bits of the TWCR to one to start sending the byte. Poll TWINT flag in TWCR register to see whether the byte transmitted completely Receive Data Set TWEN and TWINT bits of TWCR to one to start receiving a byte. Poll TWINT flag in TWCR to see whether a byte has been received completely read the received byte from the TWDR

TWI, Master Mode programming Transmit STOP condition Set TWEN, TWSTO, and TWINT bits of TWCR to one Note: we cannot poll the TWINT flag after transmitting the STOP condition

Writing and reading a byte in master mode #include <avr/io.h> void i2c_write(unsigned char data) { TWDR = data ; TWCR = (1<< TWINT)|(1<<TWEN); while ((TWCR & (1 <<TWINT)) == 0); } //*************************************************** unsigned char i2c_read(unsigned char isLast) if (isLast == 0) //send ACK TWCR = (1<< TWINT)|(1<<TWEN)|(1<<TWEA); //send ACK else TWCR = (1<< TWINT)|(1<<TWEN); //send NACK return TWDR; void i2c_start(void) TWCR = (1 << TWINT) | (1 << TWSTA) | (1 << TWEN); while ((TWCR & (1 << TWINT)) == 0); void i2c_stop() TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO); void i2c_init(void) TWSR=0x00; //set prescaler bits to zero TWBR=152; //SCL frequency is 50K for XTAL = 16M TWCR=0x04; //enable the TWI module int main (void) i2c_init(); //writing a byte i2c_start(); //transmit START condition i2c_write(0b11010000); //transmit SLA + W(0) i2c_write(0b11110000); //transmit data i2c_stop(); //transmit STOP condition //reading a byte i2c_write(0b11010001); //transmit SLA + R(1) PORTD =i2c_read(1); //read one byte of data while(1); //stay here forever

TWI, Slave Mode programming Initializing Set the slave address by setting the values for the TWAR register. 7 bits for address 8th bit is TWGCE ( 1 = answer general calls) Set the TWEN bit in TWCR to one to enable the TWI module Set the TWEN, TWINT, and TWEA bits of TWCR to one to enable the TWI and acknowledge generation Listening poll the TWINT flag to see when the slave is addressed by a master device or use its interrupt

TWI, Slave Mode programming Send Data Copy the data byte to the TWDR Set the TWEN, TWEA, and TWINT bits of the TWCR register to one to start sending the byte. Poll TWINT flag in TWCR register to see whether the byte transmitted completely Receive Data Set TWEN and TWINT bits of TWCR to one to start receiving a byte. Poll TWINT flag in TWCR to see whether a byte has been received completely read the received byte from the TWDR

DS1307 RTC (Real-time clock) Keeps time and date

Connecting DS1307 to the AVR

DS1307 address map 64 bytes of RAM BCD format is used Bit7 of address location 0 (CH) should be zero to enable the oscillator Address location 07 is the control register

Register Pointer in DS1307 In DS1307 there is a register pointer that specifies the byte that will be accessed in the next read or write command. After each read or write operation, the content of the register pointer is automatically incremented. It is useful in multi-byte read or write. Register pointer:

Write to DS1307 Transmit START condition Transmit the address of DS1307 (1001101) followed by 0 to indicate a write operation Transmit the address of location you want to access (it set the value of Register Pointer) Transmit one or more bytes of date Transmit STOP condition

Read from DS1307 Transmit START condition Transmit the address of DS1307 (1001101) followed by 1 to indicate a read operation Receive one or more bytes of date Transmit STOP condition Note: the register pointer indicates which address will be read (you should set it using a write operation)

Set Time and Get Time void rtc_setTime(unsigned char h,unsigned char m,unsigned char s) { i2c_start(); //transmit START condition i2c_write(0xD0); //address DS1307 for write i2c_write(0); //set register pointer to 0 i2c_write(s); //set seconds i2c_write(m); //set minutes i2c_write(h); //set hour i2c_stop(); //transmit STOP condition } void rtc_getTime(unsigned char *h,unsigned char *m,unsigned char *s) i2c_write(0xD1); //address DS1307 for read *s = i2c_read(1); //read second, return ACK *m = i2c_read(1); //read minute, return ACK *h = i2c_read(0); //read hour, return NACK

DS3231 module Similar to DS1307

Connecting DS3231 to AVR