This routine sets up SPI transfer
void SetupSPI(void)
{ SSPSTAT=0x40; SSPCON=0x21; }
void SetupSPI_CC1000(void) { SSPSTAT=0x40; SSPCON=0x31; } //============================================================ BYTE SPI_write(BYTE value) { unsigned char data; int i; SSPBUF=value; // SSPBUF=(addr<<1)|0x01; // Write address to rf, write bit is always 1 // Wait until data is written i=0x500; while (STAT_BF==0) { i--; if(i==0) return 0; } data=SSPBUF; return data; }
//=============================================================== BYTE SPI_read() { char Value; int i; SSPBUF=0xFF; // Dummy write i=0x500; while (STAT_BF==0) { i--; if(i==0) return 0; } Value=SSPBUF;
return Value; }
|