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 NRF_Read_Reg(uint8_t reg) { uint8_t reg_val; SPI_CSN_L(); SPI_RW(reg); reg_val = SPI_RW(0); /* 读取该寄存器返回数据 */ SPI_CSN_H(); /* 禁止该器件 */ return reg_val; }
/* ***************************************************************** * 写寄存器 ***************************************************************** */ uint8_t NRF_Write_Reg(uint8_t reg, uint8_t value) { uint8_t status; SPI_CSN_L(); status = SPI_RW(reg); SPI_RW(value); /* 写数据 */ SPI_CSN_H(); /* 禁止该器件 */ return status; }
uint8_t spiBurstFifoAccess(uint8_t addrByte, uint8_t * pData, uint8_t len) { SPI_CSN_L(); // while (SPI_MISO_READ()); spi_writebyte(addrByte); SPI_WriteBuf(pData, len); SPI_CSN_H(); return 1; }
uint8_t Mrfi_SpiCmdStrobe(uint8_t cmd) { uint8_t statusByte; SPI_CSN_L(); // while (SPI_MISO_READ()); statusByte = spi_writebyte(cmd); SPI_CSN_H(); return(statusByte); }
uint8_t spiRegAccess(uint8_t addrByte, uint8_t writeValue) { uint8_t readValue; SPI_CSN_L(); // while (SPI_MISO_READ()); spi_writebyte(addrByte); readValue = spi_writebyte(writeValue); SPI_CSN_H(); return(readValue); }
/* ***************************************************************** * * 写缓冲区 * ***************************************************************** */ uint8_t NRF_Write_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* 选通器件 */ status = SPI_RW(reg); /* 写寄存器地址 */ for(i=0; i<uchars; i++) { SPI_RW(pBuf[i]); /* 写数据 */ } SPI_CSN_H(); /* 禁止该器件 */ return status; }
/* ***************************************************************** * 读缓冲区 ***************************************************************** */ uint8_t NRF_Read_Buf(uint8_t reg, uint8_t *pBuf, uint8_t uchars) { uint8_t i; uint8_t status; SPI_CSN_L(); /* 选通器件 */ status = SPI_RW(reg); /* 写寄存器地址 */ for(i=0; i<uchars; i++) { pBuf[i] = SPI_RW(0); /* 读取返回数据 */ } SPI_CSN_H(); /* 禁止该器件 */ return status; }