Introduction to I2C & SPI. Chapter 22

Similar documents
Serial Peripheral Interface. What is it? Basic SPI. Capabilities. Protocol. Pros and Cons. Uses

I2C a learn.sparkfun.com tutorial

Parallel Data Transfer. Suppose you need to transfer data from one HCS12 to another. How can you do this?

Introduction the Serial Communications Parallel Communications Parallel Communications with Handshaking Serial Communications

Lecture 25 March 23, 2012 Introduction to Serial Communications

McMaster University Embedded Systems. Computer Engineering 4DS4 Lecture 6 Serial Peripherals Amin Vali Feb. 2016

Raspberry Pi - I/O Interfaces

Microcontrollers and Interfacing

or between microcontrollers)

I2C a learn.sparkfun.com tutorial

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

PARALLEL COMMUNICATIONS

SPI Universal Serial Communication Interface SPI Mode

Preliminary Data MOS IC. Type Ordering Code Package SDA Q67100-H5096 P-DIP-8-1

Introduction the Serial Communications Huang Sections 9.2, 10.2 SCI Block User Guide SPI Block User Guide

Inter-Integrated Circuit Bus IIC I2C TWI

Part 1 Using Serial EEPROMs

CprE 488 Embedded Systems Design. Lecture 4 Interfacing Technologies

Preliminary Data MOS IC. Type Ordering Code Package SDA Q67100-H5092 P-DIP-8-1

Interfacing Techniques in Embedded Systems

17. I 2 C communication channel

Growing Together Globally Serial Communication Design In Embedded System

1.3inch OLED User Manual

Real-Time Embedded Systems. CpE-450 Spring 06

Universität Dortmund. IO and Peripheral Interfaces

Serial Communications

Hello, and welcome to this presentation of the STM32 I²C interface. It covers the main features of this communication interface, which is widely used

An SPI interface for the 65(C)02 family of microprocessors

EECS 373 Design of Microprocessor-Based Systems

IV B.Tech. I Sem (R13) ECE : Embedded Systems : UNIT -4 1 UNIT 4

Tutorial for I 2 C Serial Protocol

The I2C BUS Interface

MIKROPROCESORY PRO VÝKONOVÉ SYSTÉMY. Serial Data Transmission (Stručný přehled) České vysoké učení technické Fakulta elektrotechnická

Basics of UART Communication

EECS 373 Design of Microprocessor-Based Systems

Level Shifter. for. Hardware User s Manual.

Laboratory 5 Communication Interfaces

Embedded Systems and Software. Serial Interconnect Buses I 2 C (SMB) and SPI

Serial Communication. Spring, 2018 Prof. Jungkeun Park

RL78 Serial interfaces

EECS 373 Design of Microprocessor-Based Systems

Digital Storage Oscilloscope

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

Application Note: AZD025 IQ Switch - ProxSense TM Series I2C Example Code for the IQS222

EE 456 Fall, Table 1 SPI bus signals. Figure 1 SPI Bus exchange of information between a master and a slave.

ELE492 Embedded System Design

The 9S12 Serial Peripheral Inteface (SPI) Huang Section 10.2 through 10.6 SPI Block User Guide

SPI (Serial & Peripheral Interface)

LB5900 Series Power Sensor SPI & I2C Interface Guide

19.1. Unit 19. Serial Communications

Raspberry Pi. Hans-Petter Halvorsen, M.Sc.

The Cubesat Internal bus: The I2C

Development and research of different architectures of I 2 C bus controller. E. Vasiliev, MIET

FPGA Implementation Of SPI To I2C Bridge

AN-895 APPLICATION NOTE

Freescale Semiconductor, Inc.

SPI 3-Wire Master (VHDL)

Prototyping Module Datasheet

UNIT IV SERIAL COMMUNICATIONS

ICS Humla CTF. Copyright 2017 Payatu 1

UART TO SPI SPECIFICATION

EPT-200TMP-TS-U2 TMP102 Temperature Sensor Docking Board Data Sheet

DESIGNING OF INTER INTEGRATED CIRCUIT USING VERILOG

Nuvoton NCT5655Y/W. 16-bit I 2 C-bus and SMBus GPIO controller with interrupt. Revision: 1.0 Date: May, 2016 NCT5655Y/W

Interfacing to Digital Potentiometers

Emulating I2C Bus Master by using FlexIO

VORAGO VA108x0 I 2 C programming application note

Each I2C master has 8-deep transmit and receive FIFOs for efficient data handling. SPI to Dual I2C Masters. Registers

USB-to-I2C. Ultra Hardware User s Manual.

How to Implement I 2 C Serial Communication Using Intel MCS-51 Microcontrollers

Handson Technology. I2C Specification and Devices. 1

Communication. Chirag Sangani

< W3150A+ / W5100 Application Note for SPI >

App Note Application Note: Addressing Multiple FPAAs Using a SPI Interface

Exercise 2 I 2 C Management 1/7

Lecture 5: Computing Platforms. Asbjørn Djupdal ARM Norway, IDI NTNU 2013 TDT

SILICON MICROSTRUCTURES

Unit 19 - Serial Communications 19.1

Understanding SPI with Precision Data Converters

Serial Buses in Industrial and Automotive Applications

C8051F700 Serial Peripheral Interface (SPI) Overview

Codec. WM8731 Audio Codec

Lesson I2C. I²C (Inter-Integrated Circuit) Lab Assignment: I2C Slave Driver

Microcontroller basics

Electronics Single wire communication

PAT9125EL: Optical Tracking Miniature Chip

ArduCAM-M-2MP Camera Shield

I 2 C Communication. Embedded Systems Interfacing. 25 October 2011

AN2737 Application note Basic in-application programming example using the STM8 I 2 C and SPI peripherals Introduction

GT24C02. 2-Wire. 2Kb Serial EEPROM (Smart Card application)

Digital Circuits Part 2 - Communication

Serial Communication. Simplex Half-Duplex Duplex

18-349: Introduction to Embedded Real-Time Systems

CDP68HC68S1. Serial Multiplexed Bus Interface. Features. Description. Ordering Information. Pinouts. April 1994

An SPI Temperature Sensor Interface with the Z8 Encore! SPI Bus

Amarjeet Singh. January 30, 2012

Embedded Workshop 10/28/15 Rusty Cain

M68HC08 Microcontroller The MC68HC908GP32. General Description. MCU Block Diagram CPU08 1

Theory of Operation STOP CONDITION

USB-910H API DLL and Include File Reference Manual

Transcription:

Introduction to I2C & SPI Chapter 22

Issues with Asynch. Communication Protocols Asynchronous Communications Devices must agree ahead of time on a data rate The two devices must also have clocks that are close to the same rate Excessive differences between clock rates on either end will cause garbled data Asynchronous serial ports require hardware overhead The UART at either end is relatively complex and difficult to accurately implement in software if necessary Most UART devices only support a certain set of fixed baud rates, and the highest of these is usually around 230400 bits per second https://learn.sparkfun.com/tutorials/i2c?_ga=1.229206105.432923716.1447312656

Asynchronous Transmission Example of an A followed by a B Stops Start Stop Start Stop A =0x41 B = 0x45

Synchronous Transmission Example of an A followed by a B Clock Data A =0x41 B = 0x42

The Inter-integrated Circuit (I 2 C) The Inter-integrated Circuit (I 2 C) Protocol is a protocol intended to allow multiple slave (or secondary) digital integrated circuits ( chips ) to communicate with one or more master chips. Multi-master system, allowing more than one master (or primary) to communicate with all devices on the bus When multiple primary devices are used, the master devices can t talk to each other over the bus and must take turns using the bus lines. In I2C there are three additional modes specified: fast-mode plus, at 1MHz; high-speed mode, at 3.4MHz; and ultra-fast mode, at 5MHz. Master generates the clock signal Characteristics - Serial, byte-oriented - Multi-master, multi-slave - Two bidirectional open-drain lines, plus ground Serial Data Line (SDA) Serial Clock Line (SCL) SDA and SCL need to pull up with resistors

Timing Diagram Pay attention Pay attention A START condition is a high-to-low transition on SDA when SCL is high. A STOP condition is a low to high transition on SDA when SCL is high. The address and the data bytes are sent most significant bit first. Master generates the clock signal and sends it to the slave during data transfer 6

Inter-Integrated Circuit (I2C) Master generates the clock signal Serial data line Serial clock line SDA and SCL have to be open-drain Connected to positive if the output is 1 In high impedance state if the output is 0 Each Device has an unique address (7, 10 or 16 bits). Address 0 used for broadcast STM32 internal pull-up is too weak (internal 100KΩ) External pull-up (4.7 kw for low speed, 3 kw for standard mode, and 1 kw for fast mode). Fast mode refers to fast rise time! 7

Inter-Integrated Circuit (I2C) The I 2 C bus drivers are OPEN DRAIN meaning that they can pull the corresponding signal line low, but cannot drive it high There can be no bus contention where one device is trying to drive the line high while another tries to pull it low, eliminating the potential for damage to the drivers or excessive power dissipation in the system STM32 internal pull-up is too weak (internal 100KΩ) External pull-up (4.7 kw for low speed, 3 kw for standard mode, and 1 kw for fast mode fast rise time!) Wired-AND bus: A sender can pull the lines to low, even if other senders are trying to drive the lines to high

Multiple Masters Connected to positive if the output is 1 In high impedance state if the output is 0 In single master systems, arbitration is not needed. Arbitration for multiple masters: During data transfer, the master constantly checks whether the SDA voltage level matches what it has sent. When two masters generate a START setting concurrently, the first master which detects SDA low while it has actually intended to set SDA high will lose the arbitration and let the other master complete the data transfer. 9

Basic Protocol (7-bit Addressing) Setting the address Write the data value R/W- : 0 --> Primary sends data Primary Start+7-bit address + Write ACK (address is good) 8-bit data ACK (data is good) Secondary 1= Master requires data 0=Master sends data Stop (we are done START 7-bit Address STOP

Basic Protocol (10-bit Addressing) Setting the address Write the data value R/W- : 0 --> Primary sends data Start+7-bit address + Write ACK (address is good) 8-bit data ACK (data is good) Stop (we are done Code: 11110 xx Primary Secondary

Repeated Starts

Interfacing Serial Digital Thermal Sensor 13

Communicating with TC74 with an address of 0x4D

I2C Data 15

Sending Data to I2C Secondary Via Polling write

I2C Initialization void I2C_Initialization(void){ // Enable the clock of I2C RCC->APB1ENR = RCC_APB1ENR_I2C2EN; // I2C 2 clock enable // Reset the I2C (set and reset by software) RCC->APB1RSTR = RCC_APB1RSTR_I2C2RST; RCC->APB1RSTR &= ~RCC_APB1RSTR_I2C2RST; // I2C Control register. ACK is set and cleared by software, and cleared by hardware when PE=0. I2C2->CR1 = I2C_CR1_ACK; // Acknowledge after a byte is received I2C2->CR1 &= ~I2C_CR1_SMBUS; // SMBus Mode: 0 = I2C mode; 1 = SMBus mode I2C2->CR2 &= ~I2C_CR2_FREQ; // Clear Peripheral CLK frequency FREQ[5:0] I2C2->CR2 = I2C_CR2_FREQ_1; // Set Peripheral clock frequency as 2 MHz I2C2->CR2 = I2C_CR2_ITEVTEN; // Event Interrupt Enable I2C2->CR1 &= ~I2C_CR1_PE; // Disable I2C to configure TRISE I2C2->TRISE &= ~I2C_TRISE_TRISE; // Clear Maximum Rise Time I2C2->TRISE = 17; // Set Maximum Rise Time for standard mode // I2C own address registers // Before the STM32 sends its start sequence it sits listening to the I2C lines waiting for its address // This is helpful if STM32 is used as slave I2C2->OAR1 %= ~(0x01); I2C2->OAR1 = 0x00; I2C2->OAR2 = 0x00; // Set up the address byte to select the slave device // Set up the I2C own address2 } // I2C Clock control register I2C2->CCR &= ~I2C_CCR_FS; I2C2->CCR &= ~I2C_CCR_CCR; I2C2->CCR = 0x08; I2C2->CR1 = I2C_CR1_PE; // 0 = Standard Mode ((up to 100 khz)); // 1 = Fast Mode (up to 400 khz) // Enable I2C1 17

A Brief Introduction to SPI SPI: Serial Peripheral Interface

Serial Peripheral Interface (SPI) Synchronous full-duplex communication Can have multiple slave (secondary) devices No flow control or acknowledgment Slave (secondary) cannot communicate with slave directly. SCLK: serial clock SS: slave select (active low) MOSI: master out slave in MISO: master in slave out 19

Data Exchange Master has to provide clock to slave Synchronous exchange: for each clock pulse, a bit is shifted out and another bit is shifted in at the same time. This process stops when all bits are swapped. Only master can start the data transfer 20

Clock 21

Read and Write

Multiple Chip Selects