diff --git a/24l01.c b/24l01.c index 4ad868c..cfacee7 100644 --- a/24l01.c +++ b/24l01.c @@ -34,8 +34,9 @@ void NRF24L01_Init(void) SPI2_Init(); - Clr_NRF24L01_CE; - Set_NRF24L01_CSN; + Clr_NRF24L01_CE; //ENABLE 24L01 + Set_NRF24L01_CSN; //CANCLE SPI_CS +} /**检测24L01是否存在,返回值为1则失败,返回值为0则成功**/ u8 NRF24L01_Check(void) { @@ -49,4 +50,109 @@ void NRF24L01_Init(void) return 1; return 0; } + +u8 NRF24L01_Write_Reg(u8 reg,u8 value) +{ + u8 status; + Clr_NRF24L01_CSN; //ENABLE SPI + SPIx_ReadWriteByte(reg); + reg_val = SPIx_ReadWriteByte(0XFF); + Set_NRF24L01_CSN; //DISABLE SPI + return(reg_val); } + +u8 NRF24L01_Read_Reg(u8 reg) + { + u8 reg_val; + Clr_NRF24L01_CSN; + SPIx_ReadWriteByte(reg); + reg_val=SPIx_ReadWriteByte(0XFF); + Set_NRF24L01_CSN; + return(reg_val); + } + +u8 NRF24L01_Read_Buf(u8 reg, u8 *pBuf, u8 len) +{ + u8 status, u8_ctr; + Clr_NRF24L01_CSN; //ENABLE SPI + status = SPIx_ReadWriteByte(reg); + for(u8_ctr = 0 ; u8_ctr < len ; u8_ctr ++) + pBuf[u8_ctr] = SPIx_ReadWriteByte(0XFF); + Set_NRF24L01_CSN //DISABLE SPI + return status; +} + +u8 NRF24L01_Write_Buf(u8 reg, u8 *pBuf, u8 len) + { + u8 status,u8_ctr; + Clr_NRF24L01_CSN; + status = SPIx_ReadWriteByte(reg); + for(u8_ctr=0; u8_ctr