説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

nrf24l01.h 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef NRF24L01_H
  2. #define NRF24L01_H
  3. #define PACKET_BUFFER_LENGTH 22
  4. /* AVR I/O pin definionts */
  5. #define NRF_CE_DDR DDRD
  6. #define NRF_CE_PORT PORTD
  7. #define NRF_CE_PIN PD7
  8. #define NRF_CSN_DDR DDRD
  9. #define NRF_CSN_PORT PORTD
  10. #define NRF_CSN_PIN PD6
  11. #define NRF_IRQ_DDR DDRD
  12. #define NRF_IRQ_PORT PORTD
  13. #define NRF_IRQ_PIN PD5
  14. #define NRF_IRQ_PORTIN PIND
  15. void Initialize_NRF24L01(void);
  16. void Set_NRF24L01_Pins(void);
  17. void Configure_Transmission(uint8_t moduleId);
  18. uint8_t Read_NRF_Status_Register(void);
  19. uint8_t Read_NRF_Register(uint8_t address, uint8_t * registerContents);
  20. void Write_NRF_Register(uint8_t address, uint8_t registerContents);
  21. void Send_Activate_Command(void);
  22. void NRF24L01_Send_Message(uint8_t *buffer, uint8_t length);
  23. void Write_Message_To_TX_FIFO(uint8_t length, uint8_t * buffer);
  24. void Set_TX_Address(uint8_t * txAddress, uint8_t length);
  25. void Set_RX_P0_Address(uint8_t * rxAddress, uint8_t length);
  26. typedef enum
  27. {
  28. PACKET_TYPE_SALT = 0,
  29. PACKET_TYPE_REPORT = 1,
  30. PACKET_TYPE_GET_VALUES = 2,
  31. PACKET_TYPE_VALUES = 3,
  32. } PACKET_TYPE;
  33. typedef enum
  34. {
  35. VALUE_TYPE_TIME = 0,
  36. VALUE_TYPE_TEMPERATURE = 1,
  37. VALUE_TYPE_PRESSURE = 2,
  38. VALUE_TYPE_HUMIDITY = 3,
  39. } VALUE_TYPES;
  40. typedef struct __attribute__((packed)) BITFIELD_PACKET_COUNT_ELEMENT
  41. {
  42. uint8_t packetType : 5;
  43. uint8_t elementCount : 3;
  44. } BITFIELD_PACKET_COUNT_ELEMENT;
  45. typedef struct __attribute__((packed)) PACKET
  46. {
  47. uint64_t salt; /* 1 byte device id, 7 bytes remainder */
  48. union {
  49. struct {
  50. BITFIELD_PACKET_COUNT_ELEMENT packetIdentifier;
  51. uint8_t valueTypeTemperature;
  52. int16_t temperature;
  53. uint8_t valueTypePressure;
  54. uint32_t pressure;
  55. uint8_t valueTypeHumidity;
  56. uint16_t humidity;
  57. uint8_t unused[10];
  58. } values;
  59. uint8_t buffer[PACKET_BUFFER_LENGTH];
  60. }payload;
  61. uint16_t crc;
  62. } PACKET;
  63. #endif