SPI 功能使用方法 Application Note

Similar documents
Chapter 7. Digital Arithmetic and Arithmetic Circuits. Signed/Unsigned Binary Numbers

PC Link Mode. Terminate PC Link? Esc. [GO]/[Esc] - - [GO]/[Esc] 轉接座未放滿. Make auto accord with socket mounted? [GO]/[Esc] Copy to SSD E0000

SSL VPN User Manual (SSL VPN 連線使用手冊 )

Chapter 7. Signed/Unsigned Binary Numbers. Digital Arithmetic and Arithmetic Circuits. Unsigned Binary Arithmetic. Basic Rules (Unsigned)

UAK1-C01 USB Interface Data Encryption Lock USB 資料加密鎖. Specifications for Approval

一般來說, 安裝 Ubuntu 到 USB 上, 不外乎兩種方式 : 1) 將電腦上的硬碟排線先予以排除, 將 USB 隨身碟插入主機, 以一般光碟安裝方式, 將 Ubuntu 安裝到 USB

BTC, EMPREX Wireless Keybaord +Mouse + USB dongle. 6309URF III Quick Installation Guide

InTANK ir2771-s3 ir2772-s3. User Manual

Frame Relay 訊框中繼 FRSW S0/0 S0/1

購票流程說明 How To purchase The Ticket?

港專單一登入系統 (SSO) 讓本校的同學, 全日制及兼職老師只要一個登入帳戶, 便可同時使用由本校提供的網上系統及服務, 包括 Blackboard 網上學習平台, 港專電郵服務, 圖書館電子資料庫及其他教學行政系統.

Oxford isolution. 下載及安裝指南 Download and Installation Guide

SM59R09A5 與 W77E58 應用差異說明一 適用產品 :SM59R09A5

2009 OB Workshop: Structural Equation Modeling. Changya Hu, Ph.D. NCCU 2009/07/ /07/03

Increase Productivity and Quality by New Layout Flow

RA8835. Dot Matrix LCD Controller Q&A. Preliminary Version 1.2. July 13, RAiO Technology Inc.

Oracle Database 11g Overview

Password Protection 此篇文章說明如何在程式中加入密碼保護的機制, 當程式開啟, 使用者必須先輸入使用者帳號及密碼, 若是合法使用者才能進入應用程式

Chapter 4 (Part IV) The Processor: Datapath and Control (Parallelism and ILP)

購票流程說明 How To purchase The Ticket?

桌上電腦及筆記本電腦安裝 Acrobat Reader 應用程式

Preamble Ethernet packet Data FCS

RENESAS BLE 實作課程 Jack Chen Victron Technology CO., LTD 2015 Renesas Electronics Corporation. All rights reserved.

Figure 1 Microsoft Visio

Multimedia Service Support and Session Management 鍾國麟

DVS-8504E-H 四路 H.264 數位影像編碼器

全面強化電路設計與模擬驗證. Addi Lin / Graser 2 / Sep / 2016

InTANK ir2622 User Manual

EZCast Docking Station

EZCast Wire User s Manual

InTANK ir2623-s3 User Manual

Twin API Guide. How to use Twin

EZCast Wire. User s Manual. Rev. 2.00

Quick Installation Guide for Connectivity Adapter Cable CA-42

JAVA Programming Language Homework V: Overall Review

CLAD 考前準備 與 LabVIEW 小技巧

Syntest Tool 使用說明. Speaker: Yu-Hsien Cheng Adviser: Kuen-Jong Lee. VLSI/CAD Training Course

DVS-8501E/DVS-8501E-H 單路 H.264 數位影像編碼器

GPIB 儀器控制之概念及軟硬體介紹 研華股份有限公司 工業自動化事業群

MH-3621-U3 Clone Dual SATA HDD Docking System

SOHOTANK PD3500+ User Manual

MP3 Codec Design 吳炳飛教授. Chaotic Systems & Signal Processing Lab, CSSP Lab. CSSP Lab:

English G H. Package Contents. Hardware Requirements. Technical Specifications. Device Overview. MSI DS502 GAMING HEADSET User Guide

Allegro SPB V16 Advance

The notice regarding Participation Ways of our global distributor video conference on Feb. 5.

49 <script type="text/javascript"> 50 var gcid=0,sex=false,birthday=kendo.tostring(new Date(),"yyyy/MM/dd"); 51 $(function(){ 52

Software Architecture Case Study: Applying Layer in SyncFree

外薦交換生線上申請系統操作說明 Instruction on Exchange Student Online Application System. [ 中文版 ] [English Version]

Chapter 7 Pointers ( 指標 )

Multilingual Version. English. 中文 Français. Español 日本語. Deutsch. Italiano

場次 : C3. 公司名稱 : Radware. 主題 : ADC & Security for SDDC. 主講人 : Sam Lin ( 職稱 ) 總經理

Dr. Whai-En Chen. Institute of Computer Science and Information Engineering National Ilan University TEL: #340

WIN Semiconductors. Wireless Information Networking 穩懋半導體 2014 年第四季法人說明會. p.0

步驟 1: 首頁以 facebook 或 google 帳號登入, 並點選節目 Step 1:Log in with your facebook/google account, then click the show banner.

Ubiquitous Computing Using SIP B 朱文藝 B 周俊男 B 王雋伯

Additional Information

SOHORAID ST8-TB3 User Manual

描述性資料採礦 Descriptive Data Mining

Use of SCTP for Handoff and Path Selection Strategy in Wireless Network

David M. Kroenke and David J. Auer Database Processing Fundamentals, Design, and Implementation

Citrix CloudGateway. aggregate control. all apps and data to any device, anywhere

微算機原理與實驗 Principle of Microcomputer(UEE 2301/1071 )

Operation Function Locations. Operations. Wireless Microphone Wireless Receiving Features. Wireless Transmission Audio Function Operations

ICP Enablon User Manual Factory ICP Enablon 用户手册 工厂 Version th Jul 2012 版本 年 7 月 16 日. Content 内容

微處理機系統 吳俊興高雄大學資訊工程學系. February 21, What are microprocessors (µp)? What are the topics of this course? Why to take this course?

MSI MS-3871 Wireless 11b/g/n + Bluetooth BT2.1 EDR Combo Slim Module. User sguide

Mid-term EXAM. 11/14/2009

RTL8710BN Build and Debug Environment Setup IAR

TC-7100 Microprocessor Turbidity/S.S. Transmitter

多元化資料中心 的保護策略 技術顧問 陳力維

Simulation of SDN/OpenFlow Operations. EstiNet Technologies, Inc.

VB 拼圖應用 圖形式按鈕屬性 資科系 林偉川

報告人 / 主持人 : 林寶樹 Colleges of Computer Science & ECE National Chiao Tung University

Lotusphere Comes to You 輕鬆打造 Web 2.0 入口網站 IBM Corporation

VZ-P18 和 VZ-P38 專業教材提示機 完美的展示效果

Chapter 1 Introduction to Computers, the Internet, and the Web

Operating manual. LawMate WN7911B-ZZ. WiFi Module V 01

4Affirma Analog Artist Design Flow

FCC Compliance Statement:

System-on-Chip (SOC) 晶 系統組

AVG Anti-Virus User Manual. Document revision ( )

Registering ( 註冊新帳號 )

Chinese (Traditional) Style Guide

User s Manual. Rev. 1.04

C B A B B C C C C A B B A B C D A D D A A B D C C D D A B D A D C D B D A C A B

Java 程式設計基礎班 (7) 劉根豪台大電機所網路資料庫研究室. Java I/O. Class 7 1. Class 7

NCCU 資訊碩專班 Advanced Programming Languages

C A R I T A S M E D I C A L C E N T R E 明愛醫院 Rev. (A) (B) (C) (D) D A T A A C C E S S R E Q U E S T ( D A R ) 查閱資料要求申請須知

User s Manual / 使用手冊 Model : TIP-M200ST-BK

Invitation to Computer Science 5 th Edition. Chapter 8 Information Security

Department of Computer Science and Engineering National Sun Yat-sen University Data Structures - Final Exam., Jan. 9, 2017

黃河凱. Kaiser Huang 巨匠電腦北區 / 新竹認證中心認證講師國立新竹教育大學數位學習科技研究所在職生微軟原廠認證講師 MCT

Digital imaging & free fall of immersed sphere with wall effects

研華公司 H 營運成果與財務報告

Gigabyte and Giga-byte are trademarks of Giga-byte Technology Co., Ltd. Microsoft and Windows XP are trademarks of Microsoft Corporation.

RP-300. Receipt Printer User s Manual. All specifications are subject to change without notice

What is a Better Program?

Command Dictionary CUSTOM

Protech RMA Request Form

Transcription:

1 適用產品 :SM59R16A2 / SM59R08A2 2 SPI 使用概述 : SPI 通信使用 4 個引腳, 分別為 SPI_: 當 master 時資料輸出 ; 當 slave 時資料輸入 SPI_: 當 master 時資料輸入 ; 當 slave 時資料輸出 SPI_SCK: SPI 的時脈信號由 master 主控產生 ; 資料 ( 輸出及輸入 ) 和時脈同步 SPI_SS: 此引腳功能唯有當作 slave mode 時可使用 (master mode 此引腳則當做 GPIO 使用 ) = 0: master 致能 slave = 1: master 禁能 slave Master CLK Slave 1 CLK Slave 2 CLK IO IO SS SS Fig. 15-1: SPI signals between master and slave devices 3 以下說明與 SPI 相關的特殊控制暫存器及特殊狀態暫存器 Special Function Register (SFR) SPI Description Direct Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 RESET SPI function SPIC1 SPI control register 1 F1h SPIEN SPIMSS SPISSP SPICKP SPICKE SPIBR[2:0] 08h SPIC2 SPI control register 2 F2h SPIFD TBC[2:0] - RBC[2:0] 00h SPIS SPI status register F5h - SPIMLS SPIOV SPITXIF SPITDR SPIRXIF SPIRDR SPIRS 40h SPITXD SPI transmit data buffer F3h SPITXD[7:0] 00h SPIRXD SPI receive data buffer F4h SPIRXD[7:0] 00h IRFWX-A079 1 Ver A 2008/05

Mnemonic: SPIC1 Address: F1h SPIEN SPIMSS SPISSP SPICKP SPICKE SPIBR[2:0] 08h SPIEN: SPI 模主致能旗標 : 1 致能 0 禁能 SPIMSS: 主從模式選擇旗標 (Master or Slave mode Select) 1 MCU 做為 Master mode. 0 MCU 做為 Slave mode. SPISSP: (SS) 引腳致能狀態旗標 ; 當 MCU 為 slave 時, 可由旗標設定 Slave Select (SS) 引腳致能狀態 (slave mode used only) 1 高準位致能 high active. 0 低準位致能 low active. SPICKP: 時脈閒置準位旗標 (master mode used only) 1 時脈閒置時為高準位 (SCK high during idle), Ex : 0 時脈閒置時為低準位 (SCK high during idle), Ex : SPICKE: 時脈取樣旗標 Clock sample edge select. 1 正緣取樣 data latch in rising edge 0 負緣取樣 data latch in falling edge. * 為確保資料取樣的正確性, 無論使用正緣或負緣取樣, 時脈及資料同步時皆需有足夠的準備時間 (set-up time) 及保持時間 (hold time),sm59r16a2/sm59r08a2 時序產生如下圖 : sufficient set-up time sufficient hold time SPIBR[2:0]: SPI 鮑率選擇 (master mode used only), Fosc 為晶振頻率 : SPIBR[2:0] Baud rate 0:0:0 Fosc/4 0:0:1 Fosc/8 0:1:0 Fosc/16 0:1:1 Fosc/32 1:0:0 Fosc/64 1:0:1 Fosc/128 1:1:0 Fosc/256 1:1:1 Fosc/512 IRFWX-A079 2 Ver A 2008/05

Mnemonic: SPIC2 Address: F2h SPIFD TBC[2:0] - RBC[2:0] 00h SPIFD: 全雙工模式旗標 (Full-duplex mode enable) 1 : 全雙工模式致能 0 : 全雙工模式禁能當全雙工模式旗標 SPIFD 致能時,TBC[2:0] 和 RBC[2:0] 會被清除並保持為零, 即 SPI 全雙工模式僅允許 8 位元通訊. Input Shift register SPIRXD Output Shift register SPITXD Output Shift register SPITXD Input Shift register SPIRXD Clock Generator SCK SCK SyncMOS Master SyncMOS Slave TBC[2:0]: SPI 傳送元位旗標 ( 全雙工模式僅允許 8 位元通訊 ) TBC[2:0] Bit counter 0:0:0 8 bits output 0:0:1 1 bit output 0:1:0 2 bits output 0:1:1 3 bits output 1:0:0 4 bits output 1:0:1 5 bits output 1:1:0 6 bits output 1:1:1 7 bits output RBC[2:0]: SPI 接收元位旗標 ( 全雙工模式僅允許 8 位元通訊 ) RBC[2:0] Bit counter 0:0:0 8 bits input 0:0:1 1 bit input 0:1:0 2 bits input 0:1:1 3 bits input 1:0:0 4 bits input 1:0:1 5 bits input 1:1:0 6 bits input 1:1:1 7 bits input IRFWX-A079 3 Ver A 2008/05

Mnemonic: SPIS Address: F5h - SPIMLS SPIOV SPITXIF SPITDR SPIRXIF SPIRDR SPIRS 40h SPIMLS: MSB or LSB output /input first 1 : 最高位元優先 (MSB output/input first) 0 : 最低位元優先 (LSB output/input first) SPIOV: 溢位旗標 (Overflow flag) 1 : 當 SPIRDR 已設定 (SPIRXD 原有資料未被讀取 ) 且下一筆資料正寫入 SPIRXD 時,SPIOV 將被設定為 1, 告知 SPIRXD 資料以有損毀. 0 : 當 SPIRDR 清為零時,SPIOV 則由硬體清除. SPITXIF: Transmit Interrupt Flag. 1 : 當 SPITXD 的資料已載入移位暫存器 0 : 傳送資料完成後必須由軟體清除 SPITDR: Transmit Data Ready. 1 : 當程序為傳送模式時, 資料儲存至 SPITXD 後, 由軟體設定此旗標為 1 告知 SPI module 可傳出資料 0 : 當 SPI module 由 SPITXD 完成傳送時或 SPITXD 被載至移位暫存器時, 此旗標則由硬體自動清除 SPIRXIF: Receive Interrupt Flag. 1 : 當 SPIRXD 被載入新一筆資料後 0 : 接收資料完成後必須由軟體清除 SPIRDR: Receive Data Ready. 1 : SPI module 接收資料時,SPIRDR 由硬體自動設定為 1, 以告知 MCU 完成接收並儲存至 SPIRXD; 當新的一筆資料寫入 SPIRXD, 而 SPIRDR 未清除時,SPIRXD 原有的資料將被覆寫, 產生 overflow 0 : 由 SPIRXD 讀取資料後, 必須由軟體清除此旗標 SPIRS: Receive Start. 1 : 告知 SPI 模組可由 SPIRXD 接收資料 Mnemonic: SPITXD Address: F3h SPITXD[7:0] 00h SPITXD[7:0]: 傳送資料緩衝器. Mnemonic: SPIRXD Address: F4h SPIRXD[7:0] 00h SPIRXD[7:0]: 接收資料緩衝器 IRFWX-A079 4 Ver A 2008/05

4 以下為 SPI 相對應的中斷向量表, 和中斷有關的致能旗標 Table 11-1: Interrupt vectors Interrupt Request Flags Interrupt Vector Interrupt Number Address *(use Keil C Tool) IE0 External interrupt 0 0003h 0 TF0 Timer 0 interrupt 000Bh 1 IE1 External interrupt 1 0013h 2 TF1 Timer 1 interrupt 001Bh 3 RI0/TI0 Serial channel 0 interrupt 0023h 4 TF2/EXF2 Timer 2 interrupt 002Bh 5 SPIIF SPI interrupt 004Bh 9 ADCIF A/D converter interrupt 0053h 10 EEIIF Expanded External Interrupt 005Bh 11 IICIF IIC interrupt 006Bh 13 RI1/TI1 Serial channel 1 interrupt 0083h 16 *See Keil C about C51 User s Guide about Interrupt Function description Mnemonic Description Direct Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 RESET Interrupt IEN0 Interrupt Enable 0 register A8h EA - ET2 ES0 ET1 EX1 ET0 EX0 00h IEN1 Interrupt Enable 1 register B8h EXEN2 - IEIIC - IEEEI IEADC IESPI - 00h IEN2 Interrupt Enable 2 register 9Ah - - - - - - - ES1 00h IP0 Interrupt priority level 0 A9h - - IP0.5 IP0.4 IP0.3 IP0.2 IP0.1 IP0.0 00h IP1 Interrupt priority level 1 B9h - - IP1.5 IP1.4 IP1.3 IP1.2 IP1.1 IP1.0 00h * 如果需要使用中斷程序, 可參考以下設置 : (1) SPI 中斷致能設罝 : IEN0 = 0x80; //Enable interrupt All IEN1 = 0x02; //Enable interrupt SPI (2) SPI 中斷程序表示 : void SPI_interrupt(void) interrupt 13 using 1 IRCON_SPIIF = 0; //Clear interrupt flag IRFWX-A079 5 Ver A 2008/05

5 以下為兩顆 MCU 分別當做 SPI master 及 slave 通訊的流程圖 IRFWX-A079 6 Ver A 2008/05

6 SPI master 及 slave 通訊的範例程式說明 : 6.1 Master 將以資料 (0xFF~0x00) 傳至 Slave 6.2 Slave 接受後, 以相同的資料回傳給 Master 6.3 Master 接受 Slave 回傳的資料後, 將該資料與原傳出資料比較, 相同則表示通訊正確, 不相同則反之 Description Master: Main program //==================================================================== // // S Y N C M O S T E C H N O L O G Y // //==================================================================== #include "..\h\sm59r16a2.h" #include "..\h\sm59r16a2_extradef.h" #include "..\LCD\LCD16x2.h" #include "..\MISC\delay.h" #define Control_Byte 0xA0 #define SPI_SS P1_0 #define SPITDR=1 SPIS = 0x08 /* void SPI_interrupt(void) interrupt 13 using 1 IRCON_SPIIF = 0; //Clear interrupt flag */ void SPI_Init(void) SPIC1 = 0xD8; //SPI Enable/ master/ NC/ idle hi/ rising latch //SPIC1 = 7; //BR=(Fosc/512) SPIC2 = 0x00; //SPI full-duplex disable /8-bit communicate SPIS = 0x40; //MSB send first void SPI_TX( unsigned char DATA) SPITXD = DATA; //Load to Buffer SPIS = 0x08; //SPITDR while(!(spis&spi_txif) ); //TX completed SPIS &= (~SPI_TXIF); //Clear TXIF bit unsigned char SPI_RX(void) unsigned char Temp; SPIS = 0x01; //Receive Start while(!(spis&spi_rxif) ); //RX completed Temp = SPIRXD; //Load from Buffer SPIS = 0x02; //Receive Data Ready SPIS &= (~SPI_RXIF); //Clear RXIF bit return Temp; IRFWX-A079 7 Ver A 2008/05

Description Main program Master: void main() unsigned long Err =0, counter =1; unsigned char TxData, RxData,j; LCD_Init(); Delay10mSec(1); //must wait for LCD stable SPI_Init(); while(1) for(txdata=0xff; TxData>0; TxData--) PrintLcdStrLX( 1, 0, "M_TX: "); PrintLcdStrLX( 2, 0, "M_RX: "); SPI_SS = 0; SPI_TX( TxData ); //for(j=0; j<0; j++); RxData = SPI_RX(); SPI_SS = 1; //CS //TX //Dealy time //RX //CS SetCursorAddr(1, 6); PrintLcdHex( TxData ); SetCursorAddr(2, 6); PrintLcdHex( RxData ); counter++; SetCursorAddr(1, 12); PrintLcdDec( counter ); if(txdata!=rxdata) Err++; SetCursorAddr(2, 12); PrintLcdDec( Err ); P2=TxData; //result Description Slave: Main program //==================================================================== // // S Y N C M O S T E C H N O L O G Y // //==================================================================== #include "..\h\sm59r16a2.h" #include "..\h\sm59r16a2_extradef.h" #include "..\LCD\LCD16x2.h" #include "..\MISC\delay.h" void SPI_Init(void) SPIC1 =0x98; //SPI Enable/ slave/ Low active / NC / rising latch/ NC NC NC SPIC2 =0x00; //SPI full-duplex disable /8-bit communicate SPIS =0x40; //MSB send first IRFWX-A079 8 Ver A 2008/05

Description Main program Slave: void SPI_TX( unsigned char DATA) SPITXD = DATA; //Load to Buffer SPIS = 0x08; //SPITDR while(!(spis&spi_txif) ); //TX completed SPIS &= (~SPI_TXIF); //Clear TXIF bit unsigned char SPI_RX(void) unsigned char Temp; SPIS = 0x01; //Receive Start while(!(spis&spi_rxif) ); //RX completed Temp = SPIRXD; //Load from Buffer SPIS = 0x02; //SPIRDR SPIS &= (~SPI_RXIF); //Clear RXIF bit return Temp; void main() unsigned long Err =0, counter =1; unsigned char TxData=0, RxData=0,j; LCD_Init(); Delay10mSec(1); //must wait for LCD stable SPI_Init(); while(1) RxData = SPI_RX(); //RX SPI_TX( RxData ); //TX P2 = RxData; //result IRFWX-A079 9 Ver A 2008/05