PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

1101 líneas
60KB

  1. // RH_RF24.h
  2. // Author: Mike McCauley (mikem@airspayce.com)
  3. // Copyright (C) 2014 Mike McCauley
  4. // $Id: RH_RF24.h,v 1.14 2015/12/11 01:10:24 mikem Exp $
  5. //
  6. // Supports RF24/RF26 and RFM24/RFM26 modules in FIFO mode
  7. // also Si4464/63/62/61/60-A1
  8. // Si4063 is the same but Tx only
  9. //
  10. // Per http://www.hoperf.cn/upload/rf/RFM24.pdf
  11. // and http://www.hoperf.cn/upload/rf/RFM26.pdf
  12. // Sigh: the HopeRF documentation is utter rubbish: full of errors and incomplete. The Si446x docs are better:
  13. // http://www.silabs.com/Support%20Documents/TechnicalDocs/Si4464-63-61-60.pdf
  14. // http://www.silabs.com/Support%20Documents/TechnicalDocs/AN626.pdf
  15. // http://www.silabs.com/Support%20Documents/TechnicalDocs/AN627.pdf
  16. // http://www.silabs.com/Support%20Documents/TechnicalDocs/AN647.pdf
  17. // http://www.silabs.com/Support%20Documents/TechnicalDocs/AN633.pdf
  18. // http://www.silabs.com/Support%20Documents/TechnicalDocs/AN736.pdf
  19. // http://nicerf.com/manage/upfile/indexbanner/635231050196868750.pdf (API description)
  20. // http://www.silabs.com/Support%20Documents/Software/Si446x%20RX_HOP%20PLL%20Calculator.xlsx
  21. #ifndef RH_RF24_h
  22. #define RH_RF24_h
  23. #include <RHGenericSPI.h>
  24. #include <RHSPIDriver.h>
  25. // This is the maximum number of interrupts the driver can support
  26. // Most Arduinos can handle 2, Megas can handle more
  27. #define RH_RF24_NUM_INTERRUPTS 3
  28. // Maximum payload length the RF24 can support, limited by our 1 octet message length
  29. #define RH_RF24_MAX_PAYLOAD_LEN 255
  30. // The length of the headers we add.
  31. // The headers are inside the RF24's payload
  32. #define RH_RF24_HEADER_LEN 4
  33. // This is the maximum message length that can be supported by this driver.
  34. // Can be pre-defined to a smaller size (to save SRAM) prior to including this header
  35. // Here we allow for message length 4 bytes of address and header and payload to be included in payload size limit.
  36. #ifndef RH_RF24_MAX_MESSAGE_LEN
  37. #define RH_RF24_MAX_MESSAGE_LEN (RH_RF24_MAX_PAYLOAD_LEN - RH_RF24_HEADER_LEN - 1)
  38. #endif
  39. // Max number of times we will try to read CTS from the radio
  40. #define RH_RF24_CTS_RETRIES 2500
  41. // RF24/RF26 API commands from table 10
  42. // also Si446X API DESCRIPTIONS table 1
  43. #define RH_RF24_CMD_NOP 0x00
  44. #define RH_RF24_CMD_PART_INFO 0x01
  45. #define RH_RF24_CMD_POWER_UP 0x02
  46. #define RH_RF24_CMD_PATCH_IMAGE 0x04
  47. #define RH_RF24_CMD_FUNC_INFO 0x10
  48. #define RH_RF24_CMD_SET_PROPERTY 0x11
  49. #define RH_RF24_CMD_GET_PROPERTY 0x12
  50. #define RH_RF24_CMD_GPIO_PIN_CFG 0x13
  51. #define RH_RF24_CMD_GET_ADC_READING 0x14
  52. #define RH_RF24_CMD_FIFO_INFO 0x15
  53. #define RH_RF24_CMD_PACKET_INFO 0x16
  54. #define RH_RF24_CMD_IRCAL 0x17
  55. #define RH_RF24_CMD_PROTOCOL_CFG 0x18
  56. #define RH_RF24_CMD_GET_INT_STATUS 0x20
  57. #define RH_RF24_CMD_GET_PH_STATUS 0x21
  58. #define RH_RF24_CMD_GET_MODEM_STATUS 0x22
  59. #define RH_RF24_CMD_GET_CHIP_STATUS 0x23
  60. #define RH_RF24_CMD_START_TX 0x31
  61. #define RH_RF24_CMD_START_RX 0x32
  62. #define RH_RF24_CMD_REQUEST_DEVICE_STATE 0x33
  63. #define RH_RF24_CMD_CHANGE_STATE 0x34
  64. #define RH_RF24_CMD_RX_HOP 0x36
  65. #define RH_RF24_CMD_READ_BUF 0x44
  66. #define RH_RF24_CMD_FAST_RESPONSE_A 0x50
  67. #define RH_RF24_CMD_FAST_RESPONSE_B 0x51
  68. #define RH_RF24_CMD_FAST_RESPONSE_C 0x53
  69. #define RH_RF24_CMD_FAST_RESPONSE_D 0x57
  70. #define RH_RF24_CMD_TX_FIFO_WRITE 0x66
  71. #define RH_RF24_CMD_RX_FIFO_READ 0x77
  72. // The Clear To Send signal from the radio
  73. #define RH_RF24_REPLY_CTS 0xff
  74. //#define RH_RF24_CMD_START_TX 0x31
  75. #define RH_RF24_CONDITION_TX_COMPLETE_STATE 0xf0
  76. #define RH_RF24_CONDITION_RETRANSMIT_NO 0x00
  77. #define RH_RF24_CONDITION_RETRANSMIT_YES 0x04
  78. #define RH_RF24_CONDITION_START_IMMEDIATE 0x00
  79. #define RH_RF24_CONDITION_START_AFTER_WUT 0x01
  80. //#define RH_RF24_CMD_START_RX 0x32
  81. #define RH_RF24_CONDITION_RX_START_IMMEDIATE 0x00
  82. //#define RH_RF24_CMD_REQUEST_DEVICE_STATE 0x33
  83. #define RH_RF24_DEVICE_STATE_NO_CHANGE 0x00
  84. #define RH_RF24_DEVICE_STATE_SLEEP 0x01
  85. #define RH_RF24_DEVICE_STATE_SPI_ACTIVE 0x02
  86. #define RH_RF24_DEVICE_STATE_READY 0x03
  87. #define RH_RF24_DEVICE_STATE_ALSO_READY 0x04
  88. #define RH_RF24_DEVICE_STATE_TUNE_TX 0x05
  89. #define RH_RF24_DEVICE_STATE_TUNE_RX 0x06
  90. #define RH_RF24_DEVICE_STATE_TX 0x07
  91. #define RH_RF24_DEVICE_STATE_RX 0x08
  92. // Properties for API Description AN625 Section 2.2
  93. #define RH_RF24_PROPERTY_GLOBAL_XO_TUNE 0x0000
  94. #define RH_RF24_PROPERTY_GLOBAL_CLK_CFG 0x0001
  95. #define RH_RF24_PROPERTY_GLOBAL_LOW_BATT_THRESH 0x0002
  96. #define RH_RF24_PROPERTY_GLOBAL_CONFIG 0x0003
  97. #define RH_RF24_PROPERTY_GLOBAL_WUT_CONFIG 0x0004
  98. #define RH_RF24_PROPERTY_GLOBAL_WUT_M_15_8 0x0005
  99. #define RH_RF24_PROPERTY_GLOBAL_WUT_M_7_0 0x0006
  100. #define RH_RF24_PROPERTY_GLOBAL_WUT_R 0x0007
  101. #define RH_RF24_PROPERTY_GLOBAL_WUT_LDC 0x0008
  102. #define RH_RF24_PROPERTY_INT_CTL_ENABLE 0x0100
  103. #define RH_RF24_PROPERTY_INT_CTL_PH_ENABLE 0x0101
  104. #define RH_RF24_PROPERTY_INT_CTL_MODEM_ENABLE 0x0102
  105. #define RH_RF24_PROPERTY_INT_CTL_CHIP_ENABLE 0x0103
  106. #define RH_RF24_PROPERTY_FRR_CTL_A_MODE 0x0200
  107. #define RH_RF24_PROPERTY_FRR_CTL_B_MODE 0x0201
  108. #define RH_RF24_PROPERTY_FRR_CTL_C_MODE 0x0202
  109. #define RH_RF24_PROPERTY_FRR_CTL_D_MODE 0x0203
  110. #define RH_RF24_PROPERTY_PREAMBLE_TX_LENGTH 0x1000
  111. #define RH_RF24_PROPERTY_PREAMBLE_CONFIG_STD_1 0x1001
  112. #define RH_RF24_PROPERTY_PREAMBLE_CONFIG_NSTD 0x1002
  113. #define RH_RF24_PROPERTY_PREAMBLE_CONFIG_STD_2 0x1003
  114. #define RH_RF24_PROPERTY_PREAMBLE_CONFIG 0x1004
  115. #define RH_RF24_PROPERTY_PREAMBLE_PATTERN_31_24 0x1005
  116. #define RH_RF24_PROPERTY_PREAMBLE_PATTERN_23_16 0x1006
  117. #define RH_RF24_PROPERTY_PREAMBLE_PATTERN_15_8 0x1007
  118. #define RH_RF24_PROPERTY_PREAMBLE_PATTERN_7_0 0x1008
  119. #define RH_RF24_PROPERTY_SYNC_CONFIG 0x1100
  120. #define RH_RF24_PROPERTY_SYNC_BITS_31_24 0x1101
  121. #define RH_RF24_PROPERTY_SYNC_BITS_23_16 0x1102
  122. #define RH_RF24_PROPERTY_SYNC_BITS_15_8 0x1103
  123. #define RH_RF24_PROPERTY_SYNC_BITS_7_0 0x1104
  124. #define RH_RF24_PROPERTY_PKT_CRC_CONFIG 0x1200
  125. #define RH_RF24_PROPERTY_PKT_CONFIG1 0x1206
  126. #define RH_RF24_PROPERTY_PKT_LEN 0x1208
  127. #define RH_RF24_PROPERTY_PKT_LEN_FIELD_SOURCE 0x1209
  128. #define RH_RF24_PROPERTY_PKT_LEN_ADJUST 0x120a
  129. #define RH_RF24_PROPERTY_PKT_TX_THRESHOLD 0x120b
  130. #define RH_RF24_PROPERTY_PKT_RX_THRESHOLD 0x120c
  131. #define RH_RF24_PROPERTY_PKT_FIELD_1_LENGTH_12_8 0x120d
  132. #define RH_RF24_PROPERTY_PKT_FIELD_1_LENGTH_7_0 0x120e
  133. #define RH_RF24_PROPERTY_PKT_FIELD_1_CONFIG 0x120f
  134. #define RH_RF24_PROPERTY_PKT_FIELD_1_CRC_CONFIG 0x1210
  135. #define RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_12_8 0x1211
  136. #define RH_RF24_PROPERTY_PKT_FIELD_2_LENGTH_7_0 0x1212
  137. #define RH_RF24_PROPERTY_PKT_FIELD_2_CONFIG 0x1213
  138. #define RH_RF24_PROPERTY_PKT_FIELD_2_CRC_CONFIG 0x1214
  139. #define RH_RF24_PROPERTY_PKT_FIELD_3_LENGTH_12_8 0x1215
  140. #define RH_RF24_PROPERTY_PKT_FIELD_3_LENGTH_7_0 0x1216
  141. #define RH_RF24_PROPERTY_PKT_FIELD_3_CONFIG 0x1217
  142. #define RH_RF24_PROPERTY_PKT_FIELD_3_CRC_CONFIG 0x1218
  143. #define RH_RF24_PROPERTY_PKT_FIELD_4_LENGTH_12_8 0x1219
  144. #define RH_RF24_PROPERTY_PKT_FIELD_4_LENGTH_7_0 0x121a
  145. #define RH_RF24_PROPERTY_PKT_FIELD_4_CONFIG 0x121b
  146. #define RH_RF24_PROPERTY_PKT_FIELD_4_CRC_CONFIG 0x121c
  147. #define RH_RF24_PROPERTY_PKT_FIELD_5_LENGTH_12_8 0x121d
  148. #define RH_RF24_PROPERTY_PKT_FIELD_5_LENGTH_7_0 0x121e
  149. #define RH_RF24_PROPERTY_PKT_FIELD_5_CONFIG 0x121f
  150. #define RH_RF24_PROPERTY_PKT_FIELD_5_CRC_CONFIG 0x1220
  151. #define RH_RF24_PROPERTY_PKT_RX_FIELD_1_LENGTH_12_8 0x1221
  152. #define RH_RF24_PROPERTY_PKT_RX_FIELD_1_LENGTH_7_0 0x1222
  153. #define RH_RF24_PROPERTY_PKT_RX_FIELD_1_CONFIG 0x1223
  154. #define RH_RF24_PROPERTY_PKT_RX_FIELD_1_CRC_CONFIG 0x1224
  155. #define RH_RF24_PROPERTY_PKT_RX_FIELD_2_LENGTH_12_8 0x1225
  156. #define RH_RF24_PROPERTY_PKT_RX_FIELD_2_LENGTH_7_0 0x1226
  157. #define RH_RF24_PROPERTY_PKT_RX_FIELD_2_CONFIG 0x1227
  158. #define RH_RF24_PROPERTY_PKT_RX_FIELD_2_CRC_CONFIG 0x1228
  159. #define RH_RF24_PROPERTY_PKT_RX_FIELD_3_LENGTH_12_8 0x1229
  160. #define RH_RF24_PROPERTY_PKT_RX_FIELD_3_LENGTH_7_0 0x122a
  161. #define RH_RF24_PROPERTY_PKT_RX_FIELD_3_CONFIG 0x122b
  162. #define RH_RF24_PROPERTY_PKT_RX_FIELD_3_CRC_CONFIG 0x122c
  163. #define RH_RF24_PROPERTY_PKT_RX_FIELD_4_LENGTH_12_8 0x122d
  164. #define RH_RF24_PROPERTY_PKT_RX_FIELD_4_LENGTH_7_0 0x122e
  165. #define RH_RF24_PROPERTY_PKT_RX_FIELD_4_CONFIG 0x122f
  166. #define RH_RF24_PROPERTY_PKT_RX_FIELD_4_CRC_CONFIG 0x1230
  167. #define RH_RF24_PROPERTY_PKT_RX_FIELD_5_LENGTH_12_8 0x1231
  168. #define RH_RF24_PROPERTY_PKT_RX_FIELD_5_LENGTH_7_0 0x1232
  169. #define RH_RF24_PROPERTY_PKT_RX_FIELD_5_CONFIG 0x1233
  170. #define RH_RF24_PROPERTY_PKT_RX_FIELD_5_CRC_CONFIG 0x1234
  171. #define RH_RF24_PROPERTY_MODEM_MOD_TYPE 0x2000
  172. #define RH_RF24_PROPERTY_MODEM_MAP_CONTROL 0x2001
  173. #define RH_RF24_PROPERTY_MODEM_DSM_CTRL 0x2002
  174. #define RH_RF24_PROPERTY_MODEM_DATA_RATE_2 0x2003
  175. #define RH_RF24_PROPERTY_MODEM_DATA_RATE_1 0x2004
  176. #define RH_RF24_PROPERTY_MODEM_DATA_RATE_0 0x2005
  177. #define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_3 0x2006
  178. #define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_2 0x2007
  179. #define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_1 0x2008
  180. #define RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_0 0x2009
  181. #define RH_RF24_PROPERTY_MODEM_FREQ_DEV_2 0x200a
  182. #define RH_RF24_PROPERTY_MODEM_FREQ_DEV_1 0x200b
  183. #define RH_RF24_PROPERTY_MODEM_FREQ_DEV_0 0x200c
  184. #define RH_RF24_PROPERTY_MODEM_TX_RAMP_DELAY 0x2018
  185. #define RH_RF24_PROPERTY_MODEM_MDM_CTRL 0x2019
  186. #define RH_RF24_PROPERTY_MODEM_IF_CONTROL 0x201a
  187. #define RH_RF24_PROPERTY_MODEM_IF_FREQ_2 0x201b
  188. #define RH_RF24_PROPERTY_MODEM_IF_FREQ_1 0x201c
  189. #define RH_RF24_PROPERTY_MODEM_IF_FREQ_0 0x201d
  190. #define RH_RF24_PROPERTY_MODEM_DECIMATION_CFG1 0x201e
  191. #define RH_RF24_PROPERTY_MODEM_DECIMATION_CFG0 0x201f
  192. #define RH_RF24_PROPERTY_MODEM_BCR_OSR_1 0x2022
  193. #define RH_RF24_PROPERTY_MODEM_BCR_OSR_0 0x2023
  194. #define RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_2 0x2024
  195. #define RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_1 0x2025
  196. #define RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_0 0x2026
  197. #define RH_RF24_PROPERTY_MODEM_BCR_GAIN_1 0x2027
  198. #define RH_RF24_PROPERTY_MODEM_BCR_GAIN_0 0x2028
  199. #define RH_RF24_PROPERTY_MODEM_BCR_GEAR 0x2029
  200. #define RH_RF24_PROPERTY_MODEM_BCR_MISC1 0x202a
  201. #define RH_RF24_PROPERTY_MODEM_AFC_GEAR 0x202c
  202. #define RH_RF24_PROPERTY_MODEM_AFC_WAIT 0x202d
  203. #define RH_RF24_PROPERTY_MODEM_AFC_GAIN_1 0x202e
  204. #define RH_RF24_PROPERTY_MODEM_AFC_GAIN_0 0x202f
  205. #define RH_RF24_PROPERTY_MODEM_AFC_LIMITER_1 0x2030
  206. #define RH_RF24_PROPERTY_MODEM_AFC_LIMITER_0 0x2031
  207. #define RH_RF24_PROPERTY_MODEM_AFC_MISC 0x2032
  208. #define RH_RF24_PROPERTY_MODEM_AGC_CONTROL 0x2035
  209. #define RH_RF24_PROPERTY_MODEM_AGC_WINDOW_SIZE 0x2038
  210. #define RH_RF24_PROPERTY_MODEM_AGC_RFPD_DECAY 0x2039
  211. #define RH_RF24_PROPERTY_MODEM_AGC_IFPD_DECAY 0x203a
  212. #define RH_RF24_PROPERTY_MODEM_FSK4_GAIN1 0x203b
  213. #define RH_RF24_PROPERTY_MODEM_FSK4_GAIN0 0x203c
  214. #define RH_RF24_PROPERTY_MODEM_FSK4_TH1 0x203d
  215. #define RH_RF24_PROPERTY_MODEM_FSK4_TH0 0x203e
  216. #define RH_RF24_PROPERTY_MODEM_FSK4_MAP 0x203f
  217. #define RH_RF24_PROPERTY_MODEM_OOK_PDTC 0x2040
  218. #define RH_RF24_PROPERTY_MODEM_OOK_CNT1 0x2042
  219. #define RH_RF24_PROPERTY_MODEM_OOK_MISC 0x2043
  220. #define RH_RF24_PROPERTY_MODEM_RAW_SEARCH 0x2044
  221. #define RH_RF24_PROPERTY_MODEM_RAW_CONTROL 0x2045
  222. #define RH_RF24_PROPERTY_MODEM_RAW_EYE_1 0x2046
  223. #define RH_RF24_PROPERTY_MODEM_RAW_EYE_0 0x2047
  224. #define RH_RF24_PROPERTY_MODEM_ANT_DIV_MODE 0x2048
  225. #define RH_RF24_PROPERTY_MODEM_ANT_DIV_CONTROL 0x2049
  226. #define RH_RF24_PROPERTY_MODEM_RSSI_THRESH 0x204a
  227. #define RH_RF24_PROPERTY_MODEM_RSSI_JUMP_THRESH 0x204b
  228. #define RH_RF24_PROPERTY_MODEM_RSSI_CONTROL 0x204c
  229. #define RH_RF24_PROPERTY_MODEM_RSSI_CONTROL2 0x204d
  230. #define RH_RF24_PROPERTY_MODEM_RSSI_COMP 0x204e
  231. #define RH_RF24_PROPERTY_MODEM_ANT_DIV_CONT 0x2049
  232. #define RH_RF24_PROPERTY_MODEM_CLKGEN_BAND 0x2051
  233. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE13_7_0 0x2100
  234. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE12_7_0 0x2101
  235. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE11_7_0 0x2102
  236. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE10_7_0 0x2103
  237. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE9_7_0 0x2104
  238. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE8_7_0 0x2105
  239. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE7_7_0 0x2106
  240. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE6_7_0 0x2107
  241. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE5_7_0 0x2108
  242. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE4_7_0 0x2109
  243. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE3_7_0 0x210a
  244. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE2_7_0 0x210b
  245. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE1_7_0 0x210c
  246. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE0_7_0 0x210d
  247. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM0 0x210e
  248. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM1 0x210f
  249. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM2 0x2110
  250. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM3 0x2111
  251. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE13_7_0 0x2112
  252. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE12_7_0 0x2113
  253. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE11_7_0 0x2114
  254. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE10_7_0 0x2115
  255. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE9_7_0 0x2116
  256. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE8_7_0 0x2117
  257. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE7_7_0 0x2118
  258. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE6_7_0 0x2119
  259. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE5_7_0 0x211a
  260. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE4_7_0 0x211b
  261. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE3_7_0 0x211c
  262. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE2_7_0 0x211d
  263. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE1_7_0 0x211e
  264. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE0_7_0 0x211f
  265. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM0 0x2120
  266. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM1 0x2121
  267. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM2 0x2122
  268. #define RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM3 0x2123
  269. #define RH_RF24_PROPERTY_PA_MODE 0x2200
  270. #define RH_RF24_PROPERTY_PA_PWR_LVL 0x2201
  271. #define RH_RF24_PROPERTY_PA_BIAS_CLKDUTY 0x2202
  272. #define RH_RF24_PROPERTY_PA_TC 0x2203
  273. #define RH_RF24_PROPERTY_SYNTH_PFDCP_CPFF 0x2300
  274. #define RH_RF24_PROPERTY_SYNTH_PFDCP_CPINT 0x2301
  275. #define RH_RF24_PROPERTY_SYNTH_VCO_KV 0x2302
  276. #define RH_RF24_PROPERTY_SYNTH_LPFILT3 0x2303
  277. #define RH_RF24_PROPERTY_SYNTH_LPFILT2 0x2304
  278. #define RH_RF24_PROPERTY_SYNTH_LPFILT1 0x2305
  279. #define RH_RF24_PROPERTY_SYNTH_LPFILT0 0x2306
  280. #define RH_RF24_PROPERTY_MATCH_VALUE_1 0x3000
  281. #define RH_RF24_PROPERTY_MATCH_MASK_1 0x3001
  282. #define RH_RF24_PROPERTY_MATCH_CTRL_1 0x3002
  283. #define RH_RF24_PROPERTY_MATCH_VALUE_2 0x3003
  284. #define RH_RF24_PROPERTY_MATCH_MASK_2 0x3004
  285. #define RH_RF24_PROPERTY_MATCH_CTRL_2 0x3005
  286. #define RH_RF24_PROPERTY_MATCH_VALUE_3 0x3006
  287. #define RH_RF24_PROPERTY_MATCH_MASK_3 0x3007
  288. #define RH_RF24_PROPERTY_MATCH_CTRL_3 0x3008
  289. #define RH_RF24_PROPERTY_MATCH_VALUE_4 0x3009
  290. #define RH_RF24_PROPERTY_MATCH_MASK_4 0x300a
  291. #define RH_RF24_PROPERTY_MATCH_CTRL_4 0x300b
  292. #define RH_RF24_PROPERTY_FREQ_CONTROL_INTE 0x4000
  293. #define RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_2 0x4001
  294. #define RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_1 0x4002
  295. #define RH_RF24_PROPERTY_FREQ_CONTROL_FRAC_0 0x4003
  296. #define RH_RF24_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_1 0x4004
  297. #define RH_RF24_PROPERTY_FREQ_CONTROL_CHANNEL_STEP_SIZE_0 0x4005
  298. #define RH_RF24_PROPERTY_FREQ_CONTROL_VCOCNT_RX_ADJ 0x4007
  299. #define RH_RF24_PROPERTY_RX_HOP_CONTROL 0x5000
  300. #define RH_RF24_PROPERTY_RX_HOP_TABLE_SIZE 0x5001
  301. #define RH_RF24_PROPERTY_RX_HOP_TABLE_ENTRY_0 0x5002
  302. //#define RH_RF24_CMD_GPIO_PIN_CFG 0x13
  303. #define RH_RF24_GPIO_NO_CHANGE 0
  304. #define RH_RF24_GPIO_DISABLED 1
  305. #define RH_RF24_GPIO_LOW 2
  306. #define RH_RF24_GPIO_HIGH 3
  307. #define RH_RF24_GPIO_INPUT 4
  308. #define RH_RF24_GPIO_32_KHZ_CLOCK 5
  309. #define RH_RF24_GPIO_BOOT_CLOCK 6
  310. #define RH_RF24_GPIO_DIVIDED_MCU_CLOCK 7
  311. #define RH_RF24_GPIO_CTS 8
  312. #define RH_RF24_GPIO_INV_CTS 9
  313. #define RH_RF24_GPIO_HIGH_ON_CMD_OVERLAP 10
  314. #define RH_RF24_GPIO_SPI_DATA_OUT 11
  315. #define RH_RF24_GPIO_HIGH_AFTER_RESET 12
  316. #define RH_RF24_GPIO_HIGH_AFTER_CALIBRATION 13
  317. #define RH_RF24_GPIO_HIGH_AFTER_WUT 14
  318. #define RH_RF24_GPIO_UNUSED_0 15
  319. #define RH_RF24_GPIO_TX_DATA_CLOCK 16
  320. #define RH_RF24_GPIO_RX_DATA_CLOCK 17
  321. #define RH_RF24_GPIO_UNUSED_1 18
  322. #define RH_RF24_GPIO_TX_DATA 19
  323. #define RH_RF24_GPIO_RX_DATA 20
  324. #define RH_RF24_GPIO_RX_RAW_DATA 21
  325. #define RH_RF24_GPIO_ANTENNA_1_SWITCH 22
  326. #define RH_RF24_GPIO_ANTENNA_2_SWITCH 23
  327. #define RH_RF24_GPIO_VALID_PREAMBLE 24
  328. #define RH_RF24_GPIO_INVALID_PREAMBLE 25
  329. #define RH_RF24_GPIO_SYNC_DETECTED 26
  330. #define RH_RF24_GPIO_RSSI_ABOVE_CAT 27
  331. #define RH_RF24_GPIO_TX_STATE 32
  332. #define RH_RF24_GPIO_RX_STATE 33
  333. #define RH_RF24_GPIO_RX_FIFO_ALMOST_FULL 34
  334. #define RH_RF24_GPIO_TX_FIFO_ALMOST_EMPTY 35
  335. #define RH_RF24_GPIO_BATT_LOW 36
  336. #define RH_RF24_GPIO_RSSI_ABOVE_CAT_LOW 37
  337. #define RH_RF24_GPIO_HOP 38
  338. #define RH_RF24_GPIO_HOP_TABLE_WRAPPED 39
  339. // #define RH_RF24_CMD_GET_INT_STATUS 0x20
  340. #define RH_RF24_INT_STATUS_CHIP_INT_STATUS 0x04
  341. #define RH_RF24_INT_STATUS_MODEM_INT_STATUS 0x02
  342. #define RH_RF24_INT_STATUS_PH_INT_STATUS 0x01
  343. #define RH_RF24_INT_STATUS_FILTER_MATCH 0x80
  344. #define RH_RF24_INT_STATUS_FILTER_MISS 0x40
  345. #define RH_RF24_INT_STATUS_PACKET_SENT 0x20
  346. #define RH_RF24_INT_STATUS_PACKET_RX 0x10
  347. #define RH_RF24_INT_STATUS_CRC_ERROR 0x08
  348. #define RH_RF24_INT_STATUS_TX_FIFO_ALMOST_EMPTY 0x02
  349. #define RH_RF24_INT_STATUS_RX_FIFO_ALMOST_FULL 0x01
  350. #define RH_RF24_INT_STATUS_INVALID_SYNC 0x20
  351. #define RH_RF24_INT_STATUS_RSSI_JUMP 0x10
  352. #define RH_RF24_INT_STATUS_RSSI 0x08
  353. #define RH_RF24_INT_STATUS_INVALID_PREAMBLE 0x04
  354. #define RH_RF24_INT_STATUS_PREAMBLE_DETECT 0x02
  355. #define RH_RF24_INT_STATUS_SYNC_DETECT 0x01
  356. #define RH_RF24_INT_STATUS_CAL 0x40
  357. #define RH_RF24_INT_STATUS_FIFO_UNDERFLOW_OVERFLOW_ERROR 0x20
  358. #define RH_RF24_INT_STATUS_STATE_CHANGE 0x10
  359. #define RH_RF24_INT_STATUS_CMD_ERROR 0x08
  360. #define RH_RF24_INT_STATUS_CHIP_READY 0x04
  361. #define RH_RF24_INT_STATUS_LOW_BATT 0x02
  362. #define RH_RF24_INT_STATUS_WUT 0x01
  363. //#define RH_RF24_PROPERTY_FRR_CTL_A_MODE 0x0200
  364. //#define RH_RF24_PROPERTY_FRR_CTL_B_MODE 0x0201
  365. //#define RH_RF24_PROPERTY_FRR_CTL_C_MODE 0x0202
  366. //#define RH_RF24_PROPERTY_FRR_CTL_D_MODE 0x0203
  367. #define RH_RF24_FRR_MODE_DISABLED 0
  368. #define RH_RF24_FRR_MODE_GLOBAL_STATUS 1
  369. #define RH_RF24_FRR_MODE_GLOBAL_INTERRUPT_PENDING 2
  370. #define RH_RF24_FRR_MODE_PACKET_HANDLER_STATUS 3
  371. #define RH_RF24_FRR_MODE_PACKET_HANDLER_INTERRUPT_PENDING 4
  372. #define RH_RF24_FRR_MODE_MODEM_STATUS 5
  373. #define RH_RF24_FRR_MODE_MODEM_INTERRUPT_PENDING 6
  374. #define RH_RF24_FRR_MODE_CHIP_STATUS 7
  375. #define RH_RF24_FRR_MODE_CHIP_INTERRUPT_PENDING 8
  376. #define RH_RF24_FRR_MODE_CURRENT_STATE 9
  377. #define RH_RF24_FRR_MODE_LATCHED_RSSI 10
  378. //#define RH_RF24_PROPERTY_INT_CTL_ENABLE 0x0100
  379. #define RH_RF24_CHIP_INT_STATUS_EN 0x04
  380. #define RH_RF24_MODEM_INT_STATUS_EN 0x02
  381. #define RH_RF24_PH_INT_STATUS_EN 0x01
  382. //#define RH_RF24_PROPERTY_PREAMBLE_CONFIG 0x1004
  383. #define RH_RF24_PREAMBLE_FIRST_1 0x20
  384. #define RH_RF24_PREAMBLE_FIRST_0 0x00
  385. #define RH_RF24_PREAMBLE_LENGTH_NIBBLES 0x00
  386. #define RH_RF24_PREAMBLE_LENGTH_BYTES 0x10
  387. #define RH_RF24_PREAMBLE_MAN_CONST 0x08
  388. #define RH_RF24_PREAMBLE_MAN_ENABLE 0x02
  389. #define RH_RF24_PREAMBLE_NON_STANDARD 0x00
  390. #define RH_RF24_PREAMBLE_STANDARD_1010 0x01
  391. #define RH_RF24_PREAMBLE_STANDARD_0101 0x02
  392. //#define RH_RF24_PROPERTY_SYNC_CONFIG 0x1100
  393. #define RH_RF24_SYNC_CONFIG_SKIP_TX 0x80
  394. #define RH_RF24_SYNC_CONFIG_RX_ERRORS_MASK 0x70
  395. #define RH_RF24_SYNC_CONFIG_4FSK 0x08
  396. #define RH_RF24_SYNC_CONFIG_MANCH 0x04
  397. #define RH_RF24_SYNC_CONFIG_LENGTH_MASK 0x03
  398. //#define RH_RF24_PROPERTY_PKT_CRC_CONFIG 0x1200
  399. #define RH_RF24_CRC_SEED_ALL_0S 0x00
  400. #define RH_RF24_CRC_SEED_ALL_1S 0x80
  401. #define RH_RF24_CRC_MASK 0x0f
  402. #define RH_RF24_CRC_NONE 0x00
  403. #define RH_RF24_CRC_ITU_T 0x01
  404. #define RH_RF24_CRC_IEC_16 0x02
  405. #define RH_RF24_CRC_BIACHEVA 0x03
  406. #define RH_RF24_CRC_16_IBM 0x04
  407. #define RH_RF24_CRC_CCITT 0x05
  408. #define RH_RF24_CRC_KOOPMAN 0x06
  409. #define RH_RF24_CRC_IEEE_802_3 0x07
  410. #define RH_RF24_CRC_CASTAGNOLI 0x08
  411. //#define RH_RF24_PROPERTY_PKT_CONFIG1 0x1206
  412. #define RH_RF24_PH_FIELD_SPLIT 0x80
  413. #define RH_RF24_PH_RX_DISABLE 0x40
  414. #define RH_RF24_4FSK_EN 0x20
  415. #define RH_RF24_RX_MULTI_PKT 0x10
  416. #define RH_RF24_MANCH_POL 0x08
  417. #define RH_RF24_CRC_INVERT 0x04
  418. #define RH_RF24_CRC_ENDIAN 0x02
  419. #define RH_RF24_BIT_ORDER 0x01
  420. //#define RH_RF24_PROPERTY_PKT_FIELD_1_CONFIG 0x120f
  421. //#define RH_RF24_PROPERTY_PKT_FIELD_2_CONFIG 0x1213
  422. //#define RH_RF24_PROPERTY_PKT_FIELD_3_CONFIG 0x1217
  423. //#define RH_RF24_PROPERTY_PKT_FIELD_4_CONFIG 0x121b
  424. //#define RH_RF24_PROPERTY_PKT_FIELD_5_CONFIG 0x121f
  425. #define RH_RF24_FIELD_CONFIG_4FSK 0x10
  426. #define RH_RF24_FIELD_CONFIG_WHITEN 0x02
  427. #define RH_RF24_FIELD_CONFIG_MANCH 0x01
  428. //#define RH_RF24_PROPERTY_PKT_RX_FIELD_1_CRC_CONFIG 0x1224
  429. //#define RH_RF24_PROPERTY_PKT_RX_FIELD_2_CRC_CONFIG 0x1228
  430. //#define RH_RF24_PROPERTY_PKT_RX_FIELD_3_CRC_CONFIG 0x122c
  431. //#define RH_RF24_PROPERTY_PKT_RX_FIELD_4_CRC_CONFIG 0x1230
  432. //#define RH_RF24_PROPERTY_PKT_RX_FIELD_5_CRC_CONFIG 0x1234
  433. #define RH_RF24_FIELD_CONFIG_CRC_START 0x80
  434. #define RH_RF24_FIELD_CONFIG_SEND_CRC 0x20
  435. #define RH_RF24_FIELD_CONFIG_CHECK_CRC 0x08
  436. #define RH_RF24_FIELD_CONFIG_CRC_ENABLE 0x02
  437. //#define RH_RF24_PROPERTY_MODEM_MOD_TYPE 0x2000
  438. #define RH_RF24_TX_DIRECT_MODE_TYPE_SYNCHRONOUS 0x00
  439. #define RH_RF24_TX_DIRECT_MODE_TYPE_ASYNCHRONOUS 0x80
  440. #define RH_RF24_TX_DIRECT_MODE_GPIO0 0x00
  441. #define RH_RF24_TX_DIRECT_MODE_GPIO1 0x20
  442. #define RH_RF24_TX_DIRECT_MODE_GPIO2 0x40
  443. #define RH_RF24_TX_DIRECT_MODE_GPIO3 0x60
  444. #define RH_RF24_MOD_SOURCE_PACKET_HANDLER 0x00
  445. #define RH_RF24_MOD_SOURCE_DIRECT_MODE 0x08
  446. #define RH_RF24_MOD_SOURCE_RANDOM_GENERATOR 0x10
  447. #define RH_RF24_MOD_TYPE_CW 0x00
  448. #define RH_RF24_MOD_TYPE_OOK 0x01
  449. #define RH_RF24_MOD_TYPE_2FSK 0x02
  450. #define RH_RF24_MOD_TYPE_2GFSK 0x03
  451. #define RH_RF24_MOD_TYPE_4FSK 0x04
  452. #define RH_RF24_MOD_TYPE_4GFSK 0x05
  453. // RH_RF24_PROPERTY_PA_MODE 0x2200
  454. #define RH_RF24_PA_MODE_1_GROUP 0x04
  455. #define RH_RF24_PA_MODE_2_GROUPS 0x08
  456. #define RH_RF24_PA_MODE_CLASS_E 0x00
  457. #define RH_RF24_PA_MODE_SWITCH_CURRENT 0x01
  458. /////////////////////////////////////////////////////////////////////
  459. /// \class RH_RF24 RH_RF24.h <RH_RF24.h>
  460. /// \brief Driver to send and receive unaddressed, unreliable datagrams via an RF24 and compatible radio transceiver.
  461. ///
  462. /// Works with
  463. /// - Silicon Labs Si4460/1/2/3/4 transceiver chips
  464. /// - The equivalent HopeRF RF24/25/26/27 transceiver chips
  465. /// - HopeRF Complete modules: RFM24W/26W/27W
  466. ///
  467. /// \par Overview
  468. ///
  469. /// This class provides basic functions for sending and receiving unaddressed,
  470. /// unreliable datagrams of arbitrary length to 250 octets per packet.
  471. ///
  472. /// Manager classes may use this class to implement reliable, addressed datagrams and streams,
  473. /// mesh routers, repeaters, translators etc.
  474. ///
  475. /// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and
  476. /// modulation scheme.
  477. ///
  478. /// This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF
  479. /// RF24 and compatible radio modules, such as the RFM24W module.
  480. ///
  481. /// The Hope-RF (http://www.hoperf.com) RF24 family is a low-cost ISM transceiver
  482. /// chip. It supports FSK, GFSK, OOK over a wide range of frequencies and
  483. /// programmable data rates. HopeRF also sell these chips on modules which includes
  484. /// a crystal and antenna coupling circuits: RFM24W, RFM26W and RFM27W
  485. ///
  486. /// This Driver provides functions for sending and receiving messages of up
  487. /// to 250 octets on any frequency supported by the RF24, in a range of
  488. /// predefined data rates and frequency deviations. Frequency can be set
  489. /// to any frequency from 142.0MHz to 1050.0MHz. Caution: most modules only support a more limited
  490. /// range of frequencies due to antenna tuning.
  491. ///
  492. /// Up to 2 RFM24 modules can be connected to an Arduino (3 on a Mega),
  493. /// permitting the construction of translators and frequency changers, etc.
  494. ///
  495. /// The following modulation types are suppported with a range of modem configurations for
  496. /// common data rates and frequency deviations:
  497. /// - OOK On-Off Keying
  498. /// - GFSK Gaussian Frequency Shift Keying
  499. /// - FSK Frequency Shift Keying
  500. ///
  501. /// Support for other RF24 features such as on-chip temperature measurement,
  502. /// transmitter power control etc is also provided.
  503. ///
  504. /// RH_RF24 uses interrupts to detect and handle events in the radio chip. The RF24 family has
  505. /// TX and RX FIFOs of 64 bytes, but through the use of interrupt, the RH_RF24 driver can send longer
  506. /// messages by filling or emptying the FIFOs on-the-fly.
  507. ///
  508. /// Tested on Anarduino Mini http://www.anarduino.com/mini/ with arduino-1.0.5
  509. /// on OpenSuSE 13.1
  510. ///
  511. /// \par Packet Format
  512. ///
  513. /// All messages sent and received by this RH_RF24 Driver conform to this packet format:
  514. ///
  515. /// - 4 octets PREAMBLE (configurable)
  516. /// - 2 octets SYNC 0x2d, 0xd4 (configurable, so you can use this as a network filter)
  517. /// - Field containing 1 octet of message length and 2 octet CRC protecting this field
  518. /// - Field 2 containing at least 4 octets, and 2 octet CRC protecting this field:
  519. /// + 4 octets HEADER: (TO, FROM, ID, FLAGS)
  520. /// + 0 to 250 octets DATA
  521. /// + 2 octets CRC, computed on HEADER and DATA
  522. ///
  523. /// \par Connecting RFM-24 to Arduino
  524. ///
  525. /// For RFM24/RFM26 and Teensy 3.1 or Anarduino Mini
  526. /// \code
  527. /// Teensy RFM-24/RFM26
  528. /// GND----------GND (ground in)
  529. /// 3V3----------VCC (3.3V in)
  530. /// interrupt 2 pin D2-----------NIRQ (interrupt request out)
  531. /// SS pin D10----------NSEL (chip select in)
  532. /// SCK pin D13----------SCK (SPI clock in)
  533. /// MOSI pin D11----------SDI (SPI Data in)
  534. /// MISO pin D12----------SDO (SPI data out)
  535. /// D9-----------SDN (shutdown in)
  536. /// /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT)
  537. /// \--TX_ANT (TX antenna control in) RFM22B only
  538. /// /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT)
  539. /// \--RX_ANT (RX antenna control in) RFM22B only
  540. /// \endcode
  541. /// Caution: tying the radio SDN pin to ground (though it might appear from the data sheets to make sense)
  542. /// does not always produce a reliable radio startup. So this driver controls the SDN pin directly.
  543. /// Note: the GPIO0-TX_ANT and GPIO1-RX_ANT connections are not required for the 11dBm RFM24W,
  544. /// which has no antenna switch.
  545. ///
  546. /// If you have an Arduino Zero, you should note that you cannot use Pin 2 for the interrupt line
  547. /// (Pin 2 is for the NMI only), instead you can use any other pin (we use Pin 3) and initialise RH_RF69 like this:
  548. /// \code
  549. /// // Slave Select is pin 10, interrupt is Pin 3
  550. /// RH_RF24 driver(10, 3);
  551. /// \endcode
  552. ///
  553. /// \par Customising
  554. ///
  555. /// The library will work out of the box with the provided examples, over the full frequency range and with
  556. /// a wide range of predefined modem configurations schemes and speeds. However, you may want to
  557. /// change the default behaviour of this library. There are several ways you can do this:
  558. ///
  559. /// - Use the RH_RF24 API based on this documentation
  560. /// - Create your own ModemConfig and pass it to setModemreeegisters()
  561. /// - Generate a new radio_config_Si4460.h using the Silicon Labs WDS software package
  562. /// - Write directly to the radio registers and properties using command() and set_properties()
  563. ///
  564. /// \par RSSI
  565. ///
  566. /// The RSSI (Received Signal Strength Indicator) is measured and latched after the message sync bytes are received.
  567. /// The latched RSSI is available from the lastRssi() member functionafter the complete message is received.
  568. /// Although lastRssi()
  569. /// supposedly returns a signed integer, in the case of this radio it actually returns an unsigned 8 bit integer (uint8_t)
  570. /// and you will have to cast the return value to use it:
  571. /// \code
  572. /// uint8_t lastRssi = (uint8_t)rf24.lastRssi();
  573. /// \endcode
  574. /// The units of RSSI are arbitrary and relative, with larger unsigned numbers indicating a stronger signal. Values up to 255
  575. /// are seen with radios in close proximity to each other. Lower limit of receivable strength is about 70.
  576. ///
  577. /// \par Transmitter Power
  578. ///
  579. /// You can control the transmitter power on the RF24/25/26/27 transceiver
  580. /// with the RH_RF24::setTxPower() function. The argument can be any of
  581. /// 0x00 to 0x4f (for RFM24/Si4460) or
  582. /// 0x00 to 0x7f (for others)
  583. /// 0x00 will yield no measurable power. For other settings there is a non-linear correlation with actual
  584. /// RF power output (see below)
  585. /// The default is 0x10. Eg:
  586. /// \code
  587. /// driver.setTxPower(0x10);
  588. /// \endcode
  589. ///
  590. /// We have made some actual power measurements against
  591. /// programmed power
  592. /// - Anarduino Mini with RFM24-433 and RFM26-433 at Vcc = 3.3V, in CW mode, 434MHz
  593. /// - 10cm RG58C/U soldered direct to RFM69 module ANT and GND
  594. /// - bnc connecteor
  595. /// - 12dB attenuator
  596. /// - BNC-SMA adapter
  597. /// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set)
  598. /// - Digitech QM-1460 digital multimeter
  599. /// \code
  600. /// Program power Measured Power dBm
  601. /// HEX RFM24 RFM26
  602. /// 0x00 not measurable not measurable
  603. /// 0x01 -20.4 -20.6
  604. /// 0x0f 2.4 4.8
  605. /// 0x1f 9.4 11.0
  606. /// 0x2f 11.2 14.2
  607. /// 0x3f 11.6 16.4
  608. /// 0x4f 11.6 18.0
  609. /// 0x5f 18.6
  610. /// 0x6f 19.0
  611. /// 0x7f 19.2
  612. /// \endcode
  613. /// Caution: the actual radiated power output will depend heavily on the power supply voltage and the antenna.
  614. class RH_RF24 : public RHSPIDriver
  615. {
  616. public:
  617. /// \brief Defines property values for a set of modem configuration registers
  618. ///
  619. /// Defines property values for a set of modem configuration registers
  620. /// that can be passed to setModemRegisters() if none of the choices in
  621. /// ModemConfigChoice suit your need setModemRegisters() writes the
  622. /// property values from this structure to the appropriate RF24 properties
  623. /// to set the desired modulation type, data rate and deviation/bandwidth.
  624. typedef struct
  625. {
  626. uint8_t prop_2000; ///< Value for property RH_RF24_PROPERTY_MODEM_MOD_TYPE
  627. uint8_t prop_2003; ///< Value for property RH_RF24_PROPERTY_MODEM_DATA_RATE_2
  628. uint8_t prop_2004; ///< Value for property RH_RF24_PROPERTY_MODEM_DATA_RATE_1
  629. uint8_t prop_2005; ///< Value for property RH_RF24_PROPERTY_MODEM_DATA_RATE_0
  630. uint8_t prop_2006; ///< Value for property RH_RF24_PROPERTY_MODEM_TX_NCO_MODE_3
  631. uint8_t prop_200a; ///< Value for property RH_RF24_PROPERTY_MODEM_FREQ_DEV_2
  632. uint8_t prop_200b; ///< Value for property RH_RF24_PROPERTY_MODEM_FREQ_DEV_1
  633. uint8_t prop_200c; ///< Value for property RH_RF24_PROPERTY_MODEM_FREQ_DEV_0
  634. uint8_t prop_2018; ///< Value for property RH_RF24_PROPERTY_MODEM_TX_RAMP_DELAY
  635. uint8_t prop_201e; ///< Value for property RH_RF24_PROPERTY_MODEM_DECIMATION_CFG1
  636. uint8_t prop_201f; ///< Value for property RH_RF24_PROPERTY_MODEM_DECIMATION_CFG0
  637. uint8_t prop_2022; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_OSR_1
  638. uint8_t prop_2023; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_OSR_0
  639. uint8_t prop_2024; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_2
  640. uint8_t prop_2025; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_1
  641. uint8_t prop_2026; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_NCO_OFFSET_0
  642. uint8_t prop_2027; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_GAIN_1
  643. uint8_t prop_2028; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_GAIN_0
  644. uint8_t prop_2029; ///< Value for property RH_RF24_PROPERTY_MODEM_BCR_GEAR
  645. uint8_t prop_202d; ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_WAIT
  646. uint8_t prop_202e; ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_GAIN_1
  647. uint8_t prop_202f; ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_GAIN_0
  648. uint8_t prop_2030; ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_LIMITER_1
  649. uint8_t prop_2031; ///< Value for property RH_RF24_PROPERTY_MODEM_AFC_LIMITER_0
  650. uint8_t prop_2035; ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_CONTROL
  651. uint8_t prop_2038; ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_WINDOW_SIZE
  652. uint8_t prop_2039; ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_RFPD_DECAY
  653. uint8_t prop_203a; ///< Value for property RH_RF24_PROPERTY_MODEM_AGC_IFPD_DECAY
  654. uint8_t prop_203b; ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_GAIN1
  655. uint8_t prop_203c; ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_GAIN0
  656. uint8_t prop_203d; ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_TH1
  657. uint8_t prop_203e; ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_TH0
  658. uint8_t prop_203f; ///< Value for property RH_RF24_PROPERTY_MODEM_FSK4_MAP
  659. uint8_t prop_2040; ///< Value for property RH_RF24_PROPERTY_MODEM_OOK_PDTC
  660. uint8_t prop_2043; ///< Value for property RH_RF24_PROPERTY_MODEM_OOK_MISC
  661. uint8_t prop_2045; ///< Value for property RH_RF24_PROPERTY_MODEM_RAW_CONTROL
  662. uint8_t prop_2046; ///< Value for property RH_RF24_PROPERTY_MODEM_RAW_EYE_1
  663. uint8_t prop_2047; ///< Value for property RH_RF24_PROPERTY_MODEM_RAW_EYE_0
  664. uint8_t prop_204e; ///< Value for property RH_RF24_PROPERTY_MODEM_RSSI_COMP
  665. uint8_t prop_2100; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE13_7_0
  666. uint8_t prop_2101; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE12_7_0
  667. uint8_t prop_2102; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE11_7_0
  668. uint8_t prop_2103; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE10_7_0
  669. uint8_t prop_2104; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE9_7_0
  670. uint8_t prop_2105; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE8_7_0
  671. uint8_t prop_2106; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE7_7_0
  672. uint8_t prop_2107; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE6_7_0
  673. uint8_t prop_2108; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE5_7_0
  674. uint8_t prop_2109; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE4_7_0
  675. uint8_t prop_210a; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE3_7_0
  676. uint8_t prop_210b; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE2_7_0
  677. uint8_t prop_210c; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE1_7_0
  678. uint8_t prop_210d; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COE0_7_0
  679. uint8_t prop_210e; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM0
  680. uint8_t prop_210f; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM1
  681. uint8_t prop_2110; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM2
  682. uint8_t prop_2111; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX1_CHFLT_COEM3
  683. uint8_t prop_2112; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE13_7_0
  684. uint8_t prop_2113; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE12_7_0
  685. uint8_t prop_2114; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE11_7_0
  686. uint8_t prop_2115; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE10_7_0
  687. uint8_t prop_2116; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE9_7_0
  688. uint8_t prop_2117; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE8_7_0
  689. uint8_t prop_2118; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE7_7_0
  690. uint8_t prop_2119; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE6_7_0
  691. uint8_t prop_211a; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE5_7_0
  692. uint8_t prop_211b; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE4_7_0
  693. uint8_t prop_211c; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE3_7_0
  694. uint8_t prop_211d; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE2_7_0
  695. uint8_t prop_211e; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE1_7_0
  696. uint8_t prop_211f; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COE0_7_0
  697. uint8_t prop_2120; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM0
  698. uint8_t prop_2121; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM1
  699. uint8_t prop_2122; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM2
  700. uint8_t prop_2123; ///< Value for property RH_RF24_PROPERTY_MODEM_CHFLT_RX2_CHFLT_COEM3
  701. uint8_t prop_2203; ///< Value for property RH_RF24_PROPERTY_PA_TC
  702. uint8_t prop_2300; ///< Value for property RH_RF24_PROPERTY_SYNTH_PFDCP_CPFF
  703. uint8_t prop_2301; ///< Value for property RH_RF24_PROPERTY_SYNTH_PFDCP_CPINT
  704. uint8_t prop_2303; ///< Value for property RH_RF24_PROPERTY_SYNTH_LPFILT3
  705. uint8_t prop_2304; ///< Value for property RH_RF24_PROPERTY_SYNTH_LPFILT2
  706. uint8_t prop_2305; ///< Value for property RH_RF24_PROPERTY_SYNTH_LPFILT1
  707. } ModemConfig;
  708. /// Choices for setModemConfig() for a selected subset of common
  709. /// modulation types, and data rates. If you need another configuration,
  710. /// use the register calculator. and call setModemRegisters() with your
  711. /// desired settings.
  712. /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic
  713. /// definitions and not their integer equivalents: its possible that values will be
  714. /// changed in later versions (though we will try to avoid it).
  715. /// Contributions of new complete and tested ModemConfigs ready to add to this list will be readily accepted.
  716. typedef enum
  717. {
  718. FSK_Rb0_5Fd1 = 0, ///< FSK Rb = 0.5kbs, Fd = 1kHz
  719. FSK_Rb5Fd10, ///< FSK Rb = 5kbs, Fd = 10kHz
  720. FSK_Rb50Fd100, ///< FSK Rb = 50kbs, Fd = 100kHz
  721. FSK_Rb150Fd300, ///< FSK Rb = 50kbs, Fd = 100kHz
  722. GFSK_Rb0_5Fd1, ///< GFSK Rb = 0.5kbs, Fd = 1kHz
  723. GFSK_Rb5Fd10, ///< GFSK Rb = 5kbs, Fd = 10kHz
  724. GFSK_Rb50Fd100, ///< GFSK Rb = 50kbs, Fd = 100kHz
  725. GFSK_Rb150Fd300, ///< GFSK Rb = 150kbs, Fd = 300kHz
  726. // We were unable to get any other OOKs to work
  727. OOK_Rb5Bw30, ///< OOK Rb = 5kbs, Bw = 30kHz
  728. OOK_Rb10Bw40, ///< OOK Rb = 10kbs, Bw = 40kHz
  729. // We were unable to get any 4FSK or 4GFSK schemes to work
  730. } ModemConfigChoice;
  731. /// \brief Defines the available choices for CRC
  732. /// Types of permitted CRC polynomials, to be passed to setCRCPolynomial()
  733. /// They deliberately have the same numeric values as the CRC_POLYNOMIAL field of PKT_CRC_CONFIG
  734. typedef enum
  735. {
  736. CRC_NONE = 0,
  737. CRC_ITU_T,
  738. CRC_IEC_16,
  739. CRC_Biacheva,
  740. CRC_16_IBM,
  741. CRC_CCITT,
  742. CRC_Koopman,
  743. CRC_IEEE_802_3,
  744. CRC_Castagnoli,
  745. } CRCPolynomial;
  746. /// \brief Defines the commands we can interrogate in printRegisters
  747. typedef struct
  748. {
  749. uint8_t cmd; ///< The command number
  750. uint8_t replyLen; ///< Number of bytes in the reply stream (after the CTS)
  751. } CommandInfo;
  752. /// Constructor. You can have multiple instances, but each instance must have its own
  753. /// interrupt and slave select pin. After constructing, you must call init() to initialise the interface
  754. /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient
  755. /// distinct interrupt lines, one for each instance.
  756. /// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF24 before
  757. /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple)
  758. /// \param[in] interruptPin The interrupt Pin number that is connected to the RF24 DIO0 interrupt line.
  759. /// Defaults to pin 2.
  760. /// Caution: You must specify an interrupt capable pin.
  761. /// On many Arduino boards, there are limitations as to which pins may be used as interrupts.
  762. /// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin.
  763. /// On other Arduinos pins 2 or 3.
  764. /// See http://arduino.cc/en/Reference/attachInterrupt for more details.
  765. /// On Chipkit Uno32, pins 38, 2, 7, 8, 35.
  766. /// On other boards, any digital pin may be used.
  767. /// \param [in] sdnPin The pin number connected to SDN on the radio. Defaults to pin 9.
  768. /// Connecting SDN directly to ground does not aloways provide reliable radio startup.
  769. /// \param[in] spi Pointer to the SPI interface object to use.
  770. /// Defaults to the standard Arduino hardware SPI interface
  771. RH_RF24(uint8_t slaveSelectPin = SS, uint8_t interruptPin = 2, uint8_t sdnPin = 9, RHGenericSPI& spi = hardware_spi);
  772. /// Initialises this instance and the radio module connected to it.
  773. /// The following steps are taken:
  774. /// - Initialise the slave select and shutdown pins and the SPI interface library
  775. /// - Checks the connected RF24 module can be communicated
  776. /// - Attaches an interrupt handler
  777. /// - Configures the RF24 module
  778. /// - Sets the frequency to 434.0 MHz
  779. /// - Sets the modem data rate to GFSK_Rb5Fd10
  780. /// - Sets the tranmitter power level to 16 (about 2.4dBm on RFM4)
  781. /// \return true if everything was successful
  782. bool init();
  783. /// Sets the chip mode that will be used when the RH_RF24 driver is idle (ie not transmitting or receiving)
  784. /// You can use this to control the power level consumed while idle, at the cost of slower
  785. /// transition to tranmit or receive states
  786. /// \param[in] idleMode The chip state to use when idle. Sensible choices might be RH_RF24_DEVICE_STATE_SLEEP or RH_RF24_DEVICE_STATE_READY
  787. void setIdleMode(uint8_t idleMode);
  788. /// Sets the transmitter and receiver
  789. /// centre frequency.
  790. /// Valid frequency ranges for RFM24/Si4460, Si4461, RFM25/Si4463 are:
  791. /// 142MHz to 175Mhz, 284MHz to 350MHz, 425MHz to 525MHz, 850MHz to 1050MHz.
  792. /// Valid frequency ranges for RFM26/Si4464 are:
  793. /// 119MHz to 960MHz.
  794. /// Caution: RFM modules are designed with antenna coupling components to suit a limited band
  795. /// of frequencies (marked underneath the module). It is possible to set frequencies in other bands,
  796. /// but you may only get little or no power radiated.
  797. /// \param[in] centre Frequency in MHz.
  798. /// \param[in] afcPullInRange Not used
  799. /// \return true if the selected frequency is within a valid range for the connected radio and if
  800. /// setting the new frequency succeeded.
  801. bool setFrequency(float centre, float afcPullInRange = 0.05);
  802. /// Sets all the properties required to configure the data modem in the RF24, including the data rate,
  803. /// bandwidths etc. You can use this to configure the modem with custom configurations if none of the
  804. /// canned configurations in ModemConfigChoice suit you.
  805. /// \param[in] config A ModemConfig structure containing values for the modem configuration registers.
  806. void setModemRegisters(const ModemConfig* config);
  807. /// Select one of the predefined modem configurations. If you need a modem configuration not provided
  808. /// here, use setModemRegisters() with your own ModemConfig. The default after init() is RH_RF24::GFSK_Rb5Fd10.
  809. /// \param[in] index The configuration choice.
  810. /// \return true if index is a valid choice.
  811. bool setModemConfig(ModemConfigChoice index);
  812. /// Starts the receiver and checks whether a received message is available.
  813. /// This can be called multiple times in a timeout loop
  814. /// \return true if a complete, valid message has been received and is able to be retrieved by
  815. /// recv()
  816. bool available();
  817. /// Turns the receiver on if it not already on.
  818. /// If there is a valid message available, copy it to buf and return true
  819. /// else return false.
  820. /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).
  821. /// You should be sure to call this function frequently enough to not miss any messages
  822. /// It is recommended that you call it in your main loop.
  823. /// \param[in] buf Location to copy the received message
  824. /// \param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.
  825. /// \return true if a valid message was copied to buf
  826. bool recv(uint8_t* buf, uint8_t* len);
  827. /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent().
  828. /// Then loads a message into the transmitter and starts the transmitter. Note that a message length
  829. /// of 0 is NOT permitted.
  830. /// \param[in] data Array of data to be sent
  831. /// \param[in] len Number of bytes of data to send (> 0)
  832. /// \return true if the message length was valid and it was correctly queued for transmit
  833. bool send(const uint8_t* data, uint8_t len);
  834. /// The maximum message length supported by this driver
  835. /// \return The maximum message length supported by this driver
  836. uint8_t maxMessageLength();
  837. /// Sets the length of the preamble
  838. /// in bytes.
  839. /// Caution: this should be set to the same
  840. /// value on all nodes in your network. Default is 4.
  841. /// \param[in] bytes Preamble length in bytes.
  842. void setPreambleLength(uint16_t bytes);
  843. /// Sets the sync words for transmit and receive
  844. /// Caution: SyncWords should be set to the same
  845. /// value on all nodes in your network. Nodes with different SyncWords set will never receive
  846. /// each others messages, so different SyncWords can be used to isolate different
  847. /// networks from each other. Default is { 0x2d, 0xd4 }.
  848. /// \param[in] syncWords Array of sync words, 1 to 4 octets long. NULL if no sync words to be used.
  849. /// \param[in] len Number of sync words to set, 1 to 4. 0 if no sync words to be used.
  850. void setSyncWords(const uint8_t* syncWords = NULL, uint8_t len = 0);
  851. /// Sets the CRC polynomial to be used to generate the CRC for both receive and transmit
  852. /// otherwise the default of CRC_16_IBM will be used.
  853. /// \param[in] polynomial One of RH_RF24::CRCPolynomial choices CRC_*
  854. /// \return true if polynomial is a valid option for this radio.
  855. bool setCRCPolynomial(CRCPolynomial polynomial);
  856. /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running,
  857. /// disables them.
  858. void setModeIdle();
  859. /// If current mode is Tx or Idle, changes it to Rx.
  860. /// Starts the receiver in the RF24.
  861. void setModeRx();
  862. /// If current mode is Rx or Idle, changes it to Rx. F
  863. /// Starts the transmitter in the RF24.
  864. void setModeTx();
  865. /// Sets the transmitter power output level register PA_PWR_LVL
  866. /// The power argument to this function has a non-linear correlation with the actual RF power output.
  867. /// See the transmitter power table above for some examples.
  868. /// Also the Si446x Data Sheet section 5.4.2 may be helpful.
  869. /// Be a good neighbour and set the lowest power level you need.
  870. /// Caution: legal power limits may apply in certain countries.
  871. /// After init(), the power will be set to 0x10.
  872. /// \param[in] power Transmitter power level. For RFM24/Si4460, valid values are 0x00 to 0x4f. For others, 0x00 to 0x7f
  873. void setTxPower(uint8_t power);
  874. /// Dump the values of available command replies and properties
  875. /// to the Serial device if RH_HAVE_SERIAL is defined for the current platform
  876. /// Not all commands have valid replies, therefore they are not all printed.
  877. /// Caution: the list is very long
  878. bool printRegisters();
  879. /// Send a string of command bytes to the chip and get a string of reply bytes
  880. /// Different RFM24 commands take different numbers of command bytes and send back different numbers
  881. /// of reply bytes. See the Si446x documentaiton for more details.
  882. /// Both command bytes and reply bytes are optional
  883. /// \param[in] cmd The command number. One of RH_RF24_CMD_*
  884. /// \param[in] write_buf Pointer to write_len bytes of command input bytes to send. If there are none, set to NULL.
  885. /// \param[in] write_len The number of bytes to send from write_buf. If there are none, set to 0
  886. /// \param[out] read_buf Pointer to read_len bytes of storage where the reply stream from the comand will be written.
  887. /// If none are required, set to NULL
  888. /// \param[in] read_len The number of bytes to read from the reply stream. If none required, set to 0.
  889. /// \return true if the command succeeeded.
  890. bool command(uint8_t cmd, const uint8_t* write_buf = 0, uint8_t write_len = 0, uint8_t* read_buf = 0, uint8_t read_len = 0);
  891. /// Set one or more chip properties using the RH_RF24_CMD_SET_PROPERTY
  892. /// command. See the Si446x API Description AN625 for details on what properties are available.
  893. /// param[in] firstProperty The property number of the first property to set. The first value in the values array
  894. /// will be used to set this property, and any subsequent values will be used to set the following properties.
  895. /// One of RH_RF24_PROPERTY_*
  896. /// param[in] values Array of 0 or more values to write the firstProperty and subsequent proerties
  897. /// param[in] count The number of values in the values array
  898. /// \return true if the command succeeeded.
  899. bool set_properties(uint16_t firstProperty, const uint8_t* values, uint8_t count);
  900. /// Get one or more chip properties using the RH_RF24_CMD_GET_PROPERTY
  901. /// command. See the Si446x API Description AN625 for details on what properties are available.
  902. /// param[in] firstProperty The property number of the first property to get. The first value in the values array
  903. /// will be set with this property, and any subsequent values will be set from the following properties.
  904. /// One of RH_RF24_PROPERTY_*
  905. /// param[out] values Array of 0 or more values to receive the firstProperty and subsequent proerties
  906. /// param[in] count The number of values in the values array
  907. /// \return true if the command succeeeded.
  908. bool get_properties(uint16_t firstProperty, uint8_t* values, uint8_t count);
  909. /// Measures and returns the current
  910. /// Chip temperature.
  911. /// \return The current chip temperature in degrees Centigrade
  912. float get_temperature();
  913. /// Measures and returns the current
  914. /// Chip Vcc supply voltage.
  915. /// \return The current chip Vcc supply voltage in Volts.
  916. float get_battery_voltage();
  917. /// Measures and returns the current
  918. /// voltage applied to a GPIO pin (which has previously been configured as a voltage input)
  919. /// \param[in] gpio The GPIO pin to read. 0 to 3.
  920. /// \return The current pin voltage in Volts.
  921. float get_gpio_voltage(uint8_t gpio);
  922. /// Read one of the Fast Read Response registers.
  923. /// The Fast Read Response register must be previously configured with the matching
  924. /// RH_RF24_PROPERTY_FRR_CTL_?_MODE property to select what chip property will be available in that register.
  925. /// \param[in] reg The index of the FRR register to read. 0 means FRR A, 1 means B etc.
  926. /// \return the value read from the specified Fast Read Response register.
  927. uint8_t frr_read(uint8_t reg);
  928. /// Sets the radio into low-power sleep mode.
  929. /// If successful, the transport will stay in sleep mode until woken by
  930. /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc)
  931. /// Caution: there is a time penalty as the radio takes a finte time to wake from sleep mode.
  932. /// \return true if sleep mode was successfully entered.
  933. virtual bool sleep();
  934. protected:
  935. /// This is a low level function to handle the interrupts for one instance of RF24.
  936. /// Called automatically by isr*()
  937. /// Should not need to be called by user code.
  938. void handleInterrupt();
  939. /// Clears the chips RX FIFO
  940. /// \return true if successful
  941. bool clearRxFifo();
  942. /// Clears RH_RF24's internal TX and RX buffers and counters
  943. void clearBuffer();
  944. /// Loads the next part of the currently transmitting message
  945. /// into the chips TX buffer
  946. void sendNextFragment();
  947. /// Copies the next part of the currenrtly received message from the chips RX FIFO to the
  948. /// receive buffer
  949. void readNextFragment();
  950. /// Loads data into the chips TX FIFO
  951. /// \param[in] data Array of data bytes to be loaded
  952. /// \param[in] len Number of bytes in data to be loaded
  953. /// \return true if successful
  954. bool writeTxFifo(uint8_t *data, uint8_t len);
  955. /// Checks the contents of the RX buffer.
  956. /// If it contans a valid message adressed to this node
  957. /// sets _rxBufValid.
  958. void validateRxBuf();
  959. /// Cycles the Shutdown pin to force the cradio chip to reset
  960. void power_on_reset();
  961. /// Sets registers, commands and properties
  962. /// in the ratio according to the data in the commands array
  963. /// \param[in] commands Array of data containing radio commands in the format provided by radio_config_Si4460.h
  964. /// \return true if successful
  965. bool configure(const uint8_t* commands);
  966. /// Clears all pending interrutps in the radio chip.
  967. bool cmd_clear_all_interrupts();
  968. private:
  969. /// Low level interrupt service routine for RF24 connected to interrupt 0
  970. static void isr0();
  971. /// Low level interrupt service routine for RF24 connected to interrupt 1
  972. static void isr1();
  973. /// Low level interrupt service routine for RF24 connected to interrupt 1
  974. static void isr2();
  975. /// Array of instances connected to interrupts 0 and 1
  976. static RH_RF24* _deviceForInterrupt[];
  977. /// Index of next interrupt number to use in _deviceForInterrupt
  978. static uint8_t _interruptCount;
  979. /// The configured interrupt pin connected to this instance
  980. uint8_t _interruptPin;
  981. /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated)
  982. /// else 0xff
  983. uint8_t _myInterruptIndex;
  984. /// The configured pin connected to the SDN pin of the radio
  985. uint8_t _sdnPin;
  986. /// The radio OP mode to use when mode is RHModeIdle
  987. uint8_t _idleMode;
  988. /// The reported PART device type
  989. uint16_t _deviceType;
  990. /// The selected output power in dBm
  991. int8_t _power;
  992. /// The message length in _buf
  993. volatile uint8_t _bufLen;
  994. /// Array of octets of the last received message or the next to transmit message
  995. uint8_t _buf[RH_RF24_MAX_PAYLOAD_LEN];
  996. /// True when there is a valid message in the Rx buffer
  997. volatile bool _rxBufValid;
  998. /// Index into TX buffer of the next to send chunk
  999. volatile uint8_t _txBufSentIndex;
  1000. /// Time in millis since the last preamble was received (and the last time the RSSI was measured)
  1001. uint32_t _lastPreambleTime;
  1002. };
  1003. /// @example rf24_client.pde
  1004. /// @example rf24_server.pde
  1005. /// @example rf24_reliable_datagram_client.pde
  1006. /// @example rf24_reliable_datagram_server.pde
  1007. #endif