Two Wire Interface Another popular serial peripheral interface bus -More flexible than SPI -Master and slave modes supported -7-bit slave address -400khz.

Slides:



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

Computer Architecture
INPUT-OUTPUT ORGANIZATION
Dr. Rabie A. Ramadan Al-Azhar University Lecture 3
8086.  The 8086 is Intel’s first 16-bit microprocessor  The 8086 can run at different clock speeds  Standard 8086 – 5 MHz  –10 MHz 
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.
CS-334: Computer Architecture
Introduction of Holtek HT-46 series MCU
SPI on the ATmega SS’ line only used in Slave mode SPDR
Serial Communication Buses: I 2 C and SPI By Brody Dunn.
Serial Peripheral Interface (SPI)
Configuration. Mirjana Stojanovic Process of loading bitstream of a design into the configuration memory. Bitstream is the transmission.
I2CI2C CS-423 Dick Steflik. Inter-Integrated Circuit Developed and patented by Philips for connecting low speed peripherals to a motherboard, embedded.
Unit-5 CO-MPI autonomous
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.
Synchronous Serial IO Send a separate clock line with data
NS Training Hardware. System Controller Module.
INPUT-OUTPUT ORGANIZATION
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 10: Serial buses Oct 6, 2011.
Serial Peripheral Interface Module MTT M SERIAL PERIPHERAL INTERFACE (SPI)
Chapter 7 Input/Output Luisa Botero Santiago Del Portillo Ivan Vega.
Lecture 111 Lecture 11: Lab 3 Overview, the ADV7183B Video Decoder and the I 2 C Bus ECE 412: Microcomputer Laboratory.
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
Embedded Bus – i2c David E. Culler Lab 2 Feb 2, 2015
Chapter 10: Input / Output Devices Dr Mohamed Menacer Taibah University
7/23 Inter-chip Serial Communication: SPI and I 2 C Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee.
Khaled A. Al-Utaibi  Interrupt-Driven I/O  Hardware Interrupts  Responding to Hardware Interrupts  INTR and NMI  Computing the.
Lecture 9 I2C NCHUEE 720A Lab Prof. Jichiang Tsai.
DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK
Advanced Microprocessor1 I/O Interface Programmable Interval Timer: 8254 Three independent 16-bit programmable counters (timers). Each capable in counting.
I2C Master Core Simulation Environment. I2C Master Core Requirements Coverage (*) Requirement I2C IP RS-906: The I2C IP shall define the period of time,
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 based Design for Biomedical Applications MBE 3 – MDBA XI : Project Outlooks.
12/16/  List the elements of 8255A Programmable Peripheral Interface (PPI)  Explain its various operating modes  Develop a simple program to.
Refer to Chapter 15 in the reference book
©2008 R. Gupta, UCSD COSMOS Summer 2008 Peripheral Interfaces Rajesh K. Gupta Computer Science and Engineering University of California, San Diego.
PS/2 Mouse/Keyboard Port
OCRP RF Control WINLAB – Rutgers University Date : June Authors : Prasanthi Maddala, Khanh Le,
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.
Serial Peripheral Interface SPI I2C (i-squared cee)
Communicating. The ATmega16 communicates through one of the following ways: Serial Peripheral Interface (SPI) Universal Synchronous and Asynchronous serial.
Embedded Communication Protocols Don Heer 10/18/10 1.
BIRLA VISHVAKARMA MAHAVIDYALAY SUBJECT: SPI PROTOCOL & MAX7221 DISPLAY INTERFACING SUBMITTED BY: KISHAN AVASTHI( ) MANSI CHANDEGARA( )
میکرو کنترلرهای AVR Serial Interfaces, I2C and SPI
Lab 9 Multiprocessor, Buses, SPI, I2C. Multiprocessors Why multiprocessors? The structure of multiprocessors. Elements of multiprocessors: – Processing.
Outline Analog to digital conversion (ADC) of NuMaker TRIO
Serial Communication Buses: I2C and SPI
The I2C Bus.
Two Wire Interface Another popular serial peripheral interface bus
Inter-IC Bus (I C) 2.
Chapter 11: Inter-Integrated Circuit (I2C) Interface
(Inter-IC bus) By Tejaswini Gadicherla
Two Wire Interface (TWI)
EE 107 Fall 2017 Lecture 7 Serial Buses – I2C Direct Memory Access
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.
Computer Organization and Design
SPI Protocol and DAC Interfacing
I2C and RTC Chapter 18 Sepehr Naimi
I2C Protocol and RTC Interfacing
Another Physical Layer – I2C
Serial Communication 19th Han Seung Uk.
Presentation transcript:

Two Wire Interface Another popular serial peripheral interface bus -More flexible than SPI -Master and slave modes supported -7-bit slave address -400khz data xfer speed -Bidirectional, open-drain bus (device pulls down, resistors pull up) -Two wires, SCL (clock) and SDA (data) Typical TWI bus configuration

Two Wire Interface A TWI transmission consists of -A Start condition -An address packet consisting of -Read/Write indication and -Slave acknowledge, (SLA+RW) -One or more data packets -a Stop condition A Start condition initiates a transmission by a master. Between Start and Stop conditions, the bus is busy and no other masters should try to initiate a transfer. A Start condition is signaled by a falling edge of SDA while SCL is high.

Two Wire Interface Address packet -Address packet is 9 bits long -MSB first -Address “ ” is reserved for broadcast mode -7 address bits (driven by master) -1 read/write control bit (driven by master) -1 acknowledge bit (driven by addressed slave)

Two Wire Interface Data packet -All data packets are 9 bits long -MSB first -One data byte plus an acknowledge -During a transfer, Master generates SCL, Receiver acknowledges -Acknowledge (ACK): Slave pulls down SDA in the 9 th SCL cycle -Not Acknowledge (NACK): Slave does not pull down SDA in 9 th cycle NACK ACK

Two Wire Interface STOP condition -A Stop condition completes a transmission by a master. -A Stop condition is signaled by a rising edge of SDA while SCL is high. SDA SCL

Two Wire Interface Special cases -A Repeated Start occurs when the master initiates a new transfer without relinquishing control of the bus. Otherwise, this is just like another Start. SDA SCL -Clock stretching: If a Master is issuing a clock that is too fast, the Slave can extend the clock by extending the low period of SCL. -Multiple packets: Several data bytes may be sent between SLA+RW and Stop conditions.

Two Wire Interface TWI Registers -TWBR (bit rate register) -Controls the period of SCL when the TWI module is operating in Master mode -TWAR (address register) -Used when TWI module is receiving data to identify its address. -TWCR (control register) -Controls operation of the TWI unit -Used to generate START, STOP, ACK pulse -Also enables TWI operation including interrupt enables -TWSR (status register) -Reflects the status of the TWI logic bus via codes. -Holds the prescale value for the TWI SCL pulse generator -TWDR (data register) -In transmit mode, it holds the data to send -In receive mode, it holds the data received

Two Wire Interface TWI Interrupts -The TWINT flag in the control register must be cleared by SW -it is not cleared by the ISR like other interrupt sources -TWINT indicates that software needs to take care of something on the TWI bus. -One cycle after TWINT asserts, TWSR will hold a status code identifying the event that caused the interrupt. -While TWINT is set, SCL is stretched low and the TWI bus is stalled to allow software time to take care of business. -When TWINT is reset, the bus begins operations again. -When TWAR, TWSR or TWDR are changed, TWINT must be logic “1”.

Two Wire Interface TWI Interrupts (cont) -TWINT is set when the TWI unit: -finishes sending a Start/Repeated Start -finishes sending a SLA+RW -finishes sending an address byte -looses arbitration -has been addressed by its slave address or a general call -has received a data byte -receives a Stop or Repeated Start while being addressed as a slave -has a bus error do to illegal Start or Stop conditions -TWINT is not set after the TWI unit: -sends the STOP condition

Two Wire Interface while(!(TWCR & (1<<TWINT))) Using TWI (assuming its enabled) TWCR = (1<<TWINT) | (1<<TSWTA) if((TWSR & 0xF8) != START) error(); TWDR = SLA_W; TWCR = (1<<TWINT) while(!(TWCR & (1<<TWINT))) if((TWSR & 0xF8) != MT_SLA_ACK) error(); TWDR = data; TWCR = (1<<TWINT) while(!(TWCR & (1<<TWINT))) if((TWSR & 0xF8) != MT_DATA_ACK) error(); TWCR = (1<<TWINT) | (1<<TWSTO)

Two Wire Interface A typical TWI device: The pointer register is used to read or write the other registers. The device is address according to the manufacturers fixed address plus the address pin. Writing to the chip is sometimes a two step process. But, the LM73 pointer register remembers the last pointed to register.

Two Wire Interface LM73: one byte write -send device address -send pointer address -send data value to register 0x90 0x00 - temp 0x01 - config 0x04 - ctrl/stat data

LM73: two byte read with preset pointer Two Wire Interface 0x91 data NACK by master indicates end of reading.

Two Wire Interface Gotcha’s with the LM73: Don’t take a long time doing stuff while TWINT is asserted. You may need a short pause between stop an start conditions. When using 400khz clock, I didn’t. I did with slower clocks!

Two Wire Interface TWI coding Strongly suggest using twi.h: #include The #defines there will help make your code readable. //start condition transmitted #define TW START0x08 //repeated start condition transmitted #define TW_REP_START0x10 //SLA+W transmitted, ACK received #define TW_MT_SLA_ACK0x18 //SLW_W transmitted, NACK received #define TW_MT_SLA_NACK0x

Two Wire Interface TWI coding Strongly suggest using your own defines too: //LM73 Addresses on the I2C bus //Using LM73-0, address pin floating (datasheet pg. 9) #define LM73_ADDRESS 0x90 #define LM73_WRITE (LM73_ADDRESS | TW_WRITE) //LSB is a zero to write #define LM73_READ (LM73_ADDRESS | TW_READ) //LSB is a one to read //define the codes for actions to occur #define TWCR_START 0xA4 //send start condition #define TWCR_STOP 0x94 //send stop condition #define TWCR_RACK 0xC4 //receive byte and return ack to slave #define TWCR_RNACK 0x84 //receive byte and return nack to slave #define TWCR_SEND 0x84 //pokes the TWINT flag in TWCR and TWEN #define LM73_PTR_TEMP 0x00 //LM73 temperature address #define LM73_PTR_CONFIG 0x01 //LM73 configuration address #define LM73_PTR_CTRL_STATUS 0x04 //LM73 ctrl and stat register

Two Wire Interface TWI coding Strongly suggest well structured code with inline debug as needed: TWCR = TWCR_START; //send start condition while(!(TWCR & (1<<TWINT))){} //wait for start condition to transmit if(!(TW_STATUS == TW_START)){ string2lcd(error1); return(1);}//check start status TWDR = LM73_WRITE; //send device addr, write bit set TWCR = TWCR_SEND; //poke TWINT to send address while(!(TWCR & (1<<TWINT))){} //wait for LM73 address to go out if(TW_STATUS != TW_MT_SLA_ACK){ string2lcd(error2); return(1);}//check status reg for SLA+W ACK TWDR = LM73_PTR_TEMP; //send pointer address to LM73 TWCR = TWCR_SEND; //poke TWINT to send address while(!(TWCR & (1<<TWINT))){} //wait for LM73 data byte 1 to go out if(TW_STATUS != TW_MT_DATA_ACK){ string2lcd(error3); return(1);} //check ack status TWCR = TWCR_STOP; //finish transaction return(0); //return success value }

Two Wire Interface Reading the temperature is a bit funny... uint8_t rd_temp(){ TWCR = TWCR_START; //send start condition * TWDR = LM73_READ; //send device addr, read bit set * TWCR = TWCR_RACK; //receive data byte, return ACK while(!(TWCR & (1<<TWINT))){} //wait for data byte to come in if(TW_STATUS != TW_MR_DATA_ACK){return(1);} //byte 1 read failure lm73_temp_high = TWDR; //store temp high byte TWCR = TWCR_RNACK; //recv temp low byte, return NACK while(!(TWCR & (1<<TWINT))){} //wait for data byte to come in if(TW_STATUS != TW_MR_DATA_NACK){return(1);} //byte 2 read failure lm73_temp_low = TWDR; //store temp low byte TWCR = TWCR_STOP; //conclude transaction return(0); //return success value }