[Microchip]/PIC16F2012. 6. 9. 01:31

[PIC16F73] SPI 테스트

[PIC16F73] SPI 테스트

 

- FOSC/4 (or TCY)
- FOSC/16 (or 4 • TCY)
- FOSC/64 (or 16 • TCY)
- (Timer2 output)/2 data rate of 5 Mbps(at FOSC = 20 MHz).

 

 

PIC16F723 SPI 블록도

 

 

 

 

 

 

PIC16F723 SPI 레지스터

 

 

 

 

 

PIC16F723 SPI초기화 함수

void SPI0_Init(void)
{
 //RC3 pin => SCK output
 //RC4 pin => SDI input
 //RC5 pin => SDO output
 SSPBUF = 0x00;  //SSPBUF Clear
 ADCON1 = 0x06;

 Cbi(TRISC, (BIT3|BIT5));
 Sbi(TRISC, (BIT4));

 SSPSTAT = 0;
 SSPEN = 1;    //spi enable
 SSPM2 = 0;    //master 

 SSPM1 = 0;SSPM0 = 0; // FOSC/4
 
 CKE = 1;        // data transmitted on rising edge
 CKP = 0;        // clock idle state low
}

 

 

PIC16F723 SPI Write Read함수 포팅

unsigned char SPI0_WriteReadByte(unsigned char Data)
{
 SSPBUF = Data;           // write to buffer for TX
 while ( !BF );          // wait until cycle complete
 return ( SSPBUF );      // return with byte read
}

 

Posted by nexp

댓글을 달아 주세요