sx1276-LoRa.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. /*
  2. * THE FOLLOWING FIRMWARE IS PROVIDED: (1) "AS IS" WITH NO WARRANTY; AND
  3. * (2)TO ENABLE ACCESS TO CODING INFORMATION TO GUIDE AND FACILITATE CUSTOMER.
  4. * CONSEQUENTLY, SEMTECH SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR
  5. * CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
  6. * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
  7. * CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  8. *
  9. * Copyright (C) SEMTECH S.A.
  10. */
  11. /*!
  12. * \file sx1276-LoRa.h
  13. * \brief SX1276 RF chip driver mode LoRa
  14. *
  15. * \version 2.0.B2
  16. * \date May 6 2013
  17. * \author Gregory Cristian
  18. *
  19. * Last modified by Miguel Luis on Jun 19 2013
  20. */
  21. #ifndef __SX1276_LORA_H__
  22. #define __SX1276_LORA_H__
  23. #include "stdint.h"
  24. #include "stdbool.h"
  25. /*!
  26. * SX1276 LoRa General parameters definition
  27. */
  28. typedef struct sLoRaSettings
  29. {
  30. uint32_t RFFrequency;
  31. int8_t Power;
  32. uint8_t SignalBw; // LORA [0: 7.8 kHz, 1: 10.4 kHz, 2: 15.6 kHz, 3: 20.8 kHz, 4: 31.2 kHz,
  33. // 5: 41.6 kHz, 6: 62.5 kHz, 7: 125 kHz, 8: 250 kHz, 9: 500 kHz, other: Reserved]
  34. uint8_t SpreadingFactor; // LORA [6: 64, 7: 128, 8: 256, 9: 512, 10: 1024, 11: 2048, 12: 4096 chips]
  35. uint8_t ErrorCoding; // LORA [1: 4/5, 2: 4/6, 3: 4/7, 4: 4/8]
  36. bool CrcOn; // [0: OFF, 1: ON]
  37. bool ImplicitHeaderOn; // [0: OFF, 1: ON]
  38. bool RxSingleOn; // [0: Continuous, 1 Single]
  39. bool FreqHopOn; // [0: OFF, 1: ON]
  40. uint8_t HopPeriod; // Hops every frequency hopping period symbols
  41. uint32_t TxPacketTimeout;
  42. uint32_t RxPacketTimeout;
  43. uint8_t PayloadLength;
  44. }tLoRaSettings;
  45. /*!
  46. * RF packet definition
  47. */
  48. #define RF_BUFFER_SIZE_MAX 256
  49. #define RF_BUFFER_SIZE 256
  50. /*!
  51. * RF state machine
  52. */
  53. //LoRa
  54. typedef enum
  55. {
  56. RFLR_STATE_IDLE,
  57. RFLR_STATE_RX_INIT,
  58. RFLR_STATE_RX_RUNNING,
  59. RFLR_STATE_RX_DONE,
  60. RFLR_STATE_RX_TIMEOUT,
  61. RFLR_STATE_TX_INIT,
  62. RFLR_STATE_TX_RUNNING,
  63. RFLR_STATE_TX_DONE,
  64. RFLR_STATE_TX_TIMEOUT,
  65. RFLR_STATE_CAD_INIT,
  66. RFLR_STATE_CAD_RUNNING,
  67. }tRFLRStates;
  68. /*!
  69. * SX1276 definitions
  70. */
  71. #define XTAL_FREQ 32000000
  72. #define FREQ_STEP 61.03515625
  73. /*!
  74. * SX1276 Internal registers Address
  75. */
  76. #define REG_LR_FIFO 0x00
  77. // Common settings
  78. #define REG_LR_OPMODE 0x01
  79. #define REG_LR_BANDSETTING 0x04
  80. #define REG_LR_FRFMSB 0x06
  81. #define REG_LR_FRFMID 0x07
  82. #define REG_LR_FRFLSB 0x08
  83. // Tx settings
  84. #define REG_LR_PACONFIG 0x09
  85. #define REG_LR_PARAMP 0x0A
  86. #define REG_LR_OCP 0x0B
  87. // Rx settings
  88. #define REG_LR_LNA 0x0C
  89. // LoRa registers
  90. #define REG_LR_FIFOADDRPTR 0x0D
  91. #define REG_LR_FIFOTXBASEADDR 0x0E
  92. #define REG_LR_FIFORXBASEADDR 0x0F
  93. #define REG_LR_FIFORXCURRENTADDR 0x10
  94. #define REG_LR_IRQFLAGSMASK 0x11
  95. #define REG_LR_IRQFLAGS 0x12
  96. #define REG_LR_NBRXBYTES 0x13
  97. #define REG_LR_RXHEADERCNTVALUEMSB 0x14
  98. #define REG_LR_RXHEADERCNTVALUELSB 0x15
  99. #define REG_LR_RXPACKETCNTVALUEMSB 0x16
  100. #define REG_LR_RXPACKETCNTVALUELSB 0x17
  101. #define REG_LR_MODEMSTAT 0x18
  102. #define REG_LR_PKTSNRVALUE 0x19
  103. #define REG_LR_PKTRSSIVALUE 0x1A
  104. #define REG_LR_RSSIVALUE 0x1B
  105. #define REG_LR_HOPCHANNEL 0x1C
  106. #define REG_LR_MODEMCONFIG1 0x1D
  107. #define REG_LR_MODEMCONFIG2 0x1E
  108. #define REG_LR_SYMBTIMEOUTLSB 0x1F
  109. #define REG_LR_PREAMBLEMSB 0x20
  110. #define REG_LR_PREAMBLELSB 0x21
  111. #define REG_LR_PAYLOADLENGTH 0x22
  112. #define REG_LR_PAYLOADMAXLENGTH 0x23
  113. #define REG_LR_HOPPERIOD 0x24
  114. #define REG_LR_FIFORXBYTEADDR 0x25
  115. #define REG_LR_MODEMCONFIG3 0x26
  116. #define REG_LR_FEIMSB 0x28
  117. #define REG_LR_FEIMIB 0x29
  118. #define REG_LR_FEILSB 0x2A
  119. #define REG_LR_LORADETECTOPTIMIZE 0x31
  120. #define REG_LR_INVERTIQ 0x33
  121. #define REG_LR_DETECTIONTHRESHOLD 0x37
  122. // end of documented register in datasheet
  123. // I/O settings
  124. #define REG_LR_DIOMAPPING1 0x40
  125. #define REG_LR_DIOMAPPING2 0x41
  126. // Version
  127. #define REG_LR_VERSION 0x42
  128. // Additional settings
  129. #define REG_LR_PLLHOP 0x44
  130. #define REG_LR_TCXO 0x4B
  131. #define REG_LR_PADAC 0x4D
  132. #define REG_LR_FORMERTEMP 0x5B
  133. #define REG_LR_BITRATEFRAC 0x5D
  134. #define REG_LR_AGCREF 0x61
  135. #define REG_LR_AGCTHRESH1 0x62
  136. #define REG_LR_AGCTHRESH2 0x63
  137. #define REG_LR_AGCTHRESH3 0x64
  138. /*!
  139. * SX1276 LoRa bit control definition
  140. */
  141. /*!
  142. * RegFifo
  143. */
  144. /*!
  145. * RegOpMode
  146. */
  147. #define RFLR_OPMODE_LONGRANGEMODE_MASK 0x7F
  148. #define RFLR_OPMODE_LONGRANGEMODE_OFF 0x00 // Default
  149. #define RFLR_OPMODE_LONGRANGEMODE_ON 0x80
  150. #define RFLR_OPMODE_ACCESSSHAREDREG_MASK 0xBF
  151. #define RFLR_OPMODE_ACCESSSHAREDREG_ENABLE 0x40
  152. #define RFLR_OPMODE_ACCESSSHAREDREG_DISABLE 0x00 // Default
  153. #define RFLR_OPMODE_FREQMODE_ACCESS_MASK 0xF7
  154. #define RFLR_OPMODE_FREQMODE_ACCESS_LF 0x08 // Default
  155. #define RFLR_OPMODE_FREQMODE_ACCESS_HF 0x00
  156. #define RFLR_OPMODE_MASK 0xF8
  157. #define RFLR_OPMODE_SLEEP 0x00
  158. #define RFLR_OPMODE_STANDBY 0x01 // Default
  159. #define RFLR_OPMODE_SYNTHESIZER_TX 0x02
  160. #define RFLR_OPMODE_TRANSMITTER 0x03
  161. #define RFLR_OPMODE_SYNTHESIZER_RX 0x04
  162. #define RFLR_OPMODE_RECEIVER 0x05
  163. // LoRa specific modes
  164. #define RFLR_OPMODE_RECEIVER_SINGLE 0x06
  165. #define RFLR_OPMODE_CAD 0x07
  166. /*!
  167. * RegBandSetting
  168. */
  169. #define RFLR_BANDSETTING_MASK 0x3F
  170. #define RFLR_BANDSETTING_AUTO 0x00 // Default
  171. #define RFLR_BANDSETTING_DIV_BY_1 0x40
  172. #define RFLR_BANDSETTING_DIV_BY_2 0x80
  173. #define RFLR_BANDSETTING_DIV_BY_6 0xC0
  174. /*!
  175. * RegFrf (MHz)
  176. */
  177. #define RFLR_FRFMSB_434_MHZ 0x6C // Default
  178. #define RFLR_FRFMID_434_MHZ 0x80 // Default
  179. #define RFLR_FRFLSB_434_MHZ 0x00 // Default
  180. #define RFLR_FRFMSB_863_MHZ 0xD7
  181. #define RFLR_FRFMID_863_MHZ 0xC0
  182. #define RFLR_FRFLSB_863_MHZ 0x00
  183. #define RFLR_FRFMSB_864_MHZ 0xD8
  184. #define RFLR_FRFMID_864_MHZ 0x00
  185. #define RFLR_FRFLSB_864_MHZ 0x00
  186. #define RFLR_FRFMSB_865_MHZ 0xD8
  187. #define RFLR_FRFMID_865_MHZ 0x40
  188. #define RFLR_FRFLSB_865_MHZ 0x00
  189. #define RFLR_FRFMSB_866_MHZ 0xD8
  190. #define RFLR_FRFMID_866_MHZ 0x80
  191. #define RFLR_FRFLSB_866_MHZ 0x00
  192. #define RFLR_FRFMSB_867_MHZ 0xD8
  193. #define RFLR_FRFMID_867_MHZ 0xC0
  194. #define RFLR_FRFLSB_867_MHZ 0x00
  195. #define RFLR_FRFMSB_868_MHZ 0xD9
  196. #define RFLR_FRFMID_868_MHZ 0x00
  197. #define RFLR_FRFLSB_868_MHZ 0x00
  198. #define RFLR_FRFMSB_869_MHZ 0xD9
  199. #define RFLR_FRFMID_869_MHZ 0x40
  200. #define RFLR_FRFLSB_869_MHZ 0x00
  201. #define RFLR_FRFMSB_870_MHZ 0xD9
  202. #define RFLR_FRFMID_870_MHZ 0x80
  203. #define RFLR_FRFLSB_870_MHZ 0x00
  204. #define RFLR_FRFMSB_902_MHZ 0xE1
  205. #define RFLR_FRFMID_902_MHZ 0x80
  206. #define RFLR_FRFLSB_902_MHZ 0x00
  207. #define RFLR_FRFMSB_903_MHZ 0xE1
  208. #define RFLR_FRFMID_903_MHZ 0xC0
  209. #define RFLR_FRFLSB_903_MHZ 0x00
  210. #define RFLR_FRFMSB_904_MHZ 0xE2
  211. #define RFLR_FRFMID_904_MHZ 0x00
  212. #define RFLR_FRFLSB_904_MHZ 0x00
  213. #define RFLR_FRFMSB_905_MHZ 0xE2
  214. #define RFLR_FRFMID_905_MHZ 0x40
  215. #define RFLR_FRFLSB_905_MHZ 0x00
  216. #define RFLR_FRFMSB_906_MHZ 0xE2
  217. #define RFLR_FRFMID_906_MHZ 0x80
  218. #define RFLR_FRFLSB_906_MHZ 0x00
  219. #define RFLR_FRFMSB_907_MHZ 0xE2
  220. #define RFLR_FRFMID_907_MHZ 0xC0
  221. #define RFLR_FRFLSB_907_MHZ 0x00
  222. #define RFLR_FRFMSB_908_MHZ 0xE3
  223. #define RFLR_FRFMID_908_MHZ 0x00
  224. #define RFLR_FRFLSB_908_MHZ 0x00
  225. #define RFLR_FRFMSB_909_MHZ 0xE3
  226. #define RFLR_FRFMID_909_MHZ 0x40
  227. #define RFLR_FRFLSB_909_MHZ 0x00
  228. #define RFLR_FRFMSB_910_MHZ 0xE3
  229. #define RFLR_FRFMID_910_MHZ 0x80
  230. #define RFLR_FRFLSB_910_MHZ 0x00
  231. #define RFLR_FRFMSB_911_MHZ 0xE3
  232. #define RFLR_FRFMID_911_MHZ 0xC0
  233. #define RFLR_FRFLSB_911_MHZ 0x00
  234. #define RFLR_FRFMSB_912_MHZ 0xE4
  235. #define RFLR_FRFMID_912_MHZ 0x00
  236. #define RFLR_FRFLSB_912_MHZ 0x00
  237. #define RFLR_FRFMSB_913_MHZ 0xE4
  238. #define RFLR_FRFMID_913_MHZ 0x40
  239. #define RFLR_FRFLSB_913_MHZ 0x00
  240. #define RFLR_FRFMSB_914_MHZ 0xE4
  241. #define RFLR_FRFMID_914_MHZ 0x80
  242. #define RFLR_FRFLSB_914_MHZ 0x00
  243. #define RFLR_FRFMSB_915_MHZ 0xE4 // Default
  244. #define RFLR_FRFMID_915_MHZ 0xC0 // Default
  245. #define RFLR_FRFLSB_915_MHZ 0x00 // Default
  246. #define RFLR_FRFMSB_916_MHZ 0xE5
  247. #define RFLR_FRFMID_916_MHZ 0x00
  248. #define RFLR_FRFLSB_916_MHZ 0x00
  249. #define RFLR_FRFMSB_917_MHZ 0xE5
  250. #define RFLR_FRFMID_917_MHZ 0x40
  251. #define RFLR_FRFLSB_917_MHZ 0x00
  252. #define RFLR_FRFMSB_918_MHZ 0xE5
  253. #define RFLR_FRFMID_918_MHZ 0x80
  254. #define RFLR_FRFLSB_918_MHZ 0x00
  255. #define RFLR_FRFMSB_919_MHZ 0xE5
  256. #define RFLR_FRFMID_919_MHZ 0xC0
  257. #define RFLR_FRFLSB_919_MHZ 0x00
  258. #define RFLR_FRFMSB_920_MHZ 0xE6
  259. #define RFLR_FRFMID_920_MHZ 0x00
  260. #define RFLR_FRFLSB_920_MHZ 0x00
  261. #define RFLR_FRFMSB_921_MHZ 0xE6
  262. #define RFLR_FRFMID_921_MHZ 0x40
  263. #define RFLR_FRFLSB_921_MHZ 0x00
  264. #define RFLR_FRFMSB_922_MHZ 0xE6
  265. #define RFLR_FRFMID_922_MHZ 0x80
  266. #define RFLR_FRFLSB_922_MHZ 0x00
  267. #define RFLR_FRFMSB_923_MHZ 0xE6
  268. #define RFLR_FRFMID_923_MHZ 0xC0
  269. #define RFLR_FRFLSB_923_MHZ 0x00
  270. #define RFLR_FRFMSB_924_MHZ 0xE7
  271. #define RFLR_FRFMID_924_MHZ 0x00
  272. #define RFLR_FRFLSB_924_MHZ 0x00
  273. #define RFLR_FRFMSB_925_MHZ 0xE7
  274. #define RFLR_FRFMID_925_MHZ 0x40
  275. #define RFLR_FRFLSB_925_MHZ 0x00
  276. #define RFLR_FRFMSB_926_MHZ 0xE7
  277. #define RFLR_FRFMID_926_MHZ 0x80
  278. #define RFLR_FRFLSB_926_MHZ 0x00
  279. #define RFLR_FRFMSB_927_MHZ 0xE7
  280. #define RFLR_FRFMID_927_MHZ 0xC0
  281. #define RFLR_FRFLSB_927_MHZ 0x00
  282. #define RFLR_FRFMSB_928_MHZ 0xE8
  283. #define RFLR_FRFMID_928_MHZ 0x00
  284. #define RFLR_FRFLSB_928_MHZ 0x00
  285. /*!
  286. * RegPaConfig
  287. */
  288. #define RFLR_PACONFIG_PASELECT_MASK 0x7F
  289. #define RFLR_PACONFIG_PASELECT_PABOOST 0x80
  290. #define RFLR_PACONFIG_PASELECT_RFO 0x00 // Default
  291. #define RFLR_PACONFIG_MAX_POWER_MASK 0x8F
  292. #define RFLR_PACONFIG_OUTPUTPOWER_MASK 0xF0
  293. /*!
  294. * RegPaRamp
  295. */
  296. #define RFLR_PARAMP_TXBANDFORCE_MASK 0xEF
  297. #define RFLR_PARAMP_TXBANDFORCE_BAND_SEL 0x10
  298. #define RFLR_PARAMP_TXBANDFORCE_AUTO 0x00 // Default
  299. #define RFLR_PARAMP_MASK 0xF0
  300. #define RFLR_PARAMP_3400_US 0x00
  301. #define RFLR_PARAMP_2000_US 0x01
  302. #define RFLR_PARAMP_1000_US 0x02
  303. #define RFLR_PARAMP_0500_US 0x03
  304. #define RFLR_PARAMP_0250_US 0x04
  305. #define RFLR_PARAMP_0125_US 0x05
  306. #define RFLR_PARAMP_0100_US 0x06
  307. #define RFLR_PARAMP_0062_US 0x07
  308. #define RFLR_PARAMP_0050_US 0x08
  309. #define RFLR_PARAMP_0040_US 0x09 // Default
  310. #define RFLR_PARAMP_0031_US 0x0A
  311. #define RFLR_PARAMP_0025_US 0x0B
  312. #define RFLR_PARAMP_0020_US 0x0C
  313. #define RFLR_PARAMP_0015_US 0x0D
  314. #define RFLR_PARAMP_0012_US 0x0E
  315. #define RFLR_PARAMP_0010_US 0x0F
  316. /*!
  317. * RegOcp
  318. */
  319. #define RFLR_OCP_MASK 0xDF
  320. #define RFLR_OCP_ON 0x20 // Default
  321. #define RFLR_OCP_OFF 0x00
  322. #define RFLR_OCP_TRIM_MASK 0xE0
  323. #define RFLR_OCP_TRIM_045_MA 0x00
  324. #define RFLR_OCP_TRIM_050_MA 0x01
  325. #define RFLR_OCP_TRIM_055_MA 0x02
  326. #define RFLR_OCP_TRIM_060_MA 0x03
  327. #define RFLR_OCP_TRIM_065_MA 0x04
  328. #define RFLR_OCP_TRIM_070_MA 0x05
  329. #define RFLR_OCP_TRIM_075_MA 0x06
  330. #define RFLR_OCP_TRIM_080_MA 0x07
  331. #define RFLR_OCP_TRIM_085_MA 0x08
  332. #define RFLR_OCP_TRIM_090_MA 0x09
  333. #define RFLR_OCP_TRIM_095_MA 0x0A
  334. #define RFLR_OCP_TRIM_100_MA 0x0B // Default
  335. #define RFLR_OCP_TRIM_105_MA 0x0C
  336. #define RFLR_OCP_TRIM_110_MA 0x0D
  337. #define RFLR_OCP_TRIM_115_MA 0x0E
  338. #define RFLR_OCP_TRIM_120_MA 0x0F
  339. #define RFLR_OCP_TRIM_130_MA 0x10
  340. #define RFLR_OCP_TRIM_140_MA 0x11
  341. #define RFLR_OCP_TRIM_150_MA 0x12
  342. #define RFLR_OCP_TRIM_160_MA 0x13
  343. #define RFLR_OCP_TRIM_170_MA 0x14
  344. #define RFLR_OCP_TRIM_180_MA 0x15
  345. #define RFLR_OCP_TRIM_190_MA 0x16
  346. #define RFLR_OCP_TRIM_200_MA 0x17
  347. #define RFLR_OCP_TRIM_210_MA 0x18
  348. #define RFLR_OCP_TRIM_220_MA 0x19
  349. #define RFLR_OCP_TRIM_230_MA 0x1A
  350. #define RFLR_OCP_TRIM_240_MA 0x1B
  351. /*!
  352. * RegLna
  353. */
  354. #define RFLR_LNA_GAIN_MASK 0x1F
  355. #define RFLR_LNA_GAIN_G1 0x20 // Default
  356. #define RFLR_LNA_GAIN_G2 0x40
  357. #define RFLR_LNA_GAIN_G3 0x60
  358. #define RFLR_LNA_GAIN_G4 0x80
  359. #define RFLR_LNA_GAIN_G5 0xA0
  360. #define RFLR_LNA_GAIN_G6 0xC0
  361. #define RFLR_LNA_BOOST_LF_MASK 0xE7
  362. #define RFLR_LNA_BOOST_LF_DEFAULT 0x00 // Default
  363. #define RFLR_LNA_BOOST_LF_GAIN 0x08
  364. #define RFLR_LNA_BOOST_LF_IP3 0x10
  365. #define RFLR_LNA_BOOST_LF_BOOST 0x18
  366. #define RFLR_LNA_RXBANDFORCE_MASK 0xFB
  367. #define RFLR_LNA_RXBANDFORCE_BAND_SEL 0x04
  368. #define RFLR_LNA_RXBANDFORCE_AUTO 0x00 // Default
  369. #define RFLR_LNA_BOOST_HF_MASK 0xFC
  370. #define RFLR_LNA_BOOST_HF_OFF 0x00 // Default
  371. #define RFLR_LNA_BOOST_HF_ON 0x03
  372. /*!
  373. * RegFifoAddrPtr
  374. */
  375. #define RFLR_FIFOADDRPTR 0x00 // Default
  376. /*!
  377. * RegFifoTxBaseAddr
  378. */
  379. #define RFLR_FIFOTXBASEADDR 0x80 // Default
  380. /*!
  381. * RegFifoTxBaseAddr
  382. */
  383. #define RFLR_FIFORXBASEADDR 0x00 // Default
  384. /*!
  385. * RegFifoRxCurrentAddr (Read Only)
  386. */
  387. /*!
  388. * RegIrqFlagsMask
  389. */
  390. #define RFLR_IRQFLAGS_RXTIMEOUT_MASK 0x80
  391. #define RFLR_IRQFLAGS_RXDONE_MASK 0x40
  392. #define RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK 0x20
  393. #define RFLR_IRQFLAGS_VALIDHEADER_MASK 0x10
  394. #define RFLR_IRQFLAGS_TXDONE_MASK 0x08
  395. #define RFLR_IRQFLAGS_CADDONE_MASK 0x04
  396. #define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL_MASK 0x02
  397. #define RFLR_IRQFLAGS_CADDETECTED_MASK 0x01
  398. /*!
  399. * RegIrqFlags
  400. */
  401. #define RFLR_IRQFLAGS_RXTIMEOUT 0x80
  402. #define RFLR_IRQFLAGS_RXDONE 0x40
  403. #define RFLR_IRQFLAGS_PAYLOADCRCERROR 0x20
  404. #define RFLR_IRQFLAGS_VALIDHEADER 0x10
  405. #define RFLR_IRQFLAGS_TXDONE 0x08
  406. #define RFLR_IRQFLAGS_CADDONE 0x04
  407. #define RFLR_IRQFLAGS_FHSSCHANGEDCHANNEL 0x02
  408. #define RFLR_IRQFLAGS_CADDETECTED 0x01
  409. /*!
  410. * RegFifoRxNbBytes (Read Only) //
  411. */
  412. /*!
  413. * RegRxHeaderCntValueMsb (Read Only) //
  414. */
  415. /*!
  416. * RegRxHeaderCntValueLsb (Read Only) //
  417. */
  418. /*!
  419. * RegRxPacketCntValueMsb (Read Only) //
  420. */
  421. /*!
  422. * RegRxPacketCntValueLsb (Read Only) //
  423. */
  424. /*!
  425. * RegModemStat (Read Only) //
  426. */
  427. #define RFLR_MODEMSTAT_RX_CR_MASK 0x1F
  428. #define RFLR_MODEMSTAT_MODEM_STATUS_MASK 0xE0
  429. /*!
  430. * RegPktSnrValue (Read Only) //
  431. */
  432. /*!
  433. * RegPktRssiValue (Read Only) //
  434. */
  435. /*!
  436. * RegRssiValue (Read Only) //
  437. */
  438. /*!
  439. * RegHopChannel (Read Only) //
  440. */
  441. #define RFLR_HOP_CHANNEL_PAYLOAD_CRC_ON_MASK 0xBF
  442. #define RFLR_HOP_CHANNEL_PAYLOAD_CRC_ON 0x40
  443. #define RFLR_HOP_CHANNEL_PAYLOAD_CRC_OFF 0x00
  444. /*!
  445. * RegModemConfig1
  446. */
  447. #define RFLR_MODEMCONFIG1_BW_MASK 0x0F
  448. #define RFLR_MODEMCONFIG1_BW_7_81_KHZ 0x00
  449. #define RFLR_MODEMCONFIG1_BW_10_41_KHZ 0x10
  450. #define RFLR_MODEMCONFIG1_BW_15_62_KHZ 0x20
  451. #define RFLR_MODEMCONFIG1_BW_20_83_KHZ 0x30
  452. #define RFLR_MODEMCONFIG1_BW_31_25_KHZ 0x40
  453. #define RFLR_MODEMCONFIG1_BW_41_66_KHZ 0x50
  454. #define RFLR_MODEMCONFIG1_BW_62_50_KHZ 0x60
  455. #define RFLR_MODEMCONFIG1_BW_125_KHZ 0x70 // Default
  456. #define RFLR_MODEMCONFIG1_BW_250_KHZ 0x80
  457. #define RFLR_MODEMCONFIG1_BW_500_KHZ 0x90
  458. #define RFLR_MODEMCONFIG1_CODINGRATE_MASK 0xF1
  459. #define RFLR_MODEMCONFIG1_CODINGRATE_4_5 0x02
  460. #define RFLR_MODEMCONFIG1_CODINGRATE_4_6 0x04 // Default
  461. #define RFLR_MODEMCONFIG1_CODINGRATE_4_7 0x06
  462. #define RFLR_MODEMCONFIG1_CODINGRATE_4_8 0x08
  463. #define RFLR_MODEMCONFIG1_IMPLICITHEADER_MASK 0xFE
  464. #define RFLR_MODEMCONFIG1_IMPLICITHEADER_ON 0x01
  465. #define RFLR_MODEMCONFIG1_IMPLICITHEADER_OFF 0x00 // Default
  466. /*!
  467. * RegModemConfig2
  468. */
  469. #define RFLR_MODEMCONFIG2_SF_MASK 0x0F
  470. #define RFLR_MODEMCONFIG2_SF_6 0x60
  471. #define RFLR_MODEMCONFIG2_SF_7 0x70 // Default
  472. #define RFLR_MODEMCONFIG2_SF_8 0x80
  473. #define RFLR_MODEMCONFIG2_SF_9 0x90
  474. #define RFLR_MODEMCONFIG2_SF_10 0xA0
  475. #define RFLR_MODEMCONFIG2_SF_11 0xB0
  476. #define RFLR_MODEMCONFIG2_SF_12 0xC0
  477. #define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_MASK 0xF7
  478. #define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_ON 0x08
  479. #define RFLR_MODEMCONFIG2_TXCONTINUOUSMODE_OFF 0x00
  480. #define RFLR_MODEMCONFIG2_RXPAYLOADCRC_MASK 0xFB
  481. #define RFLR_MODEMCONFIG2_RXPAYLOADCRC_ON 0x04
  482. #define RFLR_MODEMCONFIG2_RXPAYLOADCRC_OFF 0x00 // Default
  483. #define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB_MASK 0xFC
  484. #define RFLR_MODEMCONFIG2_SYMBTIMEOUTMSB 0x00 // Default
  485. /*!
  486. * RegHopChannel (Read Only)
  487. */
  488. #define RFLR_HOPCHANNEL_PLL_LOCK_TIMEOUT_MASK 0x7F
  489. #define RFLR_HOPCHANNEL_PLL_LOCK_FAIL 0x80
  490. #define RFLR_HOPCHANNEL_PLL_LOCK_SUCCEED 0x00 // Default
  491. #define RFLR_HOPCHANNEL_PAYLOAD_CRC16_MASK 0xBF
  492. #define RFLR_HOPCHANNEL_PAYLOAD_CRC16_ON 0x40
  493. #define RFLR_HOPCHANNEL_PAYLOAD_CRC16_OFF 0x00 // Default
  494. #define RFLR_HOPCHANNEL_CHANNEL_MASK 0x3F
  495. /*!
  496. * RegSymbTimeoutLsb
  497. */
  498. #define RFLR_SYMBTIMEOUTLSB_SYMBTIMEOUT 0x64 // Default
  499. /*!
  500. * RegPreambleLengthMsb
  501. */
  502. #define RFLR_PREAMBLELENGTHMSB 0x00 // Default
  503. /*!
  504. * RegPreambleLengthLsb
  505. */
  506. #define RFLR_PREAMBLELENGTHLSB 0x08 // Default
  507. /*!
  508. * RegPayloadLength
  509. */
  510. #define RFLR_PAYLOADLENGTH 0x0E // Default
  511. /*!
  512. * RegPayloadMaxLength
  513. */
  514. #define RFLR_PAYLOADMAXLENGTH 0xFF // Default
  515. /*!
  516. * RegHopPeriod
  517. */
  518. #define RFLR_HOPPERIOD_FREQFOPPINGPERIOD 0x00 // Default
  519. /*!
  520. * RegDioMapping1
  521. */
  522. #define RFLR_DIOMAPPING1_DIO0_MASK 0x3F
  523. #define RFLR_DIOMAPPING1_DIO0_00 0x00 // Default
  524. #define RFLR_DIOMAPPING1_DIO0_01 0x40
  525. #define RFLR_DIOMAPPING1_DIO0_10 0x80
  526. #define RFLR_DIOMAPPING1_DIO0_11 0xC0
  527. #define RFLR_DIOMAPPING1_DIO1_MASK 0xCF
  528. #define RFLR_DIOMAPPING1_DIO1_00 0x00 // Default
  529. #define RFLR_DIOMAPPING1_DIO1_01 0x10
  530. #define RFLR_DIOMAPPING1_DIO1_10 0x20
  531. #define RFLR_DIOMAPPING1_DIO1_11 0x30
  532. #define RFLR_DIOMAPPING1_DIO2_MASK 0xF3
  533. #define RFLR_DIOMAPPING1_DIO2_00 0x00 // Default
  534. #define RFLR_DIOMAPPING1_DIO2_01 0x04
  535. #define RFLR_DIOMAPPING1_DIO2_10 0x08
  536. #define RFLR_DIOMAPPING1_DIO2_11 0x0C
  537. #define RFLR_DIOMAPPING1_DIO3_MASK 0xFC
  538. #define RFLR_DIOMAPPING1_DIO3_00 0x00 // Default
  539. #define RFLR_DIOMAPPING1_DIO3_01 0x01
  540. #define RFLR_DIOMAPPING1_DIO3_10 0x02
  541. #define RFLR_DIOMAPPING1_DIO3_11 0x03
  542. /*!
  543. * RegDioMapping2
  544. */
  545. #define RFLR_DIOMAPPING2_DIO4_MASK 0x3F
  546. #define RFLR_DIOMAPPING2_DIO4_00 0x00 // Default
  547. #define RFLR_DIOMAPPING2_DIO4_01 0x40
  548. #define RFLR_DIOMAPPING2_DIO4_10 0x80
  549. #define RFLR_DIOMAPPING2_DIO4_11 0xC0
  550. #define RFLR_DIOMAPPING2_DIO5_MASK 0xCF
  551. #define RFLR_DIOMAPPING2_DIO5_00 0x00 // Default
  552. #define RFLR_DIOMAPPING2_DIO5_01 0x10
  553. #define RFLR_DIOMAPPING2_DIO5_10 0x20
  554. #define RFLR_DIOMAPPING2_DIO5_11 0x30
  555. #define RFLR_DIOMAPPING2_MAP_MASK 0xFE
  556. #define RFLR_DIOMAPPING2_MAP_PREAMBLEDETECT 0x01
  557. #define RFLR_DIOMAPPING2_MAP_RSSI 0x00 // Default
  558. /*!
  559. * RegVersion (Read Only)
  560. */
  561. /*!
  562. * RegAgcRef
  563. */
  564. /*!
  565. * RegAgcThresh1
  566. */
  567. /*!
  568. * RegAgcThresh2
  569. */
  570. /*!
  571. * RegAgcThresh3
  572. */
  573. /*!
  574. * RegFifoRxByteAddr (Read Only)
  575. */
  576. /*!
  577. * RegPllHop
  578. */
  579. #define RFLR_PLLHOP_FASTHOP_MASK 0x7F
  580. #define RFLR_PLLHOP_FASTHOP_ON 0x80
  581. #define RFLR_PLLHOP_FASTHOP_OFF 0x00 // Default
  582. /*!
  583. * RegTcxo
  584. */
  585. #define RFLR_TCXO_TCXOINPUT_MASK 0xEF
  586. #define RFLR_TCXO_TCXOINPUT_ON 0x10
  587. #define RFLR_TCXO_TCXOINPUT_OFF 0x00 // Default
  588. /*!
  589. * RegPaDac
  590. */
  591. #define RFLR_PADAC_20DBM_MASK 0xF8
  592. #define RFLR_PADAC_20DBM_ON 0x07
  593. #define RFLR_PADAC_20DBM_OFF 0x04 // Default
  594. /*!
  595. * RegPll
  596. */
  597. #define RFLR_PLL_BANDWIDTH_MASK 0x3F
  598. #define RFLR_PLL_BANDWIDTH_75 0x00
  599. #define RFLR_PLL_BANDWIDTH_150 0x40
  600. #define RFLR_PLL_BANDWIDTH_225 0x80
  601. #define RFLR_PLL_BANDWIDTH_300 0xC0 // Default
  602. /*!
  603. * RegPllLowPn
  604. */
  605. #define RFLR_PLLLOWPN_BANDWIDTH_MASK 0x3F
  606. #define RFLR_PLLLOWPN_BANDWIDTH_75 0x00
  607. #define RFLR_PLLLOWPN_BANDWIDTH_150 0x40
  608. #define RFLR_PLLLOWPN_BANDWIDTH_225 0x80
  609. #define RFLR_PLLLOWPN_BANDWIDTH_300 0xC0 // Default
  610. /*!
  611. * RegModemConfig3
  612. */
  613. #define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_MASK 0xF7
  614. #define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_ON 0x08
  615. #define RFLR_MODEMCONFIG3_LOWDATARATEOPTIMIZE_OFF 0x00 // Default
  616. #define RFLR_MODEMCONFIG3_AGCAUTO_MASK 0xFB
  617. #define RFLR_MODEMCONFIG3_AGCAUTO_ON 0x04 // Default
  618. #define RFLR_MODEMCONFIG3_AGCAUTO_OFF 0x00
  619. /*!
  620. * RegFormerTemp
  621. */
  622. typedef struct sSX1276LR
  623. {
  624. uint8_t RegFifo; // 0x00
  625. // Common settings
  626. uint8_t RegOpMode; // 0x01
  627. uint8_t RegRes02; // 0x02
  628. uint8_t RegRes03; // 0x03
  629. uint8_t RegBandSetting; // 0x04
  630. uint8_t RegRes05; // 0x05
  631. uint8_t RegFrfMsb; // 0x06
  632. uint8_t RegFrfMid; // 0x07
  633. uint8_t RegFrfLsb; // 0x08
  634. // Tx settings
  635. uint8_t RegPaConfig; // 0x09
  636. uint8_t RegPaRamp; // 0x0A
  637. uint8_t RegOcp; // 0x0B
  638. // Rx settings
  639. uint8_t RegLna; // 0x0C
  640. // LoRa registers
  641. uint8_t RegFifoAddrPtr; // 0x0D
  642. uint8_t RegFifoTxBaseAddr; // 0x0E
  643. uint8_t RegFifoRxBaseAddr; // 0x0F
  644. uint8_t RegFifoRxCurrentAddr; // 0x10
  645. uint8_t RegIrqFlagsMask; // 0x11
  646. uint8_t RegIrqFlags; // 0x12
  647. uint8_t RegNbRxBytes; // 0x13
  648. uint8_t RegRxHeaderCntValueMsb; // 0x14
  649. uint8_t RegRxHeaderCntValueLsb; // 0x15
  650. uint8_t RegRxPacketCntValueMsb; // 0x16
  651. uint8_t RegRxPacketCntValueLsb; // 0x17
  652. uint8_t RegModemStat; // 0x18
  653. uint8_t RegPktSnrValue; // 0x19
  654. uint8_t RegPktRssiValue; // 0x1A
  655. uint8_t RegRssiValue; // 0x1B
  656. uint8_t RegHopChannel; // 0x1C
  657. uint8_t RegModemConfig1; // 0x1D
  658. uint8_t RegModemConfig2; // 0x1E
  659. uint8_t RegSymbTimeoutLsb; // 0x1F
  660. uint8_t RegPreambleMsb; // 0x20
  661. uint8_t RegPreambleLsb; // 0x21
  662. uint8_t RegPayloadLength; // 0x22
  663. uint8_t RegMaxPayloadLength; // 0x23
  664. uint8_t RegHopPeriod; // 0x24
  665. uint8_t RegFifoRxByteAddr; // 0x25
  666. uint8_t RegModemConfig3; // 0x26
  667. uint8_t RegTestReserved27; // 0x27
  668. uint8_t RegFeiMsb; // 0x28
  669. uint8_t RegFeiMib; // 0x29
  670. uint8_t RegFeiLsb; // 0x2A
  671. uint8_t RegTestReserved2B[0x30 - 0x2B]; // 0x2B-0x30
  672. uint8_t RegDetectOptimize; // 0x31
  673. uint8_t RegTestReserved32; // 0x32
  674. uint8_t RegInvertIQ; // 0x33
  675. uint8_t RegTestReserved34[0x36 - 0x34]; // 0x34-0x36
  676. uint8_t RegDetectionThreshold; // 0x37
  677. uint8_t RegTestReserved38[0x3F - 0x38]; // 0x38-0x3F
  678. // I/O settings
  679. uint8_t RegDioMapping1; // 0x40
  680. uint8_t RegDioMapping2; // 0x41
  681. // Version
  682. uint8_t RegVersion; // 0x42
  683. // Test
  684. uint8_t RegTestReserved43; // 0x43
  685. // Additional settings
  686. uint8_t RegPllHop; // 0x44
  687. // Test
  688. uint8_t RegTestReserved45[0x4A - 0x45]; // 0x45-0x4A
  689. // Additional settings
  690. uint8_t RegTcxo; // 0x4B
  691. // Test
  692. uint8_t RegTestReserved4C; // 0x4C
  693. // Additional settings
  694. uint8_t RegPaDac; // 0x4D
  695. // Test
  696. uint8_t RegTestReserved4E[0x5A - 0x4E]; // 0x4E-0x5A
  697. // Additional settings
  698. uint8_t RegFormerTemp; // 0x5B
  699. // Test
  700. uint8_t RegTestReserved5C; // 0x5C
  701. // Additional settings
  702. uint8_t RegBitrateFrac; // 0x5D
  703. // Additional settings
  704. uint8_t RegTestReserved5E[0x60 - 0x5E]; // 0x5E-0x60
  705. // Additional settings
  706. uint8_t RegAgcRef; // 0x60
  707. uint8_t RegAgcThresh1; // 0x61
  708. uint8_t RegAgcThresh2; // 0x62
  709. uint8_t RegAgcThresh3; // 0x63
  710. // Test
  711. uint8_t RegTestReserved64[0x70 - 0x64]; // 0x64-0x70
  712. }tSX1276LR;
  713. extern tSX1276LR* SX1276LR;
  714. /*!
  715. * \brief Initializes the SX1276
  716. */
  717. void SX1276LoRaInit( void );
  718. /*!
  719. * \brief Sets the SX1276 to datasheet default values
  720. */
  721. void SX1276LoRaSetDefaults( void );
  722. /*!
  723. * \brief Enables/Disables the LoRa modem
  724. *
  725. * \param [IN]: enable [true, false]
  726. */
  727. void SX1276LoRaSetLoRaOn( bool enable );
  728. /*!
  729. * \brief Sets the SX1276 operating mode
  730. *
  731. * \param [IN] opMode New operating mode
  732. */
  733. void SX1276LoRaSetOpMode( uint8_t opMode );
  734. /*!
  735. * \brief Gets the SX1276 operating mode
  736. *
  737. * \retval opMode Current operating mode
  738. */
  739. uint8_t SX1276LoRaGetOpMode( void );
  740. /*!
  741. * \brief Reads the current Rx gain setting
  742. *
  743. * \retval rxGain Current gain setting
  744. */
  745. uint8_t SX1276LoRaReadRxGain( void );
  746. /*!
  747. * \brief Trigs and reads the current RSSI value
  748. *
  749. * \retval rssiValue Current RSSI value in [dBm]
  750. */
  751. double SX1276LoRaReadRssi( void );
  752. /*!
  753. * \brief Gets the Rx gain value measured while receiving the packet
  754. *
  755. * \retval rxGainValue Current Rx gain value
  756. */
  757. uint8_t SX1276LoRaGetPacketRxGain( void );
  758. /*!
  759. * \brief Gets the SNR value measured while receiving the packet
  760. *
  761. * \retval snrValue Current SNR value in [dB]
  762. */
  763. int8_t SX1276LoRaGetPacketSnr( void );
  764. /*!
  765. * \brief Gets the RSSI value measured while receiving the packet
  766. *
  767. * \retval rssiValue Current RSSI value in [dBm]
  768. */
  769. double SX1276LoRaGetPacketRssi( void );
  770. /*!
  771. * \brief Sets the radio in Rx mode. Waiting for a packet
  772. */
  773. void SX1276LoRaStartRx( void );
  774. /*!
  775. * \brief Gets a copy of the current received buffer
  776. *
  777. * \param [IN]: buffer Buffer pointer
  778. * \param [IN]: size Buffer size
  779. */
  780. void SX1276LoRaGetRxPacket( void *buffer, uint16_t *size );
  781. /*!
  782. * \brief Sets a copy of the buffer to be transmitted
  783. *
  784. * \param [IN]: buffer Buffer pointer
  785. * \param [IN]: size Buffer size
  786. */
  787. void SX1276LoRaSetTxPacket( const void *buffer, uint16_t size );
  788. /*!
  789. * \brief Gets the current RFState
  790. *
  791. * \retval rfState Current RF state [RF_IDLE, RF_BUSY,
  792. * RF_RX_DONE, RF_RX_TIMEOUT,
  793. * RF_TX_DONE, RF_TX_TIMEOUT]
  794. */
  795. uint8_t SX1276LoRaGetRFState( void );
  796. /*!
  797. * \brief Sets the new state of the RF state machine
  798. *
  799. * \param [IN]: state New RF state machine state
  800. */
  801. void SX1276LoRaSetRFState( uint8_t state );
  802. /*!
  803. * \brief Process the LoRa modem Rx and Tx state machines depending on the
  804. * SX1276 operating mode.
  805. *
  806. * \retval rfState Current RF state [RF_IDLE, RF_BUSY,
  807. * RF_RX_DONE, RF_RX_TIMEOUT,
  808. * RF_TX_DONE, RF_TX_TIMEOUT]
  809. */
  810. uint32_t SX1276LoRaProcess( void );
  811. #endif //__SX1276_LORA_H__