mdelay(1000);
nRF24L01_TxPacket(TxBuf);
SPI_RW_Reg(WRITE_REG+STATUS,0XFF);
printk("test 3 \n");
mdelay(1000);
nRF24L01_TxPacket(TxBuf);
SPI_RW_Reg(WRITE_REG+STATUS,0XFF);
printk("test 4 \n");
mdelay(1000);
*/
return (1);
}
//函数:uint8 SPI_RW(uint8 tmp)
//功能:NRF24L01的SPI写时序tmp
uint8 SPI_RW(uint8 tmp)
{
uint8 bit_ctr;
for(bit_ctr=0 ;bit_ctr<8 ;bit_ctr++) // output 8-bit
{
if(tmp & 0x80) // output 'tmp', MSB to MOSI
MOSI_H;
else
MOSI_L;
tmp <<= 1; // shift next bit into MSB..
SCK_H; // Set SCK high..
ndelay(60);
tmp |= MISO_STU; // capture current MISO bit
SCK_L; // ..then set SCK low again
ndelay(60);
}
return(tmp); // return read tmp
}
//函数:uint8 SPI_Read(uint8 reg)
//功能:NRF24L01的SPI时序
uint8 SPI_Read(uint8 reg)
{
uint8 reg_val;
CSN_L; // CSN low, initialize SPI communication...
ndelay(60);
SPI_RW(reg); // Select register to read from..
reg_val = SPI_RW(0); // ..then read registervalue
CSN_H; // CSN high, terminate SPI communication
ndelay(60);
return(reg_val); // return register value
}
//功能:NRF24L01读写寄存器函数
uint8 SPI_RW_Reg(uint8 reg, uint8 value)
{
uint8 status;
CSN_L; // CSN low, init SPI transaction
ndelay(60);
status = SPI_RW(reg); // select register
SPI_RW(value); // ..and write value to it..
CSN_H; // CSN high again
ndelay(60);
return(status); // return nRF24L01 status uint8
}
//函数:uint8 SPI_Read_Buf(uint8 reg, uint8 *pBuf, uint8 uchars)
//功能: 用于读数据,reg:为寄存器地址,pBuf:为待读出数据地址,uchars:读出数据的个数
uint8 SPI_Read_Buf(uint8 reg, uint8 *pBuf, uint8 uchars)
{
uint8 status,uint8_ctr;
CSN_L; // Set CSN low, init SPI tranaction
ndelay(60);
status = SPI_RW(reg); // Select register to write to and read status uint8
for(uint8_ctr=0;uint8_ctr
pBuf[uint8_ctr] = SPI_RW(0); //
ndelay(20);
}
CSN_H;
ndelay(60);
return(status); // return nRF24L01 status uint8
}
//函数:uint8 SPI_Write_Buf(uint8 reg, uint8 *pBuf, uint8 uchars)
//功能: 用于写数据:为寄存器地址,pBuf:为待写入数据地址,uchars:写入数据的个数
uint8 SPI_Write_Buf(uint8 reg, uint8 *pBuf, uint8 uchars)
{
uint8 status,uint8_ctr;
CSN_L; //SPI使能
ndelay(60);
status = SPI_RW(reg);
for(uint8_ctr=0; uint8_ctr
SPI_RW(*pBuf++);
ndelay(20);
}
CSN_H; //关闭SPI
ndelay(60);
return(status); //
}
//函数:void SetRX_Mode(void)
//功能:数据接收配置
void SetRX_Mode(void)
{
CE_L;
ndelay(60);
// SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f); // IRQ收发完成中断响应,16位CRC ,主接收
//udelay(1);
CE_H;
udelay(130);
}
//函数:unsigned char nRF24L01_RxPacket(unsigned char* rx_buf)
//功能:数据读取后放如rx_buf接收缓冲区中
unsigned char nRF24L01_RxPacket(unsigned char* rx_buf)
{
unsigned char reva le=0;
sta=SPI_Read(STATUS); // 读取状态寄存其来判断数据接收状况
if(sta & (1<
CE_L; //SPI使能
udelay(50);
SPI_Read_Buf(RD_RX_PLOAD,rx_buf,TX_PLOAD_WIDTH);// read receive payload from RX_FIFO buffer
reva le =1; //读取数据完成标志
}
SPI_RW_Reg(WRITE_REG+STATUS,sta); //接收到数据后RX_DR,TX_DS,MAX_PT都置高为1,通过写1来清楚中断标志