⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nrf24l01.c~

📁 ld2330语音模块程序
💻 C~
字号:

//============================================================================
//本文档用于驱动nRF24L01

//********接收数据宽度*********                                                            
unsigned char flash RDW[6]={13,13,13,13,13,13};
//*******接收地址**********
static unsigned char ADDR0[6]={0x0A,0,2,3,4,5};
static unsigned char ADDR1[6]={0x0B,1,2,3,4,5};
#define ADDR2 2
#define ADDR3 3
#define ADDR4 4
#define ADDR5 5
//******发送地址***********
static unsigned char TxAddr[6]={0x10,1,2,3,4,5};

#define nRF24L01_RxMode CLI_CE nRF24L01_WriteReg(0x00,0x0F);SET_CE
#define nRF24L01_TxMode  CLI_CE nRF24L01_WriteReg(0x00,0x0E);SET_CE        
 
//nRF24L01 SPI总线说明:
//   1. 低字节先传送,高字节后传送,基于小端格式的传送
//   2.字节内部高位先传送,低位后传送
//============================================================================
//功能:  向nRF24L01发送数据
void nRF24L01_WriteBytes(unsigned char *Buffer,unsigned char Bytes)
{
          SEL_CS3                                                    //选中nRF24L01 
          Buffer[0]|=0x20;                                       //加入写寄存器标记
          SPI_WriteBytes(Buffer,Bytes);               //发送数据
          SEL_NON                                                   //释放nRF24L01
}                                                                                                          
//============================================================================
//功能:  从nRF24L01接收数据
void nRF24L01_ReadBytes(unsigned char *Buffer,unsigned char Bytes)
{
          SEL_CS3                                                   //选中nRF24L01
          SPI_ReadBytes(Buffer,Bytes);            //读取数据  
          SEL_NON                                                  //释放nRF24L01
}
//============================================================================
//功能: 写nRF24L01寄存器
void nRF24L01_WriteReg(unsigned char Reg,unsigned char Value)
{
          unsigned char Buffer[2];
          SEL_CS3
          Buffer[0]=Reg|0x20;
          Buffer[1]=Value;
          SPI_WriteBytes(Buffer,2);
          SEL_NON          
}
//============================================================================
//功能:  读取nRF24L01的状态
unsigned char nRF24L01_GetStatus()
{
          unsigned char Status;
          Status=0xFF;
          SEL_CS3
          SPI_ReadBytes(&Status,1);
          SEL_NON
          return Status;
}


//============================================================================
//功能:  nRF24L01芯片初始化
//Time: 2008-4-8
//Vision: V1.0
void nRF24L01_Init()
{
     CLI_CE
     nRF24L01_WriteReg(0x01,0x00);            //通道0自动应答
     nRF24L01_WriteReg(0x02,0x3F);            //通道0接收使能
     nRF24L01_WriteReg(0x03,0x03);            //地址宽度为5bytes
     nRF24L01_WriteReg(0x04,0x00);            //出错自动重发,4000uS+86uS等待,重发15次
     nRF24L01_WriteReg(0x05,0x01);            //选择通道1
     nRF24L01_WriteReg(0x06,0x0F);            //1Mbps,0dBm,接收放大器使能
     nRF24L01_WriteReg(0x07,0x00);            //状态寄存器复位                                                        
     nRF24L01_WriteBytes(ADDR0,6);            //设置通道0地址
     nRF24L01_WriteBytes(ADDR1,6);            //设置通道1地址     
     nRF24L01_WriteReg(0x0C,ADDR2);         //设置通道2地址 
     nRF24L01_WriteReg(0x0D,ADDR3);         //设置通道3地址 
     nRF24L01_WriteReg(0x0E,ADDR4);         //设置通道4地址 
     nRF24L01_WriteReg(0x0F,ADDR5);         //设置通道5地址 
     nRF24L01_WriteBytes(TxAddr,6);            //设置发送地址
     nRF24L01_WriteReg(0x11,RDW[0]);         //通道0接收数据长度(字节)
     nRF24L01_WriteReg(0x12,RDW[1]);         //通道1接收数据长度(字节)
     nRF24L01_WriteReg(0x13,RDW[2]);         //通道2接收数据长度(字节)
     nRF24L01_WriteReg(0x14,RDW[3]);         //通道3接收数据长度(字节)
     nRF24L01_WriteReg(0x15,RDW[4]);         //通道4接收数据长度(字节)
     nRF24L01_WriteReg(0x16,RDW[5]);         //通道5接收数据长度(字节)     
}

//=============================================================================
//功能:  nRF24L01发送数据
//Time: 2008-4-8
//Vision:  V1.0
unsigned char nRF24L01_SendData(unsigned char *TxBuffer,unsigned char TDW)
{     
      unsigned char Reg=0xA0;
      nRF24L01_TxMode
      SEL_CS3
      SPI_ReadBytes(&Reg,1);
      SPI_WriteBytes(TxBuffer,TDW);
      SEL_NON
      CLI_CE
      return Reg;
}

//==============================================================================
//功能:  nRF24L01接收数据
//Time: 2008-4-8
//Vision: V1.0
unsigned char nRF24L01_RecData(unsigned char *RxBuffer,unsigned char RDW)
{
        unsigned char Reg=0x61;
        SEL_CS3
        SPI_ReadBytes(&Reg,1);
        SPI_ReadBytes(RxBuffer,RDW);
        SEL_NON        
        return Reg;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -