void cc1101_init(void) { SPI_CSN_L(); Mrfi_DelayUsec(10); SPI_CSN_H(); Mrfi_DelayUsec(40); SPI_CSN_L(); while (SPI_MISO_READ()); spi_writebyte(SRES); while (SPI_MISO_READ()); SPI_CSN_H(); RfWriteRfSettings(); Mrfi_SpiWriteReg(TI_CCxxx0_IOCFG0, 0x06); { uint8_t tmp = 0; tmp = Mrfi_SpiReadReg(TI_CCxxx0_IOCFG0); if(tmp != 0x06) while(1); } Mrfi_SpiCmdStrobe(SIDLE); Mrfi_SpiCmdStrobe(SRX); P2IES |= GPIO0; // Ñ¡ÔñÉÏÉý/ϽµÑØ P2REN |= GPIO0; // push-up enable P2IFG &=~GPIO0; P2IE |= GPIO0; }
uint8_t spi_writebyte (uint8_t value) { uint8_t i,temp,data; data = value; temp = 0; for(i = 0;i < 8;i ++) { if((data&0x80) == 0x80) SPI_MOSI_H(); else SPI_MOSI_L(); SPI_SCLK_H(); data = data<<1; if(SPI_MISO_READ() == 1) { temp = temp | (1<<(7-i)); } SPI_MOSI_L(); SPI_SCLK_L(); } return temp; }
unsigned char spi_TxByte(unsigned char txchar) { unsigned char received_ch=0,index; for(index=0; index <8;index++) { if(txchar & 0x80) { SPI_MOSI_SETHIGH(); } else { SPI_MOSI_SETLOW(); } SPI_SCK_SETHIGH(); received_ch <<=1; if (SPI_MISO_READ()) { received_ch |=0x01; } txchar <<=1; Delay_ms(5); SPI_SCK_SETLOW(); Delay_ms(5); } return received_ch; }