PIC16F877A單片機(jī)SPI學(xué)習(xí)
掃描二維碼
隨時(shí)隨地手機(jī)看文章
PIR1 Register
The PIR1 register contains the individual flag bits for the peripheral
interrupts.
PIR1 REGISTER
PSPIF ADIF RCIF TXIF SSPIF CCP1IF TMR2IF TMR1IF
SSPIF:Synchronous Serial Port Interrupt Flag bit
1 = The SSP interrupt condition has occurred and must be cleared in software
before returning from the interrupt Service Routine. The condition that will
set this are:
SPI-A transmission/reception has taken,place.
I2C Slave - A transmission/reception has taken place.
I2C Master
0 = No SSP interrupt condition has occurred.
SSPCON1: MSSP CONTROL REGISTER1
WCOL SSPOV SSPEN CKP SSPM3 SSPM2 SSPM1 SSPM0
SMP:Sample bit
SPI Master mode:
1 = Input data sampled at end of data output time
0 = Input data sampled at middle of data output time
SPI Slave mode:
SMP must be cleared when SPI is used in Slave mode.
CKE:SPI Clock Select bit
1 = Transmit occurs on transition from active to Idle clock state
0 = Transmit occurs on transition from Idle to active clock state
BF:Buffer Full Status bit(Recevie mode only)
1 = Receive complete,SSPBUF is full
0 = Receive not complete,SSPBUF is empty
SSPSR寄存器我們是不能直接使用的。
SPI的工作方式可以從兩個(gè)方面來(lái)看,一個(gè)是數(shù)據(jù)的傳送,一個(gè)是數(shù)據(jù)的接收。送出數(shù)據(jù)的時(shí)候,只要將數(shù)據(jù)寫(xiě)入SSPBUF即可;在數(shù)據(jù)傳送完成之后,SSPIF中斷標(biāo)志位會(huì)置1。接收的時(shí)間就比較復(fù)雜了。當(dāng)有數(shù)據(jù)從SDI引腳進(jìn)入單片機(jī)之后,會(huì)被存往往到SSPSR寄存器中,當(dāng)完整的8個(gè)位接收完畢之后,這個(gè)字節(jié)的數(shù)據(jù)就會(huì)自動(dòng)的放到SSPBUF中,一旦SSPBUF中放入新的數(shù)據(jù),SSPCON寄存器中的BF位就會(huì)自動(dòng)的設(shè)定為1,表示SSPBUF已經(jīng)填入了新的值,也表示數(shù)據(jù)的接收已完成。
由于PIC16F877A通過(guò)SDO發(fā)送數(shù)據(jù)的同時(shí),會(huì)通過(guò)SDI讀入數(shù)據(jù),當(dāng)1字節(jié)的發(fā)送完成時(shí),剛好接收1字節(jié)到SSPBUF,這時(shí)SSPBUF滿,BF被置1,故可通過(guò)BF標(biāo)志判斷1字節(jié)是否發(fā)送完成。