Microcontrollers and Interfacing

Similar documents
Microcontrollers and Interfacing week 10 exercises

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

Introduction to I2C & SPI. Chapter 22

< W3150A+ / W5100 Application Note for SPI >

Lecture 25 March 23, 2012 Introduction to Serial Communications

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

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

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

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

Growing Together Globally Serial Communication Design In Embedded System

Understanding SPI with Precision Data Converters

Interfacing Techniques in Embedded Systems

Serial Peripheral Interface (SPI)

Using the Z8051 MCU s USI Peripheral as an SPI Interface

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

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

Mbed Microcontroller SPI. Spring, 2018 Prof. Jungkeun Park

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

1.3inch OLED User Manual

Raspberry Pi - I/O Interfaces

COOKING WITH TEAM 279

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

or between microcontrollers)

Part 1 Using Serial EEPROMs

Real-Time Embedded Systems. CpE-450 Spring 06

MMA axis digital accelerometer module

The I2C BUS Interface

Copyright. Getting Started with Arduino Wiring for Windows 10 IoT Core Agus Kurniawan 1st Edition, Copyright 2016 Agus Kurniawan

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

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

Universität Dortmund. IO and Peripheral Interfaces

spi 1 Fri Oct 13 13:04:

UART TO SPI SPECIFICATION

ECE 471 Embedded Systems Lecture 20

SPI Universal Serial Communication Interface SPI Mode

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

CprE 488 Embedded Systems Design. Lecture 4 Interfacing Technologies

RS485 3 click. How does it work? PID: MIKROE-2821

PIC Serial Peripheral Interface (SPI) to Digital Pot

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

SPI 3-Wire Master (VHDL)

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

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

PIN ASSIGNMENT PIN DESCRIPTION

Serial Communication. Simplex Half-Duplex Duplex

Temperature Sensor TMP2 PMOD Part 1

Serial Buses in Industrial and Automotive Applications

Digital Storage Oscilloscope

Arduino Uno R3 INTRODUCTION

Freescale Semiconductor, Inc.

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

Level Shifter. for. Hardware User s Manual.

ArduCAM-M-5MP Camera Shield

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

Digital Storage Oscilloscope

AN510 Using SPI protocol with pressure sensor modules

Serial Communication. Spring, 2018 Prof. Jungkeun Park

1.6inch SPI Module user manual

FPGA Implementation Of SPI To I2C Bridge

Motherboard to MicroZed Interfaces

PARALLEL COMMUNICATIONS

DS1306. Serial Alarm Real Time Clock (RTC)

SPI (Serial & Peripheral Interface)

ArduCAM-M-2MP Camera Shield

MOS INTEGRATED CIRCUIT

EE 308 Spring Using the 9S12 SPI

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

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

ICS Humla CTF. Copyright 2017 Payatu 1

± 2g Tri-axis Accelerometer Specifications

ĐẠI HỌC QUỐC GIA TP.HỒ CHÍ MINH TRƯỜNG ĐẠI HỌC BÁCH KHOA KHOA ĐIỆN-ĐIỆN TỬ BỘ MÔN KỸ THUẬT ĐIỆN TỬ. Embedded System Design

17. I 2 C communication channel

Groking the Linux SPI Subsystem FOSDEM Matt Porter

Thermo 6 click PID: MIKROE-2769

Serial Communications

From Datasheets to Digital Logic. synthesizing an FPGA SPI slave from the gates

Interfacing Z8 Encore! XP MCUs with an I 2 C-Based Character LCD

LB5900 Series Power Sensor SPI & I2C Interface Guide

Pmod modules are powered by the host via the interface s power and ground pins.

Serial Peripheral Interface (SPI)

Design with Microprocessors

ECE471: Embedded Systems Homework 7 SPI, A/D and Temperature Probe. Due: Friday, 2 November 2018, 10:00am

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

Amarjeet Singh. January 30, 2012

Review for Exam 3. Write 0x05 to ATD0CTL4 to set at fastest conversion speed and 10-bit conversions

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

Laboratory 5 Communication Interfaces

Serial versus Parallel Data Transfers

C8051F700 Serial Peripheral Interface (SPI) Overview

LAB4. Program the on chip SPI module

BroadR-Reach click PID: MIKROE Weight: 26 g

Order Number: MC68HC55 Rev. 2 MC68HC55/D Technical Data Two-Channel CMOS ASIC Device Section 1. DSI/D (Distributed System Interface Digital) 1.1 Featu

Signal conditioning and filtering. Temperature Sensor. 1 SCK 3 MISO 4 MOSI 7 CSB Sensing element 2. Signal conditioning and filtering

Serial Peripheral Interface Bus SPI

3.2inch SPI Module MSP3218 User Manual

Communication. Chirag Sangani

SPI Protocol of the TLE941xy family

The Serial Peripheral Interface

SPI Xpress. Data sheet

SSD1309. Advance Information. 128 x 64 Dot Matrix OLED/PLED Segment/Common Driver with Controller

Transcription:

Microcontrollers and Interfacing Week 10 Serial communication with devices: Serial Peripheral Interconnect (SPI) and Inter-Integrated Circuit (I 2 C) protocols College of Information Science and Engineering Ritsumeikan University 1

2 this week history of board-level serial communications I 2 C: topology, messages SPI: topology, data exchange example device: MCP3204 quad 12-bit ADC with SPI timing circuit layout the SPI library

3 history 1982: Philips was putting digital integrated circuits (ICs) into TV sets TV control (channel buttons on the front, etc.) had to communicate with the ICs ICs had to communicate with each other mini serial network developed: Inter-Integrated Circuit (I 2 C) protocol very good for configuring devices with control registers 1985: Motorola released a microcontroller based on the 68000 architecture needed a way to communicate with diverse, fast peripherals simplicity and speed were very important point-to-point protocol developed: Serial Peripheral Interface (SPI) very good for streaming data to/from external devices

4 I 2 C topology two wires: data (SDA) and clock (SCL) bus-based: devices send messages to each other message begins with destination device address specifies whether the message is a read or write operation master controls clock master and slave can both transmit to exhange a byte followed by an acknowledgement bit

5 I 2 C messages 127 devices can be connected each device has an address messages are sent to a specific device messages are byte oriented, and either read or write (not both) the protocol is half-duplex SCL SDA (bus claim) seven-bit slave address R/W ack 1 slave address and direction byte eight data bits ack N data bytes SCL SDA (bus release)

6 SPI topology simple case: one master, one slave master controls slave select and clock two data lines: MOSI (master slave) and MISO (slave master) data clocked on both lines every clock cycle stream of bits (no byte orientation), and protocol is full-duplex master slave SCK MOSI MISO SS serial clock master out, slave in master in, slave out slave select (active low) SCK MOSI MISO SS

7 SPI with multiple slaves common case: one master, a few slaves MISO is high-impedance (disconnected) unless slave selected only one slave select can be active at any given time needs additional slave select wire for each additional slave (can be avoided with shift registers, binary decoders, etc.) master SCK serial clock MOSI master out, slave in MISO master in, slave out SS0 SS1 slave 0 slave 1 slave 2 slave 3 SS2 SCK SCK SCK SCK SS3 MOSI MOSI MOSI MOSI MISO MISO MISO MISO SS SS SS SS slave selects

8 SPI data exchange serial clock SCK slave select SS phase 0 = leading edge polarity 0 = idle low master out MOSI msb......... lsb master in MISO msb......... lsb SPI clock mode clock active (polarity, phase) idles edge 0 (0, 0) low leading (rising) 1 (0, 1) low trailing (falling) 2 (1, 0) high leading (falling) 3 (1, 1) high trailing (rising)

9 SPI example: MCP3204 4-channel, 12-bit A/D converter V DD 5 V power supply DGND 0 V digital ground AGND 0 V analogue ground CH0 CH1 CH2 CH3 NC NC DGND 1 2 3 4 5 6 7 MCP3204 14 13 12 11 10 9 8 V DD V REF AGND CLK D OUT D IN CS/SHDN V REF reference voltage, sets the upper limit of input voltage (corresponding to the maximum digital A/D output value) CH0 CH4 the four analogue input channels CLK SPI serial clock input D IN SPI serial data input (equivalent to MOSI) D OUT SPI serial data output (equivalent to MISO) CS SPI active-low chip select (equivalent to SS)

10 SPI example timing CS MCU latches data from A/D converter on rising edges of SCLK SCLK 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 D IN Data is clocked out of A/D converter on falling edges SGL/ Start D2 D1 DO DIFF Don t Care D OUT HI-Z NULL BIT B11 B10 B9 B8 B7 B6 B5 B4 B3 B2 B1 B0 MCU Transmitted Data (Aligned with falling edge of clock) MCU Received Data (Aligned with rising edge of clock) Start Bit 0 0 0 0 0 1 SGL/ D2 DIFF D1 DO X X X X X X X X X X X X X X??????????? 0 (Null) B11 B10 B9 B8 B7 B6 B5 B4 B3 B2 B1 B0 X = Don t Care Bits Data stored into MCU receive register after transmission of first 8 bits Data stored into MCU receive register after transmission of second 8 bits Data stored into MCU receive register after transmission of last 8 bits

11 SPI example circuit 5V SCK (13) serial clock V DD SCK V REF CH0 10k MISO (12) master in, slave out MISO CH1 MOSI (11) master out, slave in MOSI CH2 SS (10) Arduino GND slave select (active low) SS CH3 DGND AGND MCP3204

12 SPI example layout Pin 1

13 the SPI library Arduino has hardware support for SPI, and a library for access import the SPI library #include <SPI.h> configure the SPI library void setup() { SPI.begin(); SPI.setClockDivider(SPI_CLOCK_DIV4); // 4 MHz SPI.setDataMode(SPI_MODE0); // idle low, leading edge SPI.setBitOrder(MSBFIRST); } use the SPI library unsigned char misovalue = SPI.transfer(mosiValue); (performs full-duplex exchange of 8 bits)

14 bit banging when no hardware support for SPI (or any other protocol) we can assign General-Purpose I/O pins to the needed signals implement the protocol manually, by writing/reading the pins this is known (informally) as bit banging SPI signals #define SSN 10 // slave select pin #define MOSI 11 // master out pin #define MISO 12 // master in pin #define SCK 13 // serial clock pin SPI configuration void setup() { pinmode(ssn, OUTPUT); digitalwrite(ssn, HIGH); // slave inactive pinmode(sck, OUTPUT); digitalwrite(sck, LOW); // clock idle pinmode(mosi, OUTPUT); pinmode(miso, INPUT); }

15 bit banging write a single bit to SPI device void sendbit(unsigned char bit) { digitalwrite(mosi, bit & 1); digitalwrite(sck, HIGH); digitalwrite(sck, LOW); } // value to write // clock data into device // clock idle read a single bit from SPI device int recvbit(void) { digitalwrite(sck, HIGH); int bit = digitalread(miso); digitalwrite(sck, LOW); return bit; } // clock don t care bit into device // result bit from device // clock idle

bit banging example transaction: perform A/D conversion int readadc(int channel) { digitalwrite(ssn, LOW); sendbit(1); sendbit(1); sendbit(channel >> 2); sendbit(channel >> 1); sendbit(channel); sendbit(0); sendbit(0); // slave select active // start bit // single-ended mode // ms bit // ls bit // discard empty result bit // discard null result bit int advalue = 0; for (int i= 0; i < 12; ++i) advalue = (advalue << 1) + recvbit(); } digitalwrite(ssn, HIGH); return advalue; K // slave select inactive 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Data is clocked out of A/D converter on falling edges SGL/ Start D2 D1 DO DIFF Don t Care NULL BIT B11 B10 B9 B8 B7 B6 B5 B4 B3 B2 B1 B0 16

17 next week quick review of other devices displays sensors physical interfaces networking project suggestions some are complete projects some require connecting a few pieces together