esd-ch5_p3

12
3/3/2013 1 ĐẠI HC QUC GIA TP.HCHÍ MINH TRƯỜNG ĐẠI HC BÁCH KHOA KHOA ĐIN-ĐIN TBMÔN KTHUT ĐIN TEmbedded System Design Chapter 5: C Peripheral Interfaces (Part 3) BMôn KThut ĐinT- ĐHBK 1 (Part 3) References Martin Bates, “Programming 8bit PIC Microcontrollers in C”, Newnes, 2008 Bmôn KThut ĐinT- ĐHBK PIC 16F877A datasheet PIC C Help 2

Upload: ngoc-minh

Post on 22-Jun-2015

5 views

Category:

Documents


1 download

DESCRIPTION

communications SPI,UART, I2C

TRANSCRIPT

Page 1: ESD-Ch5_p3

3/3/2013

1

ĐẠI HỌC QUỐC GIA TP.HỒ CHÍ MINHTRƯỜ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

Chapter 5: C Peripheral Interfaces

(Part 3)

Bộ Môn Kỹ Thuật Điện Tử - ĐHBK 11

(Part 3)

References

• Martin Bates, “Programming 8‐bit PIC Microcontrollers in C”, Newnes, 2008 

Bộ môn Kỹ Thuật Điện Tử - ĐHBK

• PIC 16F877A datasheet

• PIC C Help

2

Page 2: ESD-Ch5_p3

3/3/2013

2

Outline

1.PIC16 UART Serial Link

2.PIC16 SPI Serial Bus

3.I2C Serial Bus

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 3

Outline

1.PIC16 UART Serial Link

2.PIC16 SPI Serial Bus

3.I2C Serial Bus

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 4

Page 3: ESD-Ch5_p3

3/3/2013

3

USART

• The universal synchronous/asynchronous receive transmit (USART) device is typically used in asynchronous mode to implement off‐board, one‐to‐one connections. 

• The term asynchronous  means no separate clock signal is needed to time the data reception, so only a data send, data receive, and ground wires are needed. 

• It is quick and simple to implement if a limited data bandwidth is acceptable. 

USART Operation

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 5

USART RS232 Signal

• Any pair of pins can be used for this interface, as data rate is quite low, allowing the signals to be generated in software.

• However, a dedicated hardware port is provided, which must be used if an interrupt is needed

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 6

Page 4: ESD-Ch5_p3

3/3/2013

4

CCS RS232 Serial Port Functions

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 7

RS232 Periperal Simulation

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 8

Page 5: ESD-Ch5_p3

3/3/2013

5

The program

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 9

Outline

1.PIC16 UART Serial Link

2.PIC16 SPI Serial Bus

3.I2C Serial Bus

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 10

Win 8 64Bit VS7
Note
cho den khi co ki tu duoc nhap
Page 6: ESD-Ch5_p3

3/3/2013

6

SPI Bus• The serial peripheral interface (SPI) bus provides high‐speed 

synchronous data exchange over relatively short distances (typically within a set of connected boards), using a master/slave system with hardware slave selectionsystem with hardware slave selection

• One processor must act as a master, generating the clock. Others act as slaves, using the master clock for timing the data send and receive. 

• The slaves can be other microcontrollers or peripherals with an SPI interface.

Bộ môn Kỹ Thuật Điện Tử - ĐHBK

• The SPI signals are: – Serial Clock (SCK)

– Serial Data In (SDI)

– Serial Data Out (SDO)

– Slave Select (!SS)

11

SPI Connection

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 12

SPI Signals

Page 7: ESD-Ch5_p3

3/3/2013

7

SPI Operation

• To transfer data, the master selects a slave device to talk to, by taking its SS line low. 

• Eight data bits are then clocked in or out of the slave SPI shift register to or from the master. No start and stop bits are necessary, and it is much faster than RS232. 

• The clock signal runs at the same speed as the master i t ti l k th t i 5MH h th hi i

Bộ môn Kỹ Thuật Điện Tử - ĐHBK

instruction clock, that is, 5MHz when the chip is running at the maximum 20MHz (16 series MCUs).

13

SPI Driver Functions

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 14

Page 8: ESD-Ch5_p3

3/3/2013

8

• SPI Test System Schematic

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 15

Master and slaves source code

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 16

Page 9: ESD-Ch5_p3

3/3/2013

9

Outline

1.PIC16 UART Serial Link

2.PIC16 SPI Serial Bus

3.I2C Serial Bus

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 17

I2C Bus

• The interintegrated circuit (I2C) bus is designed for short‐range communication between chips in the same system using a software addressing systemsystem using a software addressing system. 

• It requires only two signal wires and operates like a simplified local area network.

I2C connection

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 18

I2C signals

Page 10: ESD-Ch5_p3

3/3/2013

10

I2C Bus

• The I2C slave chips are attached to a two‐wire bus, which is pulled up to logic 1 when idle. Passive slave devices have their register or location addresses determined by a combination of external input address code pins and fixed internal decoding.

• As for SPI the clock is derived from the

Bộ môn Kỹ Thuật Điện Tử - ĐHBK

• As for SPI, the clock is derived from the instruction clock, up to 5MHz at the maximum clock rate of 20MHz.

19

I2C Bus

• To send a data byte, the master first sends a control code to set up the transfer, then the 8‐bit or 10‐bit address code, and finally the data. Each byte has a start and acknowledge bit, and each y g ,byte must be acknowledged before the next is sent, to improve reliability.

• The sequence to read a single byte requires a total of 5 bytes to complete the process, 3 to set the address, and 2 to return the data

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 20

Page 11: ESD-Ch5_p3

3/3/2013

11

I2C Functions

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 21

I2C Test System

RA0/AN02

OSC1/CLKIN13

OSC2/CLKOUT14

RB437

RB3/PGM36

RB235

RB134

RB0/INT33

MCLR/Vpp/THV1

+5VOFFON12345

9

DSW1

RA0/AN0RA1/AN1

3

RA2/AN2/VREF-4

RA4/T0CKI6

RA5/AN4/SS7

RE0/AN5/RD8

RE1/AN6/WR9

RE2/AN7/CS10

RC1/T1OSI/CCP216

RC2/CCP117

RC3/SCK/SCL18

19

RB7/PGD40

RB6/PGC39

RB538

RB4

RC7/RX/DT26

RC6/TX/CK25

RC5/SDO24

RC4/SDI/SDA23

RA3/AN3/VREF+5

RC0/T1OSO/T1CKI15

R14k7

R24k7

SCK6

SDA5

WP7

A01

A12

A23

U2

24FC256

678

DIPSWC_8

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 22

RD0/PSP019

RD1/PSP120

RD7/PSP730

RD6/PSP629

RD5/PSP528

RD4/PSP427

RD3/PSP322

RD2/PSP221

U1PIC16F877A

I2CSDA

SCL

TRIG

Page 12: ESD-Ch5_p3

3/3/2013

12

Bộ môn Kỹ Thuật Điện Tử - ĐHBK 23