Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifndef _NRF24L01_H
  2. #define _NRF24L01_H
  3. #include "stm32f10x.h"
  4. #include "nrf_gpio.h"
  5. #include "printf.h"
  6. //NRF24L01Ĵ
  7. #define NRF_READ_REG 0x00 //üĴ,5λΪĴַ
  8. #define NRF_WRITE_REG 0x20 //дüĴ,5λΪĴַ
  9. #define RD_RX_PLOAD 0x61 //RXЧ,1~32ֽ
  10. #define WR_TX_PLOAD 0xA0 //дTXЧ,1~32ֽ
  11. #define FLUSH_TX 0xE1 //TX FIFOĴ.ģʽ
  12. #define FLUSH_RX 0xE2 //RX FIFOĴ.ģʽ
  13. #define REUSE_TX_PL 0xE3 //ʹһ,CEΪ,ݰϷ.
  14. #define NOP 0xFF //ղ,״̬Ĵ
  15. //SPI(NRF24L01)Ĵַ
  16. #define CONFIG 0x00 //üĴַ;bit0:1ģʽ,0ģʽ;bit1:ѡ;bit2:CRCģʽ;bit3:CRCʹ;
  17. //bit4:жMAX_RT(ﵽطж)ʹ;bit5:жTX_DSʹ;bit6:жRX_DRʹ
  18. #define EN_AA 0x01 //ʹԶӦ bit0~5,Ӧͨ0~5
  19. #define EN_RXADDR 0x02 //յַ,bit0~5,Ӧͨ0~5
  20. #define SETUP_AW 0x03 //õַ(ͨ):bit1,0:00,3ֽ;01,4ֽ;02,5ֽ;
  21. #define SETUP_RETR 0x04 //Զط;bit3:0,Զط;bit7:4,Զطʱ 250*x+86us
  22. #define RF_CH 0x05 //RFͨ,bit6:0,ͨƵ;
  23. #define RF_SETUP 0x06 //RFĴ;bit3:(0:1Mbps,1:2Mbps);bit2:1,书;bit0:Ŵ
  24. #define STATUS 0x07 //״̬Ĵ;bit0:TX FIFO־;bit3:1,ͨ(:6);bit4,ﵽط
  25. //bit5:ݷж;bit6:ж;
  26. #define MAX_TX 0x10 //ﵽʹж
  27. #define TX_OK 0x20 //TXж
  28. #define RX_OK 0x40 //յж
  29. #define OBSERVE_TX 0x08 //ͼĴ,bit7:4,ݰʧ;bit3:0,ط
  30. #define CD 0x09 //زĴ,bit0,ز;
  31. #define RX_ADDR_P0 0x0A //ͨ0յַ,󳤶5ֽ,ֽǰ
  32. #define RX_ADDR_P1 0x0B //ͨ1յַ,󳤶5ֽ,ֽǰ
  33. #define RX_ADDR_P2 0x0C //ͨ2յַ,ֽڿ,ֽ,ͬRX_ADDR_P1[39:8];
  34. #define RX_ADDR_P3 0x0D //ͨ3յַ,ֽڿ,ֽ,ͬRX_ADDR_P1[39:8];
  35. #define RX_ADDR_P4 0x0E //ͨ4յַ,ֽڿ,ֽ,ͬRX_ADDR_P1[39:8];
  36. #define RX_ADDR_P5 0x0F //ͨ5յַ,ֽڿ,ֽ,ͬRX_ADDR_P1[39:8];
  37. #define TX_ADDR 0x10 //͵ַ(ֽǰ),ShockBurstTMģʽ,RX_ADDR_P0˵ַ
  38. #define RX_PW_P0 0x11 //ͨ0Чݿ(1~32ֽ),Ϊ0Ƿ
  39. #define RX_PW_P1 0x12 //ͨ1Чݿ(1~32ֽ),Ϊ0Ƿ
  40. #define RX_PW_P2 0x13 //ͨ2Чݿ(1~32ֽ),Ϊ0Ƿ
  41. #define RX_PW_P3 0x14 //ͨ3Чݿ(1~32ֽ),Ϊ0Ƿ
  42. #define RX_PW_P4 0x15 //ͨ4Чݿ(1~32ֽ),Ϊ0Ƿ
  43. #define RX_PW_P5 0x16 //ͨ5Чݿ(1~32ֽ),Ϊ0Ƿ
  44. #define NRF_FIFO_STATUS 0x17 //FIFO״̬Ĵ;bit0,RX FIFOĴձ־;bit1,RX FIFO־;bit2,3,
  45. //bit4,TX FIFOձ־;bit5,TX FIFO־;bit6,1,ѭһݰ.0,ѭ;
  46. #define W_ACK_PAYLOAD 0xA8 /// ACK
  47. #define W_TX_PAYLOAD_NO_ACK 0xA0 /// NO ACK
  48. #define DYNPD 0x1C
  49. #define FEATURF 0x1D
  50. #define R_RX_PL_WID 0x60
  51. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  52. //24L01ͽݿȶ
  53. #define TX_ADR_WIDTH 3 //5ֽڵĵַ
  54. #define RX_ADR_WIDTH 3 //5ֽڵĵַ
  55. #define TX_PLOAD_WIDTH 7 //32ֽڵûݿ
  56. #define RX_PLOAD_WIDTH 10 //32ֽڵûݿ
  57. //-----------------------------------------------------------
  58. // Functions
  59. void NRF24L01_Init(void); //ʼ
  60. void NRF24L01_RX_Mode(SPIType spiNum); //Ϊģʽ
  61. void NRF24L01_TX_Mode(SPIType spiNum); //Ϊģʽ
  62. #if APP
  63. void NRF24L01_RX_Mode_NOACK(SPIType spiNum,u8 num); //
  64. #else
  65. void NRF24L01_RX_Mode_NOACK(SPIType spiNum); //
  66. #endif
  67. //void NRF24L01_RX_Mode_NOACK(SPIType spiNum); //
  68. void NRF24L01_RX_Mode_NOACK_VCOM(SPIType spiNum); //VCOM
  69. u8 NRF24L01_Write_Buf(SPIType spiNum,u8 reg, u8 *pBuf, u8 u8s);//д
  70. u8 NRF24L01_Read_Buf(SPIType spiNum,u8 reg, u8 *pBuf, u8 u8s); //
  71. u8 NRF24L01_Read_Reg(SPIType spiNum,u8 reg); //Ĵ
  72. u8 NRF24L01_Write_Reg(SPIType spiNum,u8 reg, u8 value); //дĴ
  73. u8 NRF24L01_Check(SPIType spiNum); //24L01Ƿ
  74. u8 NRF24L01_TxPacket(SPIType spiNum,u8 *txbuf); //һ
  75. u8 NRF24L01_RxPacket(SPIType spiNum,u8 *rxbuf); //һ
  76. void RF24_CarrierTest(SPIType spiNum,unsigned char rf_channel);
  77. #define SPI_REV SPI_PORT1
  78. #define SPI_SEND SPI_PORT2
  79. #endif