You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

958 line
43KB

  1. #include "nrf24L01.h"
  2. #include "printf.h"
  3. #include "delay.h"
  4. const u8 TX_ADDRESS[5]={0x34,0x43,0x10,0x10,0x01}; //发送地址
  5. const u8 RX_ADDRESS[5]={0x34,0x43,0x10,0x10,0x01};
  6. const u8 addr[5]={0x33,0x20,0x0D,0x54,0x79};
  7. const u8 Jiang_Xi[5]={0x33,0x20,0x0D,0x54,0x79};
  8. const u8 TEL_PO[5]={0x34,0x43,0x10,0x10,0x01};
  9. const u8 YUN_NAN[5]={0x01,0x10,0x10,0x43,0x34};
  10. const u8 GUI_ZHOU[5]={0x32,0x23,0xAB,0xBA,0x01};
  11. const u8 SI_CHUAN[5]={0x34,0x12,0xBB,0xAA,0x01};
  12. const u8 NEI_MENG_GU[5]={0x34,0x12,0x86,0x75,0x01};
  13. const u8 AN_HUI[5]={0x46,0x56,0x43,0x10,0x00};
  14. const u8 SHAN_XI_XIN_NUO[5]={0x34,0x6E,0x46,0x10,0x01};
  15. const u8 VCM[5]={0x34,0x43,0x10,0x10,0x01};
  16. const u8 LIAO_NING[5]={0x86,0x2c,0x95,0x01,0x01};
  17. const u8 NEW_LIAO_NING[5] = {0x36,0xE4,0xA7,0xBC,0x01};
  18. const u8 TP[5] = {0x42,0x18,0xba,0xe8,0x01};
  19. const u8 NEI_MENG_GU_YI_DONG[5]={0x34,0x12,0x86,0x75,0x01};
  20. const u8 GUANG_XI_YI_DONG[5]={0x33,0x20,0x0D,0x54,0x00};
  21. const u8 LIAO_NING_DIAN_XI[5]={0x86,0x2C,0x95,0x00,0x00};
  22. const u8 FU_JIAN_ZHEN_ZHUO[5]={0x5A,0x45,0x4E,0x4B,0x00};
  23. const u8 SU_ZHOU_MU_LANG[5]={0xAA,0xBB,0x12,0x34,0x00};
  24. const u8 CHONG_QIN_YI_DONG[5]={0x34,0x12,0xBB,0xAA,0x00};
  25. const u8 SHAN_XI_YI_DONG[5]={0x25,0x43,0x10,0x12,0x00};
  26. const u8 QUAN_TONG[5]={0xe7,0x7e,0xe3,0x00,0x00};
  27. const u8 GAN_SU_YI_DONG[5]={0x42,0x22,0xB6,0xE9,0x00};
  28. const u8 XDF[5]={0xC0,0x13,0xE3,0x00,0x00};
  29. const u8 DH[5] = {0x83,0x21,0x95,0x15,0x00};
  30. const u8 ANHUI_DIANXIN[5] = {0x41,0x15,0x43,0x12,0x00};
  31. //初始化24L01的IO口
  32. void NRF24L01_Init(void)
  33. {
  34. GPIO_InitTypeDef GPIO_InitStructure;
  35. //使能PA,B,C端口时钟
  36. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
  37. GPIO_InitStructure.GPIO_Pin = SPI1_CE_Pin; // SPI1--CE
  38. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  39. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  40. GPIO_Init(SPI1_CE_Port, &GPIO_InitStructure); //初始化指定IO
  41. GPIO_SetBits(SPI1_CE_Port,SPI1_CE_Pin);//上拉
  42. GPIO_InitStructure.GPIO_Pin = SPI1_CS_Pin; // SPI1--CS
  43. GPIO_Init(SPI1_CS_Port, &GPIO_InitStructure); //初始化指定IO
  44. GPIO_SetBits(SPI1_CS_Port,SPI1_CS_Pin);//上拉
  45. GPIO_InitStructure.GPIO_Pin = SPI1_IRQ_Pin; // SPI1--IRQ
  46. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
  47. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  48. GPIO_Init(SPI1_IRQ_Port, &GPIO_InitStructure); //初始化指定IO
  49. GPIO_InitStructure.GPIO_Pin = SPI2_CE_Pin;
  50. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
  51. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  52. GPIO_Init(SPI2_CE_Port, &GPIO_InitStructure); //初始化指定IO
  53. GPIO_SetBits(SPI2_CE_Port,SPI2_CE_Pin);//上拉
  54. GPIO_InitStructure.GPIO_Pin = SPI2_CS_Pin;
  55. GPIO_Init(SPI2_CS_Port, &GPIO_InitStructure); //初始化指定IO
  56. GPIO_SetBits(SPI2_CS_Port,SPI2_CS_Pin);//上拉
  57. GPIO_InitStructure.GPIO_Pin = SPI2_IRQ_Pin; //SPI2--IQR
  58. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
  59. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  60. GPIO_Init(SPI2_IRQ_Port, &GPIO_InitStructure); //初始化指定IO
  61. SPI2_Init(); //初始化SPI
  62. SPI1_Init();
  63. SPI1_CE =0; //使能24L01
  64. SPI1_CSN=1; //SPI片选取消
  65. SPI2_CE =0; //使能24L01
  66. SPI2_CSN=1; //SPI片选取消
  67. SPI_SetSpeed(SPI_REV,SPI_BaudRatePrescaler_4);
  68. }
  69. void NRF24L01_Config(SPIType spiNum)
  70. {
  71. if(spiNum == SPI_PORT1)
  72. {
  73. SPI1_CE = 0; //chip enable
  74. SPI1_CSN = 1; //SPI disable
  75. }
  76. else
  77. {
  78. SPI2_CE = 0; //chip enable
  79. SPI2_CSN = 1; //SPI disable
  80. }
  81. }
  82. //SPI写寄存器
  83. //reg:指定寄存器地址
  84. //value:写入的值
  85. u8 NRF24L01_Write_Reg(SPIType spiNum,u8 reg,u8 value)
  86. {
  87. u8 status;
  88. if(spiNum == SPI_PORT1){
  89. SPI1_CSN=0; //使能SPI传输
  90. status =SPI_ReadWriteByte(spiNum,reg);//发送寄存器号
  91. SPI_ReadWriteByte(spiNum,value); //写入寄存器的值
  92. SPI1_CSN=1; //禁止SPI传输
  93. }else{
  94. SPI2_CSN=0; //使能SPI传输
  95. status =SPI_ReadWriteByte(spiNum,reg);//发送寄存器号
  96. SPI_ReadWriteByte(spiNum,value); //写入寄存器的值
  97. SPI2_CSN=1; //禁止SPI传输
  98. }
  99. return(status); //返回状态值
  100. }
  101. //读取SPI寄存器值
  102. //reg:要读的寄存器
  103. u8 NRF24L01_Read_Reg(SPIType spiNum,u8 reg)
  104. {
  105. u8 reg_val;
  106. if(spiNum == SPI_PORT1){
  107. SPI1_CSN = 0; //使能SPI传输
  108. SPI_ReadWriteByte(spiNum,reg); //发送寄存器号
  109. reg_val=SPI_ReadWriteByte(spiNum,0XFF);//读取寄存器内容
  110. SPI1_CSN = 1; //禁止SPI传输
  111. }else{
  112. SPI2_CSN = 0; //使能SPI传输
  113. SPI_ReadWriteByte(spiNum,reg); //发送寄存器号
  114. reg_val=SPI_ReadWriteByte(spiNum,0XFF);//读取寄存器内容
  115. SPI2_CSN = 1; //禁止SPI传输
  116. }
  117. return(reg_val); //返回状态值
  118. }
  119. //在指定位置读出指定长度的数据
  120. //reg:寄存器(位置)
  121. //*pBuf:数据指针
  122. //len:数据长度
  123. //返回值,此次读到的状态寄存器值
  124. u8 NRF24L01_Read_Buf(SPIType spiNum,u8 reg,u8 *pBuf,u8 len)
  125. {
  126. u8 status,u8_ctr;
  127. if(spiNum == SPI_PORT1){
  128. SPI1_CSN = 0; //使能SPI传输
  129. status=SPI_ReadWriteByte(spiNum,reg);//发送寄存器值(位置),并读取状态值
  130. for(u8_ctr=0;u8_ctr<len;u8_ctr++)pBuf[u8_ctr]=SPI_ReadWriteByte(spiNum,0XFF);//读出数据
  131. SPI1_CSN=1; //关闭SPI传输
  132. }else{
  133. SPI2_CSN = 0; //使能SPI传输
  134. status=SPI_ReadWriteByte(spiNum,reg);//发送寄存器值(位置),并读取状态值
  135. for(u8_ctr=0;u8_ctr<len;u8_ctr++)pBuf[u8_ctr]=SPI_ReadWriteByte(spiNum,0XFF);//读出数据
  136. SPI2_CSN=1; //关闭SPI传输
  137. }
  138. return status; //返回读到的状态值
  139. }
  140. //在指定位置写指定长度的数据
  141. //reg:寄存器(位置)
  142. //*pBuf:数据指针
  143. //len:数据长度
  144. //返回值,此次读到的状态寄存器值
  145. u8 NRF24L01_Write_Buf(SPIType spiNum,u8 reg, u8 *pBuf, u8 len)
  146. {
  147. u8 status,u8_ctr;
  148. if(spiNum == SPI_PORT1){
  149. SPI1_CSN = 0; //使能SPI传输
  150. status = SPI_ReadWriteByte(spiNum,reg);//发送寄存器值(位置),并读取状态值
  151. for(u8_ctr=0; u8_ctr<len; u8_ctr++)SPI_ReadWriteByte(spiNum,*pBuf++); //写入数据
  152. SPI1_CSN = 1; //关闭SPI传输
  153. }else{
  154. SPI2_CSN = 0; //使能SPI传输
  155. status = SPI_ReadWriteByte(spiNum,reg);//发送寄存器值(位置),并读取状态值
  156. for(u8_ctr=0; u8_ctr<len; u8_ctr++)SPI_ReadWriteByte(spiNum,*pBuf++); //写入数据
  157. SPI2_CSN = 1; //关闭SPI传输
  158. }
  159. return status; //返回读到的状态值m
  160. }
  161. //******************************************************
  162. //
  163. //检测24L01是否存在
  164. // spiNum: SPI_PORT1--SPI1, SPI_PORT2----SPI2
  165. //返回值:0,成功;1,失败
  166. u8 NRF24L01_Check(SPIType spiNum)
  167. {
  168. u8 buf[5]={0XA5,0XA5,0XA5,0XA5,0XA5};
  169. u8 i;
  170. SPI_SetSpeed(spiNum,SPI_BaudRatePrescaler_4); //spi速度为9Mhz(24L01的最大SPI时钟为10Mhz)
  171. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,buf,5);//写入5个字节的地址.
  172. NRF24L01_Read_Buf(spiNum,TX_ADDR,buf,5); //读出写入的地址
  173. for(i=0;i<5;i++)if(buf[i]!=0XA5)break;
  174. if(i!=5)return 1;//检测24L01错误
  175. return 0; //检测到24L01
  176. }
  177. //*********************************************************
  178. //启动NRF24L01发送一次数据
  179. // spiNum: SPI_PORT1--SPI1, SPI_PORT2----SPI2
  180. //txbuf:待发送数据首地址
  181. //返回值:发送完成状况
  182. u8 NRF24L01_TxPacket(SPIType spiNum,u8 *txbuf)
  183. {
  184. u8 sta;
  185. SPI_SetSpeed(spiNum,SPI_BaudRatePrescaler_4);//spi速度为9Mhz(24L01的最大SPI时钟为10Mhz)
  186. if(spiNum == SPI_PORT1){
  187. SPI1_CE = 0;
  188. }else{
  189. SPI2_CE=0;
  190. }
  191. NRF24L01_Write_Buf(spiNum,WR_TX_PLOAD,txbuf,TX_PLOAD_WIDTH);//写数据到TX BUF 32个字节
  192. if(spiNum == SPI_PORT1){ //启动发送
  193. SPI1_CE = 1;
  194. }else{
  195. SPI2_CE=1;
  196. }
  197. if(spiNum == SPI_PORT1){
  198. while(SPI1_IRQ!=0);//等待发送完成
  199. }else{
  200. while(SPI2_IRQ!=0);//等待发送完成
  201. }
  202. sta=NRF24L01_Read_Reg(spiNum,STATUS); //读取状态寄存器的值
  203. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,sta); //清除TX_DS或MAX_RT中断标志
  204. if(sta&MAX_TX)//达到最大重发次数
  205. {
  206. NRF24L01_Write_Reg(spiNum,FLUSH_TX,0xff);//清除TX FIFO寄存器
  207. return MAX_TX;
  208. }
  209. if(sta&TX_OK)//发送完成
  210. {
  211. return TX_OK;
  212. }
  213. return 0xff;//其他原因发送失败
  214. }
  215. //启动NRF24L01发送一次数据
  216. //txbuf:待发送数据首地址
  217. //返回值:0,接收完成;其他,错误代码
  218. //u8 NRF24L01_RxPacket(SPIType spiNum,u8 *rxbuf)
  219. //{
  220. // u8 sta;
  221. // SPI_SetSpeed(spiNum,SPI_BaudRatePrescaler_8); //spi速度为9Mhz(24L01的最大SPI时钟为10Mhz)
  222. // sta=NRF24L01_Read_Reg(spiNum,STATUS); //读取状态寄存器的值
  223. // NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,sta); //清除TX_DS或MAX_RT中断标志
  224. // if(sta&RX_OK)//接收到数据
  225. // {
  226. // NRF24L01_Read_Buf(spiNum,RD_RX_PLOAD,rxbuf,RX_PLOAD_WIDTH); //读取数据
  227. // NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  228. // return 0;
  229. // }
  230. // return 1;//没收到任何数据
  231. //}
  232. u8 NRF24L01_RxPacket(SPIType spiNum,u8 *rxbuf)
  233. {
  234. u8 sta;
  235. SPI_SetSpeed(spiNum,SPI_BaudRatePrescaler_8); //spi速度为9Mhz(24L01的最大SPI时钟为10Mhz)
  236. sta=NRF24L01_Read_Reg(spiNum,STATUS); //读取状态寄存器的值
  237. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,sta); //清除TX_DS或MAX_RT中断标志
  238. if(sta&RX_OK)//接收到数据
  239. {
  240. NRF24L01_Read_Buf(spiNum,RD_RX_PLOAD,rxbuf,RX_PLOAD_WIDTH); //读取数据
  241. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  242. //return 0;
  243. }
  244. //return 1;//没收到任何数据
  245. return sta;
  246. }
  247. //该函数初始化NRF24L01到RX模式
  248. //设置RX地址,写RX数据宽度,选择RF频道,波特率和LNA HCURR
  249. //当CE变高后,即进入RX模式,并可以接收数据了
  250. void NRF24L01_RX_Mode(SPIType spiNum)
  251. {
  252. if(spiNum == SPI_PORT1){
  253. SPI1_CE =0;
  254. }else{
  255. SPI2_CE=0;
  256. }
  257. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --3字节
  258. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH);//写RX节点地址
  259. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)TX_ADDRESS,TX_ADR_WIDTH);//写TX节点地址
  260. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x01); //使能通道0的自动应答
  261. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  262. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,42); //设置RF通信频率
  263. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  264. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  265. // NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH);//选择通道0的有效数据宽度
  266. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x06);
  267. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x01); /// P0
  268. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  269. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  270. if(spiNum == SPI_PORT1){ //CE为高,进入接收模式
  271. SPI1_CE =1;
  272. }else{
  273. SPI2_CE=1;
  274. }
  275. }
  276. void NRF24L01_RX_Mode_NOACK_VCOM(SPIType spiNum) //读VCOM考勤接收配置
  277. {
  278. if(spiNum == SPI_PORT1){
  279. SPI1_CE =0;
  280. }else{
  281. SPI2_CE=0;
  282. }
  283. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --3字节
  284. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH);//写RX节点地址
  285. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)TX_ADDRESS,TX_ADR_WIDTH);//写TX节点地址
  286. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  287. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  288. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,42); //设置RF通信频率
  289. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  290. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  291. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH);//选择通道0的有效数据宽度
  292. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x00);
  293. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x01); /// P0
  294. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  295. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  296. if(spiNum == SPI_PORT1){ //CE为高,进入接收模式
  297. SPI1_CE =1;
  298. }else{
  299. SPI2_CE=1;
  300. }
  301. }
  302. #if APP
  303. void NRF24L01_RX_JiangXi_CONFIG(SPIType spiNum)
  304. {
  305. #if 1
  306. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  307. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)Jiang_Xi,5);//写RX节点地址
  308. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)Jiang_Xi,5);//写TX节点地址
  309. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  310. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  311. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  312. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x21);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  313. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  314. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  315. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x00);
  316. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x01); /// P0
  317. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  318. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  319. #else
  320. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --4字节
  321. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)QUAN_TONG,3);//写RX节点地址
  322. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)QUAN_TONG,3);//写TX节点地址
  323. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  324. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  325. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,6); //设置RF通信频率
  326. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x0f);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  327. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  328. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  329. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x00);
  330. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x01); /// P0
  331. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  332. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  333. #endif
  334. }
  335. void NRF24L01_RX_TelPo_CONFIG(SPIType spiNum)
  336. {
  337. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x03);//地址宽度 --5字节
  338. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)TEL_PO,5);//写RX节点地址
  339. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)TEL_PO,5);//写TX节点地址
  340. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x3f); //使能通道0的自动应答
  341. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x3f);//使能通道0的接收地址
  342. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,40); //设置RF通信频率
  343. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  344. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0b);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  345. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  346. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  347. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  348. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  349. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  350. }
  351. void NRF24L01_RX_YunNan_CONFIG(SPIType spiNum)
  352. {
  353. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x03);//地址宽度 --5字节
  354. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)YUN_NAN,5);//写RX节点地址
  355. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)YUN_NAN,5);//写TX节点地址
  356. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  357. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  358. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,16); //设置RF通信频率
  359. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  360. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  361. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  362. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  363. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  364. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  365. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  366. }
  367. void NRF24L01_RX_GuiZhou_CONFIG(SPIType spiNum)
  368. {
  369. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  370. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)GUI_ZHOU,5);//写RX节点地址
  371. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)GUI_ZHOU,5);//写TX节点地址
  372. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x3f); //使能通道0的自动应答
  373. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  374. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  375. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  376. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  377. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  378. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  379. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  380. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  381. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  382. }
  383. void NRF24L01_RX_SiChuan_CONFIG(SPIType spiNum)
  384. {
  385. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  386. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)SI_CHUAN,5);//写RX节点地址
  387. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)SI_CHUAN,5);//写TX节点地址
  388. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  389. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  390. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  391. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  392. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  393. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,8);//选择通道0的有效数据宽度
  394. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  395. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  396. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  397. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  398. }
  399. void NRF24L01_RX_NeiMengGu_CONFIG(SPIType spiNum)
  400. {
  401. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  402. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)NEI_MENG_GU,5);//写RX节点地址
  403. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)NEI_MENG_GU,5);//写TX节点地址
  404. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  405. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  406. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  407. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  408. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  409. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  410. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  411. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  412. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  413. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  414. }
  415. void NRF24L01_RX_AnHui_CONFIG(SPIType spiNum)
  416. {
  417. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  418. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)AN_HUI,5);//写RX节点地址
  419. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)AN_HUI,5);//写TX节点地址
  420. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x3F); //使能通道0的自动应答
  421. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  422. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,26); //设置RF通信频率
  423. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  424. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  425. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  426. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  427. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  428. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  429. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  430. }
  431. void NRF24L01_RX_ShanXiXinNuo_CONFIG(SPIType spiNum)
  432. {
  433. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --4字节
  434. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)SHAN_XI_XIN_NUO,5);//写RX节点地址
  435. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)SHAN_XI_XIN_NUO,5);//写TX节点地址
  436. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  437. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  438. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,16); //设置RF通信频率
  439. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  440. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  441. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,6);//选择通道0的有效数据宽度
  442. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  443. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  444. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  445. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  446. }
  447. void NRF24L01_RX_VCM_CONFIG(SPIType spiNum)
  448. {
  449. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --3字节
  450. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)VCM,3);//写RX节点地址
  451. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)VCM,3);//写TX节点地址
  452. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  453. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  454. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,42); //设置RF通信频率
  455. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  456. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  457. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,7);//选择通道0的有效数据宽度
  458. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x00);
  459. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x01); /// P0
  460. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  461. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  462. }
  463. void NRF24L01_RX_LIAO_NING_CONFIG(SPIType spiNum)
  464. {
  465. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --4字节
  466. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)LIAO_NING,5);//写RX节点地址
  467. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)LIAO_NING,5);//写TX节点地址
  468. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  469. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  470. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,25); //设置RF通信频率
  471. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  472. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  473. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,6);//选择通道0的有效数据宽度
  474. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  475. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  476. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  477. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  478. }
  479. void NRF24L01_RX_NEW_LIAO_NING_CONFIG(SPIType spiNum)
  480. {
  481. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  482. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)NEW_LIAO_NING,4);//写RX节点地址
  483. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)NEW_LIAO_NING,4);//写TX节点地址
  484. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  485. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  486. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,32); //设置RF通信频率
  487. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x20);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  488. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  489. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,8);//选择通道0的有效数据宽度
  490. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  491. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  492. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  493. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  494. }
  495. void NRF24L01_RX_TP_CONFIG(SPIType spiNum)
  496. {
  497. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  498. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)TP,4);//写RX节点地址
  499. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)TP,4);//写TX节点地址
  500. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  501. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  502. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,28); //设置RF通信频率
  503. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  504. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  505. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,8);//选择通道0的有效数据宽度
  506. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  507. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  508. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  509. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  510. }
  511. void NRF24L01_RX_NMGYD_CONFIG(SPIType spiNum)
  512. {
  513. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  514. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)NEI_MENG_GU_YI_DONG,4);//写RX节点地址
  515. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)NEI_MENG_GU_YI_DONG,4);//写TX节点地址
  516. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  517. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  518. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  519. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,250Kbps,低噪声增益开启
  520. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  521. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,0x0A);//选择通道0的有效数据宽度
  522. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  523. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  524. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  525. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  526. }
  527. void NRF24L01_RX_GXYD_CONFIG(SPIType spiNum)
  528. {
  529. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  530. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)GUANG_XI_YI_DONG,4);//写RX节点地址
  531. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)GUANG_XI_YI_DONG,4);//写TX节点地址
  532. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  533. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  534. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,51); //设置RF通信频率
  535. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  536. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  537. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,9);//选择通道0的有效数据宽度
  538. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  539. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  540. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  541. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  542. }
  543. void NRF24L01_RX_FJZZ_CONFIG(SPIType spiNum)
  544. {
  545. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  546. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)FU_JIAN_ZHEN_ZHUO,4);//写RX节点地址
  547. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)FU_JIAN_ZHEN_ZHUO,4);//写TX节点地址
  548. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  549. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  550. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,40); //设置RF通信频率
  551. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x0c);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  552. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  553. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,6);//选择通道0的有效数据宽度
  554. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  555. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  556. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  557. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  558. }
  559. void NRF24L01_RX_SZML_CONFIG(SPIType spiNum)
  560. {
  561. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  562. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)SU_ZHOU_MU_LANG,4);//写RX节点地址
  563. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)SU_ZHOU_MU_LANG,4);//写TX节点地址
  564. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  565. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  566. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  567. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  568. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  569. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,8);//选择通道0的有效数据宽度
  570. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  571. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  572. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  573. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  574. }
  575. void NRF24L01_RX_CQYD_CONFIG(SPIType spiNum)
  576. {
  577. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  578. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)CHONG_QIN_YI_DONG,4);//写RX节点地址
  579. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)CHONG_QIN_YI_DONG,4);//写TX节点地址
  580. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  581. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  582. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  583. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  584. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  585. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,0x08);//选择通道0的有效数据宽度
  586. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  587. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  588. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  589. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  590. }
  591. void NRF24L01_RX_SXYD_CONFIG(SPIType spiNum)
  592. {
  593. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  594. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)SHAN_XI_YI_DONG,4);//写RX节点地址
  595. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)SHAN_XI_YI_DONG,4);//写TX节点地址
  596. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  597. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  598. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,20); //设置RF通信频率
  599. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  600. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  601. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,0x0A);//选择通道0的有效数据宽度
  602. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  603. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  604. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  605. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  606. }
  607. void NRF24L01_RX_GSYD_CONFIG(SPIType spiNum)
  608. {
  609. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  610. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)GAN_SU_YI_DONG,4);//写RX节点地址
  611. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)GAN_SU_YI_DONG,4);//写TX节点地址
  612. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  613. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  614. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,22); //设置RF通信频率
  615. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  616. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  617. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,0x08);//选择通道0的有效数据宽度
  618. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  619. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  620. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  621. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  622. }
  623. void NRF24L01_RX_XDF_CONFIG(SPIType spiNum)
  624. {
  625. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --4字节
  626. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)XDF,3);//写RX节点地址
  627. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)XDF,3);//写TX节点地址
  628. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  629. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  630. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,50); //设置RF通信频率
  631. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  632. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0F);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  633. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,16);//选择通道0的有效数据宽度
  634. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  635. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  636. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  637. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  638. }
  639. void NRF24L01_RX_DH_CONFIG(SPIType spiNum)
  640. {
  641. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  642. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)DH,4);//写RX节点地址
  643. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)DH,4);//写TX节点地址
  644. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  645. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  646. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,51); //设置RF通信频率
  647. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x07);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  648. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0F);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  649. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,5);//选择通道0的有效数据宽度
  650. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  651. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  652. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  653. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  654. }
  655. void NRF24L01_RX_AHDX_CONFIG(SPIType spiNum)
  656. {
  657. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  658. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)ANHUI_DIANXIN,4);//写RX节点地址
  659. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)ANHUI_DIANXIN,4);//写TX节点地址
  660. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x3f); //使能通道0的自动应答
  661. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x3f);//使能通道0的接收地址
  662. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,28); //设置RF通信频率
  663. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x04);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  664. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0F);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  665. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  666. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x01);
  667. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x00); /// P0
  668. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  669. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  670. }
  671. #endif
  672. #if APP
  673. void NRF24L01_RX_Mode_NOACK(SPIType spiNum,u8 num)
  674. {
  675. if(spiNum == SPI_PORT1){
  676. SPI1_CE =0;
  677. }else{
  678. SPI2_CE=0;
  679. }
  680. switch(num)
  681. {
  682. case 0:
  683. NRF24L01_RX_JiangXi_CONFIG(spiNum); //江西协议
  684. break;
  685. case 1:
  686. NRF24L01_RX_TelPo_CONFIG(spiNum); //天波协议
  687. break;
  688. case 2:
  689. NRF24L01_RX_YunNan_CONFIG(spiNum); //云南协议
  690. break;
  691. case 3:
  692. NRF24L01_RX_GuiZhou_CONFIG(spiNum); //贵州协议
  693. break;
  694. case 4:
  695. NRF24L01_RX_SiChuan_CONFIG(spiNum); //四川协议
  696. break;
  697. case 5:
  698. NRF24L01_RX_NeiMengGu_CONFIG(spiNum); //内蒙古协议
  699. break;
  700. case 6:
  701. NRF24L01_RX_AnHui_CONFIG(spiNum); //安徽协议
  702. break;
  703. case 7:
  704. NRF24L01_RX_ShanXiXinNuo_CONFIG(spiNum); //山西协议
  705. break;
  706. case 8:
  707. NRF24L01_RX_VCM_CONFIG(spiNum); //威科姆协议
  708. break;
  709. case 9:
  710. NRF24L01_RX_LIAO_NING_CONFIG(spiNum); //辽宁电信协议
  711. break;
  712. case 10:
  713. NRF24L01_RX_NEW_LIAO_NING_CONFIG(spiNum); //辽宁移动协议
  714. break;
  715. case 11:
  716. NRF24L01_RX_TP_CONFIG(spiNum); //TP专用协议
  717. break;
  718. case 12:
  719. NRF24L01_RX_NMGYD_CONFIG(spiNum); //内蒙古移动专用协议
  720. break;
  721. case 13:
  722. NRF24L01_RX_GXYD_CONFIG(spiNum); //广西移动专用协议
  723. break;
  724. case 14:
  725. NRF24L01_RX_LIAO_NING_CONFIG(spiNum); //辽宁电信-四川电信专用协议
  726. break;
  727. case 15:
  728. NRF24L01_RX_FJZZ_CONFIG(spiNum); //福建真灼专用协议
  729. break;
  730. case 16:
  731. NRF24L01_RX_SZML_CONFIG(spiNum); //苏州木兰专用协议
  732. break;
  733. case 17:
  734. NRF24L01_RX_CQYD_CONFIG(spiNum); //重庆移动专用协议
  735. break;
  736. case 18:
  737. NRF24L01_RX_SXYD_CONFIG(spiNum); //山西移动专用协议
  738. break;
  739. case 19:
  740. NRF24L01_RX_GSYD_CONFIG(spiNum); //山西移动专用协议
  741. break;
  742. case 20:
  743. NRF24L01_RX_XDF_CONFIG(spiNum); //信达丰专用协议
  744. break;
  745. case 21:
  746. NRF24L01_RX_DH_CONFIG(spiNum); //德海专用协议
  747. break;
  748. case 22:
  749. NRF24L01_RX_AHDX_CONFIG(spiNum); //安徽电信协议
  750. break;
  751. }
  752. if(spiNum == SPI_PORT1){ //CE为高,进入接收模式
  753. SPI1_CE =1;
  754. }else{
  755. SPI2_CE=1;
  756. }
  757. }
  758. #else
  759. void NRF24L01_RX_Mode_NOACK(SPIType spiNum)
  760. {
  761. if(spiNum == SPI_PORT1){
  762. SPI1_CE =0;
  763. }else{
  764. SPI2_CE=0;
  765. }
  766. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x02);//地址宽度 --4字节
  767. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)addr,5);//写RX节点地址
  768. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)addr,5);//写TX节点地址
  769. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30); //使能通道0的自动应答
  770. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址
  771. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,18); //设置RF通信频率
  772. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x24);//设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  773. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式
  774. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RX_PW_P0,10);//选择通道0的有效数据宽度
  775. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+FEATURF,0x00);
  776. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+DYNPD,0x01); /// P0
  777. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+STATUS,0x70); //清除TX_DS或MAX_RT中断标志
  778. NRF24L01_Write_Reg(spiNum,FLUSH_RX,0xff); //清除RX FIFO寄存器
  779. if(spiNum == SPI_PORT1){ //CE为高,进入接收模式
  780. SPI1_CE =1;
  781. }else{
  782. SPI2_CE=1;
  783. }
  784. }
  785. #endif
  786. //该函数初始化NRF24L01到TX模式
  787. //设置TX地址,写TX数据宽度,设置RX自动应答的地址,填充TX发送数据,选择RF频道,波特率和LNA HCURR
  788. //PWR_UP,CRC使能
  789. //当CE变高后,即进入RX模式,并可以接收数据了
  790. //CE为高大于10us,则启动发送.
  791. void NRF24L01_TX_Mode(SPIType spiNum)
  792. {
  793. if(spiNum == SPI_PORT1){
  794. SPI1_CE =0;
  795. }else{
  796. SPI2_CE=0;
  797. }
  798. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x01);//地址宽度 --3字节
  799. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)TX_ADDRESS,TX_ADR_WIDTH);//写TX节点地址
  800. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH); //设置TX节点地址,主要为了使能ACK
  801. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x01); //使能通道0的自动应答
  802. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0x01); //使能通道0的接收地址
  803. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_RETR,0x1a);//设置自动重发间隔时间:500us + 86us;最大自动重发次数:10次
  804. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_CH,42); //设置RF通道为40
  805. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+RF_SETUP,0x00); //设置TX发射参数,0db增益,1Mbps,低噪声增益开启
  806. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+CONFIG,0x0e); //配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式,开启所有中断
  807. //CE为高,10us后启动发
  808. if(spiNum == SPI_PORT1){
  809. SPI1_CE =1;
  810. }else{
  811. SPI2_CE=1;
  812. }
  813. }
  814. void RF24_CarrierTest(SPIType spiNum,unsigned char rf_channel)
  815. {
  816. unsigned char txAddr[32];
  817. unsigned char cnt;
  818. for(cnt=0;cnt<32;cnt++) txAddr[cnt] = 0xff;
  819. if(spiNum == SPI_PORT1){
  820. SPI1_CE =0;
  821. }else{
  822. SPI2_CE=0;
  823. }
  824. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+ STATUS, 0x70);
  825. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+ CONFIG, 0x72); // RF??????′??÷£??????ù±?1¤×÷2?êy£?TX_DS ?a, power up£? CRC16£?·¢é??£ê?
  826. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_AA,0x30);
  827. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+EN_RXADDR,0);
  828. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_RETR,0);
  829. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG +RF_SETUP,0x90+00); // ??2¨2aê?£?éè??·¢é?1|?ê:1dBm, ?ù?ê:1Mbps
  830. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG+SETUP_AW,0x03);
  831. NRF24L01_Write_Buf(spiNum,NRF_WRITE_REG+TX_ADDR,(u8*)NEW_LIAO_NING,5);
  832. NRF24L01_Write_Buf(spiNum,WR_TX_PLOAD,txAddr,32);
  833. NRF24L01_Write_Reg(spiNum,NRF_WRITE_REG + RF_CH, rf_channel); // ???????ú·¢é??μμà
  834. if(spiNum == SPI_PORT1){
  835. SPI1_CE =1;
  836. }else{
  837. SPI2_CE=1;
  838. }
  839. delay_5us(60); // ±?òaμ??óê±300us
  840. }