Serial Peripheral Interface (SPI)

Similar documents
17. Serial communication - I 2 C

OUTLINE. SPI Theory SPI Implementation STM32F0 SPI Resources System Overview Registers SPI Application Initialization Interface Examples

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

MEMS Differential pressure Sensor D6F-PH. User s Manual. MEMS Differential pressure Sensor A288-E1-01

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI. Laboratory Lesson 9: Serial Peripheral Interface (SPI)

spi 1 Fri Oct 13 13:04:

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

Raspberry Pi - I/O Interfaces

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

For reference only Refer to the latest documents for details

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

Module 3.C. Serial Peripheral Interface (SPI) Tim Rogers 2017

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

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

Introduction to I2C & SPI. Chapter 22

I2C ( EEPROM-AT24C02 )

Microcontrollers and Interfacing

General Purpose Input/Output (GPIO)

Serial Peripheral Interface (SPI)

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

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

Learn how to communicate

More on the 9S12 SPI Using the Dallas Semiconductor DS1302 Real Time Clock with the 9S12 SPI

Interfacing Techniques in Embedded Systems

Using the Z8051 MCU s USI Peripheral as an SPI Interface

SPI 3-Wire Master (VHDL)

EE 308 Spring Using the 9S12 SPI

Menu. What is SPI? EEL 3744 EEL 3744 SPI

LAB4. Program the on chip SPI module

The I2C BUS Interface

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

SPI( 2M-Flash-W25X16 )

Serial Peripheral Interface (SPI)

SPI Block User Guide V02.07

Lecture 25 March 23, 2012 Introduction to Serial Communications

EE 308: Microcontrollers

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

ice40 UltraPlus I 2 C and SPI Hardened IP Usage Guide Radiant Software

C8051F700 Serial Peripheral Interface (SPI) Overview

< W3150A+ / W5100 Application Note for SPI >

Serial Peripheral Interface (SPI) Host Controller Data Sheet

Serial Peripheral Interface (SPI) Last updated 8/7/18

Universität Dortmund. IO and Peripheral Interfaces

Lecture 14 Serial Peripheral Interface

Mbed Microcontroller SPI. Spring, 2018 Prof. Jungkeun Park

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

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

i_csn i_wr i_rd i_cpol i_cpha i_lsb_first i_data [15:0] o_data [15:0] o_tx_ready o_rx_ready o_rx_error o_tx_error o_tx_ack o_tx_no_ack

17. I 2 C communication channel

Understanding SPI with Precision Data Converters

SPI: Serial Peripheral Interface

Theory of Operation STOP CONDITION

Getting Started with ESPI Interface Using the Z8 Encore! XP F1680

USART. USART stands for Universal Synchronous Asynchronous Receiver Transmitter. Full-duplex NRZ asynchronous serial data transmission

Microcontrollers and Interfacing week 10 exercises

Temperature Sensor TMP2 PMOD Part 1

Real Time Embedded Systems. Lecture 1 January 17, 2012

Serial Communication. Spring, 2018 Prof. Jungkeun Park

Groking the Linux SPI Subsystem FOSDEM Matt Porter

LABORATORIO DI ARCHITETTURE E PROGRAMMAZIONE DEI SISTEMI ELETTRONICI INDUSTRIALI

or between microcontrollers)

FPGA Implementation Of SPI To I2C Bridge

1.3inch OLED User Manual

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

Design Development and Implementation of SPI

Real-Time Embedded Systems. CpE-450 Spring 06

ASNTu2s PCB with Tiger Board USB to 7-Channel 3-Wire Interface Bridge Application Notes

Serial Peripheral Interface Bus SPI

Using the MagAlpha Serial Interface Advanced Features. Application Note

BLE 1.4 SPI Driver Design Version 1.x (Draft)

STM8S005xx STM8S105xx Errata sheet

Serial communications with SPI

SPI (Serial & Peripheral Interface)

W7200 User s Guide. for STM32F10x Standard Library. - USART - GPIO - Timer. Version 1.0.0e

void GPIO_setup(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA RCC_APB2Periph_GPIOC RCC_APB2Periph_AFIO,ENABLE);

ADC to I 2 C. Data Sheet. 10 Channel Analog to Digital Converter. with output via I 2 C

Application Note, V1.0, Jul AP XC16x. Interfacing the XC16x Microcontroller to a Serial SPI EEPROM. Microcontrollers

ECE 471 Embedded Systems Lecture 20

a Serial Peripheral Interace (SPI). Embedded RISC Microcontroller Core Peripheral

SPI bus communication with LDE/LME pressure sensors

ECE 4510/5530 Microcontroller Applications Week 10

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

ArduCAM-M-2MP Camera Shield

Serial Buses in Industrial and Automotive Applications

PARALLEL COMMUNICATIONS

Design with Microprocessors

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING. EE Microcontroller Based System Design

PIC Serial Peripheral Interface (SPI) to Digital Pot

AT89S4D12. 8-Bit Microcontroller with 132K Bytes Flash Data Memory AT89S4D12. Features. Description. Pin Configurations

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

Block Diagram. mast_sel. mast_inst. mast_data. mast_val mast_rdy. clk. slv_sel. slv_inst. slv_data. slv_val slv_rdy. rfifo_depth_log2.

ECE 4510 Introduction to Microprocessors. Chapter 10

LB5900 Series Power Sensor SPI & I2C Interface Guide

Amarjeet Singh. January 30, 2012

ICS Humla CTF. Copyright 2017 Payatu 1

Section 5 SERCOM. Tasks SPI. In this section you will learn:

C-CODE EXAMPLE FOR SCP1000-D01 PRESSURE SENSOR

The Cubesat Internal bus: The I2C

By: Haron Abdel-Raziq

18-349: Introduction to Embedded Real-Time Systems

Transcription:

SPI and I 2 C 1

Serial Peripheral Interface (SPI) SPI allow half/full duplex, synchronous, serial communication with external devices The interface can be configured as master for MCU board Communication clock (SCLK) is also provided for synchronous communication 2

SPI features Full duplex synchronous transfer on 3 lines Simplex synchronous transfer on 2 lines Master or slave operation Multi-master mode support 3

SPI block diagram 4

Basic SPI configuration Usually, SPI is connected using 4 pins MISO (Master In/Slave Out): transmit data in slave mode, and received data in master mode MOSI (Master Out/Slave In): transmit data in master mode, and received data in slave mode SCLK: Clock NSS (slave select): to select a slave device 5

Single Master/Single Slave config 6

Configuring SPI in Master mode Select BR[2:0] to define baud rate Select CPOL and CPHA to define data transfer and serial clock relationship Set DFF bit to define 8 or 16 bit data transfer Configure LSBFirst bit in SPI_CR1 to define frame format Connect NSS if required MSTR and SPE must be set 7

Configuring SPI in Slave mode Select CPOL and CPHA to define data transfer and serial clock relationship Set DFF bit to define 8 or 16 bit data transfer LSBFirst bit in SPI_CR1 must be the same as Master Connect NSS if required Clear MSTR and set SPE bit 8

Timing diagram 9

Control register TXE bit is set on the transfer data from Tx buffer to the shift register RXNE bit is set on the data transfer from shift register to Rxbuffer 10

I2C Inter-Integrated bus (I2C) Interface between microcontroller and I2C bus Provide multi-master support 11

I2C feature Master master configuration I2C master feature Clock generation Start and Stop generation I2C slave feature programmable I2C address detection dual address capabilities Stop bit detection 2 interrupt vectors 12

I2C function There are 2 pins, data pin (SDA) and clock (SCL) It can be connected with standard speed (up to 100KHz) or fast mode (up to 400KHz) 13

I2C function description Mode selection: Slave transmit Slave receiver Master transmit Master receiver By default, it operates in Slave mode. It automatic switch once it receive a START condition from master to slave 14

Communication flow In master mode, I2C interface initiates the data transfer and the clock signal. A serial data transfer always begins with a start condition and ends with a stop condition In slave mode, the interface is capable of recognizing its own address (7-10 bits) Data are transmitted as 8 bit bytes, MSB first. A 9 th clock pulse, receiver must send an acknowledge 15

I2C data transfer 16

I2C block diagram 17

Mode selection By default, the device operates in slave mode. It will automatically switch from slave to master, after the device generate START condition from master to slave. 18

I2c master mode Program the peripheral input clock in I2C_CR2 register to generate correct timing Configure the clock control register Configure the rise time register Program I2C_CR1 register to enable the peripheral Set the start bit in I2C_CR1 to generate a Start condition 19

Transfer sequence 20

I2C reading data 1. Send start sequence 2. Send address of the device (with read bit) 3. Wait for response 4. Send address register of the device 5. Wait for response 6. Send start sequence again 7. Send address of the device (with read bit) 8. Wait for response 9. Wait for data (high byte first) 21 10.Wait for data (lower byte)

I2C writing data 1. Send start sequence 2. Send address of the device (with write bit) 3. Wait for response 4. Send address register of the device 5. Wait for response 6. Write high byte 7. Write lower byte 22

Example: reading data from compass 1. Send start sequence 2. Send address 3. Send start sequence again 4. Send address again 5. Read data 6. Send stop sequence 23

Example int main(){ } RCC_setup(); GPIO_setup(); I2C_setup(); while(1){ } if(i2c_lm75_status()==success){ } temp = LM75_readTemp(); void GPIO_setup(){ GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB RCC_APB2Periph_AFIO,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 GPIO_Pin_7; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOB, &GPIO_InitStructure); } 24

void I2C_setup(){ I2C_InitTypeDef I2C_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1,ENABLE); I2C_DeInit(I2C1); I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2; I2C_InitStructure.I2C_OwnAddress1 = 0x00; I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgeAddress_7bit; I2C_InitStructure.I2C_ClockSpeed = 200000; I2C_Init(I2C1, &I2C_InitStructure); I2C_Cmd(I2C1, ENALBE); // enable I2C1 } 25

ErrorStatus I2C_LM75_Status(){ unsigned int I2C_TimeOut = 100000; I2C_ClearFlag(I2C1, I2C_FLAG_AF); I2C_AcknowledgeConfig(I2C1, ENABLE); I2C_GenrateSTART(I2C1, ENABLE); while(!i2c_checkevent(i2c1, I2C_EVENT_MASTER_MODE_SELECT); // wait for start I2C_Send7BitAddress(I2C1, LM75_ADDR, I2C_Direction_Transmitter); //send slave addr while(!i2c_checkevent(i2c1,i2c_event_master_transmitter_mode_selecte D)) && I2C_TimeOut){ // get status ready } } I2C_TimeOut--; if(i2c_getflagstatus(i2c1,i2c_flag_af!= 0x0){ return ERROR; }else return SUCCESS; unsigned int LM75_readTemp(){ unsigned int RegValue = 0; I2C_AcknowledgeConfig(I2C1, ENABLE); I2C_GenerateStart(I2C1, ENABLE); // wait for START to complete while(i2c_checkevent(i2c1, I2CEVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, LM75_ADDR, I2C_Direction_Transmitter); 26

// wait for data transfer complete while(i2c_checkevent(i2c1, I2CEVENT_MASTER_RECEIVER_MODE_SELECTED)); // send data pointer I2C_SendData(I2C1,LM75_TEMP_REG); // wait for data transfer complete while(i2c_checkevent(i2c1, I2CEVENT_MASTER_BYTE_TRANSMITTED)); I2C_GenerateStart(I2C1, ENABLE); // wait for START to complete while(i2c_checkevent(i2c1, I2CEVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2C1, LM75_ADDR, I2C_Direction_Receiver); while(i2c_checkevent(i2c1, I2CEVENT_MASTER_RECEIVER_MODE_SELECTED)); while(i2c_checkevent(i2c1, I2CEVENT_MASTER_BYTE_RECEIVED)); // store data RegValue = I2C_ReceiveData(I2c1) << 8; // disable acknowledgement I2CAcknowledgeConfig(I2C1, DISABLE); // send I2C1 stop condition I2c_GenerateStop(I2C1, ENABLE); // test on EV7 and clear while(i2c_checkevent(i2c1, I2CEVENT_MASTER_BYTE_RECEIVED)); Regvalue!= I2C_ReceiveData(I2C1); return RegValue >> 7; 27 }

Simulink SPI Master Setup 28

Configuration 29

SPI Read/Write 30

Configuration Data Read/Write = the number of port 31

Clock polarity and clock phase Clock polarity low and clock phase 1 st edge (CPOL_Low/CPHA_1Edge) 32

Clock polarity and clock phase Clock polarity low and clock phase 2nd edge (CPOL_Low/CPHA_2Edge) 33

Clock polarity and clock phase Clock polarity high and clock phase 1 st edge (CPOL_High/CPHA_1Edge) 34

Clock polarity and clock phase Clock polarity high and clock phase 2nd edge (CPOL_High/CPHA_2Edge) 35

SPI Example 36

SPI Example 37

SPI Subsystem 38

Hardware 39

Test with Matlab Host 40

Output 41

I2C 42

Configuration 43

I2C Read/Write 44

I2C Configuration 45

I2C Sensor L3G4200D 46

Hardware 47

Matlab Host 48

Output 49

Humidity and Temperature Sensor 50

Hardware 51

Output 52

Questions? 53