2013年9月25日 星期三

2013年8月30日 星期五

SPI(Serial Peripheral Interface)

Overview

  • Serial interface
  • Synchronous
  • Master-Slave
  • Data Exchange

其中Synchronous protocol

  1. 資料沿著clock(SCK)來傳送
  2. 當data 需改變及被讀取時,對clock 控制
  3. 因為是同步(synchronous),所以化的clock rate是可變的,不像RS-232等的通訊

Master-Slave protocol

  • 只有一個master可以去控制SCK(clock)
  • 直到其clock signal 出現才可以傳送資料
  • all slave 都是由master clock來控制
  • slave device 可能不會去管clock

Data Exchange protocol

  • data is being clocked out,new data is clocked in
  • data is exchanged-no device is only transmitter or receive only
  • the master controls the exchange by the clock line

它在"transmits" data一筆後,必先去讀取進來的資料,若進來的資料不可讀時

這一筆的資料,就會loss並且其SPI module變成disable as result.

 

SS(CS) pin define: Slave Select/Chip Select. the master wisch to staart an SPI data exchange between that slave device and itself.

it often used to improve noise (to reset the SPI slave so that it is ready to receive the next byte)

 

Data(MOSI/MISO): data is only output during the rising or falling edge of SCK.

而data會在相對的負edge(+->-)來latche;並確認資料正確後讀取

image

pin descritor:

SS(chip Select or Slave Select):

when this signal go to low ,the slave will listend for SPI clock and data

SCK(serial clock):

to control when data in/out

SDO(serial data out):

this signal carries the data sent out of the device.

SDI(serial data input):

this signal carries the data sent into the device.

image

image

SSPSR (shift register) for SPI module. it shift data in and out of the device . the data travels in a loop to the next shift register

image

image

 

image

image

 

74HC595+ SPI =expander(output)

&4HC165+SPI=

自強基金協會-上課心得Stellaris EKS_LM3S3748

image

image

image

image

image

image

image

image

image

 

其中,特別的是為了可以在多個開發工具(不同cpu/compiler..)

將其環境,以bat file 來加以設定.而非固定

path=C:\Program Files\Putty;%path%

set MCU_ROOT=c:
path=%MCU_ROOT%\UnxUtils\winXpBin;%MCU_ROOT%\UnxUtils\bin;%MCU_ROOT%\UnxUtils\usr\local\wbin;%path%

path=C:\Program Files\CodeSourcery\Sourcery_CodeBench_Lite_for_ARM_EABI\bin;%path%

ARM的定址與組合語言

ARM的定址:

在ARM中運算方式是採用Load/Stor架構

(即其運算,需先放在暫存器中且結果也是)

image

image

  • 立即定址:
    • 即其運算元本身即為其資料。故取出指令也就取得運算元.
    • ADD R3,R3,#1 ;R3=R3+1
    • ADD R8,R7,#&ff ;R8=R7[7:0]
    • 是"#"為頭開.十六進位為在"#"後加0x or &
  • 暫存器定址:
    • 以暫存器中的內含值作為運算元。
    • ADD r1,r2,r3 ;r1=r2+r3
  • 暫存器間接定址:
    • 以暫存器中的數值作為運算元的位址,而真正的運算元放在"memory"
    • ADD r0,r1,[r2] ;r0=r1+[r2]
    • Ldr r0,[r1] ; r0=[r1]
    • 暫存器間接定址大多使用一個暫存器(基底暫存器)的數值作為記憶体的位址.
  • 基底定址:
    • 將暫存器(基底)的內容與指今中所給多的位址偏移量加以相加,並進而得到一個運算元的有效位址
    • LDR r0,[r1,#4] ; r0=[r1+4]
    • 用來處理基底附近的記憶体,基底加偏移量:前索引(pre-index)和後索引(基底+索引定址)
    • "暫存器間接定址[]"是移移量為0的氐加上偏移定址 ;"基底加偏移[,#]"定址中基底暫存器包含的並非是確定位址,基底需加(減)若干偏移量(max 4KB)來計算所要處理的位址。
    • 除了找到基底定址所指資料外,還可改為基底暫存器內容
    • LDR r0,[r1,#4]! ;r0=[r1+4],r1=r1+4,以"!"表示在完成資料傳送後,同時更新基底暫存器內容.
    • 前索引 [r1,#4] ;後索引[r1],#4。
    • 後索引:基底不包今偏移量來做傳送的位址,且再傳送後,自動加上索引
    • LDR r0,[r1],#4 ;r0=[r1],r1=r1+#4
    • image
  • 相對定址:
    • 以PC計數暫存器為基底,而指今中的位址作為偏移量來得到有效位址
    • BL Next
    • …
    • Next
    • …
    • mov pc,lr
  • 多暫存器定址:
    • 一個指今完成多個暫存器的傳送
    • LDMIA R0,{R1,R2,R3,R4}; R1=[R0];R2=[R0+4];R3=[R0+8];R4=[R0+12]
    • 最多可傳16個暫存器及其"IA"為表示在執行完LOAD/STOR後,r0以work增加長度。
  • 堆疊定址:
    • LIFO/FILO
    • 以一個堆疊指標器來指向一塊stack的頂端,並且可分為
      • 向上:向高位址生長,
      • 向下:向低位址
    • 可分為滿遞增(FA)、空遞增(EA)、滿遞減(FD)及空遞減(ED)
    • 要pop, push存取

組合組言:

<opcode>{<cond>}{S} <Rd>,<Rn>,<Shifter-operand>

ADD r0,r1,r2 ; r0=r1+r2 ,no update flage

ADDS r0,r1,r2 ; r0=r1+r2,update flage

ADDCSS r0,r1,r2 ;if C flage set then r0=r1+r2 and update flage

CMP r0,r1 ;update flage based on r0-r1

//---------------

c file

if(z==1) r1=r2+(r3*4) ;

a.ADDS r1,r2,r3,LSL #2 ; r1=r2+r3*4 and update flage

b.EQADDS …; if zero flage is 1

其符號<>: 必存在; {}選擇項

//-----------------

ARM的指令集分為

  • 跳躍指今
  • 資料處理指令
  • 程式狀態暫存器(PSR)處理指令
  • 載入/存回指令
  • 協同處理器指今
  • 例外事件產生指令

 

image

image

image

image

image

 

image

image

image

image

 

image

image

 

image

image

image

 

image

image

image

image

 

image

image

 

image

image

程式狀態暫存器:

image

image

image

image

http://www.slideshare.net/jserv/arm-and-soc-traning-part-ii-system