├── .gitattributes ├── .gitignore ├── Changelog.txt ├── License.txt ├── README.md ├── examples ├── callbacks_irq │ └── callbacks_irq.ino ├── debug │ └── debug.ino ├── lowpwr_node_baseStation │ └── lowpwr_node_baseStation.ino ├── lowpwr_node_sensor │ └── lowpwr_node_sensor.ino ├── ping_client │ └── ping_client.ino ├── ping_server │ └── ping_server.ino └── wirelessSerialLink │ └── wirelessSerialLink.ino ├── extras └── Product_Specification_nRF905_v1.5.pdf ├── keywords.txt ├── library.json ├── library.properties └── src ├── nRF905.cpp ├── nRF905.h ├── nRF905_config.h └── nRF905_defs.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /Changelog.txt: -------------------------------------------------------------------------------- 1 | 2020-11-02: 2 | - Version 4.0.2 3 | - No real changes, just needed to fix release versioning on GitHub 4 | 5 | 2020-11-01: 6 | - Version 4.0.1 7 | - Fixed issue with SPI.usingInterrupts() not being supported on ESP platforms 8 | 9 | 2020-11-01: 10 | - Version 4.0.0 11 | - Re-written in C++ with full Arduino compatibility. Original AVR C version can be found here https://github.com/zkemble/nRF905 12 | 13 | 2020-10-01: 14 | - Version 3.1.0 15 | - Added all callbacks example 16 | - Added some MCU autodetection for setting up the SPI pins 17 | - Added functions to individually set RX and TX payload sizes 18 | 19 | 2017-09-12: 20 | - Version 3 21 | - Simpified the library API 22 | - Now uses callbacks for when events occur (valid packet received, invalid packet received, address match, transmission complete). 23 | - Now uses Arduino interrupt handling when using the library in the Arduino environment 24 | - And various other things 25 | 26 | 2015-08-31: 27 | - Added ability to read config registers, mainly for debugging 28 | - Fixed issue with non-Arduino version where using a pin other than B2 for SPI SS wouldn't work 29 | 30 | 2014-01-20: 31 | - Tons of fixes, improvements, generally works much better 32 | 33 | 2013-01-18: 34 | - Removed ISR_NOBLOCK attribute from ISR 35 | 36 | 2013-01-20: 37 | - Bug fix: Destination and source were the wrong way round in memcpy() 38 | 39 | 2013-01-05: 40 | - Minor optimisation (~14bytes smaller, probably uses fewer CPU cycles) 41 | 42 | 2013-01-04: 43 | - Instead of disabling global interrupts when using SPI, just the pin change interrupt for DR is disabled. 44 | - Couldn't compile with interrupts disabled. 45 | - Putting module into receive mode was done in the wrong place in the non-arduino examples. 46 | 47 | 2013-01-01: 48 | - Initial release 49 | -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nRF905 Arduino Library 2 | ====================== 3 | 4 | [Nordic nRF905](http://www.nordicsemi.com/eng/Products/Sub-1-GHz-RF/nRF905) Radio library for Arduino. 5 | 6 | For an AVR C version of the library see [HERE](https://github.com/zkemble/nRF905). 7 | 8 | https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 9 | 10 | Documentation 11 | ------------- 12 | 13 | [Doxygen pages](http://zkemble.github.io/nRF905-arduino/) 14 | 15 | --- 16 | 17 | Zak Kemble 18 | 19 | contact@zakkemble.net 20 | -------------------------------------------------------------------------------- /examples/callbacks_irq/callbacks_irq.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Project: nRF905 AVR/Arduino Library/Driver (Callbacks example) 3 | * Author: Zak Kemble, contact@zakkemble.co.uk 4 | * Copyright: (C) 2017 by Zak Kemble 5 | * License: GNU GPL v3 (see License.txt) 6 | * Web: http://blog.zakkemble.co.uk/nrf905-avrarduino-librarydriver/ 7 | */ 8 | 9 | // 10 | // DONT USE THIS EXAMPLE, IT STILL NEEDS TO BE UPDATED FOR THE NEW VERSION OF THE NRF905 LIBRARY (v4) 11 | // 12 | 13 | /* 14 | * Example showing all callbacks and turning IRQ off and on 15 | */ 16 | 17 | #include 18 | 19 | #define RXADDR 0xE7E7E7E7 20 | #define TXADDR 0xE7E7E7E7 21 | 22 | // The NRF905_CB_RXCOMPLETE callback is ran once the packet has been received and is valid 23 | void NRF905_CB_RXCOMPLETE(void) 24 | { 25 | // Clear payload 26 | uint8_t buffer[NRF905_MAX_PAYLOAD]; 27 | nRF905_read(buffer, sizeof(buffer)); 28 | 29 | // Printing to serial inside an interrupt is bad! 30 | // If the serial buffer fills up the program will lock up! 31 | // Don't do this in your program, this only works here because we're not printing too much data 32 | Serial.println(F("Got packet")); 33 | } 34 | 35 | // If NRF905_INTERRUPTS_AM is 1 in nRF905_config.h then the NRF905_CB_RXINVALID callback is ran once the packet has been received, but was corrupted (CRC failed) 36 | void NRF905_CB_RXINVALID(void) 37 | { 38 | // Printing to serial inside an interrupt is bad! 39 | // If the serial buffer fills up the program will lock up! 40 | // Don't do this in your program, this only works here because we're not printing too much data 41 | Serial.println(F("Packet CRC failed")); 42 | } 43 | 44 | // If NRF905_INTERRUPTS_AM is 1 in nRF905_config.h then the NRF905_CB_ADDRMATCH callback is ran when the beginning of a new packet is detected (after a valid preamble and matching address) 45 | void NRF905_CB_ADDRMATCH(void) 46 | { 47 | // Printing to serial inside an interrupt is bad! 48 | // If the serial buffer fills up the program will lock up! 49 | // Don't do this in your program, this only works here because we're not printing too much data 50 | Serial.println(F("Incoming packet")); 51 | } 52 | 53 | // The NRF905_CB_TXCOMPLETE callback is ran when a packet has finished transmitting 54 | // This callback only works if the next mode is set to NRF905_NEXTMODE_STANDBY when calling nRF905_TX() 55 | void NRF905_CB_TXCOMPLETE(void) 56 | { 57 | // Printing to serial inside an interrupt is bad! 58 | // If the serial buffer fills up the program will lock up! 59 | // Don't do this in your program, this only works here because we're not printing too much data 60 | Serial.println(F("Packet sent")); 61 | } 62 | 63 | void setup() 64 | { 65 | Serial.begin(115200); 66 | 67 | // Start up 68 | nRF905_init(); 69 | 70 | nRF905_RX(); 71 | } 72 | 73 | void loop() 74 | { 75 | static uint8_t testData[] = { 76 | 2, 77 | 3, 78 | 4, 79 | 5, 80 | 6, 81 | 7 82 | }; 83 | 84 | // Transmit some data every 500ms 85 | delay(500); 86 | 87 | nRF905_TX(TXADDR, testData, sizeof(testData), NRF905_NEXTMODE_STANDBY); // Transmit and go to standby mode once sent (the NRF905_CB_TXCOMPLETE callback only works if the next mode is standby) 88 | testData[0]++; 89 | 90 | // We're about to print some stuff to serial, however the callbacks also print to serial. The callbacks are ran from an interrupt which could run at any time (like in the middle of printing out the serial message below). 91 | // To make sure the callbacks don't run we temporarily turn the radio interrupt off. 92 | // When communicating with other SPI devices on the same bus as the radio then you should also wrap those sections in an NRF905_NO_INTERRUPT() block, this will stop the nRF905 interrupt from running and trying to use the bus at the same time. 93 | 94 | NRF905_NO_INTERRUPT() 95 | { 96 | // Print the message 97 | Serial.println(F("Packet send begin")); 98 | } 99 | // Radio interrupt is now back on, any callbacks waiting will now run 100 | } 101 | -------------------------------------------------------------------------------- /examples/debug/debug.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Project: nRF905 Radio Library for Arduino (Debug example) 3 | * Author: Zak Kemble, contact@zakkemble.net 4 | * Copyright: (C) 2020 by Zak Kemble 5 | * License: GNU GPL v3 (see License.txt) 6 | * Web: https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 7 | */ 8 | 9 | /* 10 | * Read configuration registers 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | nRF905 transceiver = nRF905(); 18 | 19 | // Don't modify these 2 functions. They just pass the DR/AM interrupt to the correct nRF905 instance. 20 | void nRF905_int_dr(){transceiver.interrupt_dr();} 21 | void nRF905_int_am(){transceiver.interrupt_am();} 22 | 23 | void setup() 24 | { 25 | Serial.begin(115200); 26 | 27 | SPI.begin(); 28 | 29 | transceiver.begin( 30 | SPI, // SPI bus to use (SPI, SPI1, SPI2 etc) 31 | 10000000, // SPI Clock speed (10MHz) 32 | 6, // SPI SS 33 | 7, // CE (standby) 34 | 9, // TRX (RX/TX mode) 35 | 8, // PWR (power down) 36 | 4, // CD (collision avoid) 37 | 3, // DR (data ready) 38 | 2, // AM (address match) 39 | nRF905_int_dr, // Interrupt function for DR 40 | nRF905_int_am // Interrupt function for AM 41 | ); 42 | 43 | Serial.println(F("Started")); 44 | } 45 | 46 | void loop() 47 | { 48 | byte regs[NRF905_REGISTER_COUNT]; 49 | transceiver.getConfigRegisters(regs); 50 | 51 | Serial.print(F("Raw: ")); 52 | 53 | byte dataInvalid = 0; 54 | 55 | for(byte i=0;i= NRF905_REGISTER_COUNT) 67 | { 68 | Serial.println(F("All registers read as 0xFF or 0x00! Is the nRF905 connected correctly?")); 69 | delay(1000); 70 | return; 71 | } 72 | 73 | char* str; 74 | byte data; 75 | 76 | uint16_t channel = ((uint16_t)(regs[1] & 0x01)<<8) | regs[0]; 77 | uint32_t freq = (422400UL + (channel * 100UL)) * (1 + ((regs[1] & ~NRF905_MASK_BAND) >> 1)); 78 | 79 | Serial.print(F("Channel: ")); 80 | Serial.println(channel); 81 | Serial.print(F("Freq: ")); 82 | Serial.print(freq); 83 | Serial.println(F(" KHz")); 84 | Serial.print(F("Auto retransmit: ")); 85 | Serial.println((regs[1] & ~NRF905_MASK_AUTO_RETRAN) ? F("Enabled") : F("Disabled")); 86 | Serial.print(F("Low power RX: ")); 87 | Serial.println((regs[1] & ~NRF905_MASK_LOW_RX) ? F("Enabled") : F("Disabled")); 88 | 89 | // TX power 90 | data = regs[1] & ~NRF905_MASK_PWR; 91 | switch(data) 92 | { 93 | case NRF905_PWR_n10: 94 | data = -10; 95 | break; 96 | case NRF905_PWR_n2: 97 | data = -2; 98 | break; 99 | case NRF905_PWR_6: 100 | data = 6; 101 | break; 102 | case NRF905_PWR_10: 103 | data = 10; 104 | break; 105 | default: 106 | data = -127; 107 | break; 108 | } 109 | Serial.print(F("TX Power: ")); 110 | Serial.print((signed char)data); 111 | Serial.println(F(" dBm")); 112 | 113 | // Freq band 114 | data = regs[1] & ~NRF905_MASK_BAND; 115 | switch(data) 116 | { 117 | case NRF905_BAND_433: 118 | str = (char*)"433"; 119 | break; 120 | default: 121 | str = (char*)"868/915"; 122 | break; 123 | } 124 | Serial.print(F("Band: ")); 125 | Serial.print(str); 126 | Serial.println(F(" MHz")); 127 | 128 | Serial.print(F("TX Address width: ")); 129 | Serial.println(regs[2] >> 4); 130 | Serial.print(F("RX Address width: ")); 131 | Serial.println(regs[2] & 0x07); 132 | 133 | Serial.print(F("RX Payload size: ")); 134 | Serial.println(regs[3]); 135 | Serial.print(F("TX Payload size: ")); 136 | Serial.println(regs[4]); 137 | 138 | Serial.print(F("RX Address [0]: ")); 139 | Serial.println(regs[5]); 140 | Serial.print(F("RX Address [1]: ")); 141 | Serial.println(regs[6]); 142 | Serial.print(F("RX Address [2]: ")); 143 | Serial.println(regs[7]); 144 | Serial.print(F("RX Address [3]: ")); 145 | Serial.println(regs[8]); 146 | Serial.print(F("RX Address: ")); 147 | Serial.println(((unsigned long)regs[8]<<24 | (unsigned long)regs[7]<<16 | (unsigned long)regs[6]<<8 | (unsigned long)regs[5])); 148 | 149 | // CRC mode 150 | data = regs[9] & ~NRF905_MASK_CRC; 151 | switch(data) 152 | { 153 | case NRF905_CRC_16: 154 | str = (char*)"16 bit"; 155 | break; 156 | case NRF905_CRC_8: 157 | str = (char*)"8 bit"; 158 | break; 159 | default: 160 | str = (char*)"Disabled"; 161 | break; 162 | } 163 | Serial.print(F("CRC Mode: ")); 164 | Serial.println(str); 165 | 166 | // Xtal freq 167 | data = regs[9] & ~NRF905_MASK_CLK; 168 | switch(data) 169 | { 170 | case NRF905_CLK_4MHZ: 171 | data = 4; 172 | break; 173 | case NRF905_CLK_8MHZ: 174 | data = 8; 175 | break; 176 | case NRF905_CLK_12MHZ: 177 | data = 12; 178 | break; 179 | case NRF905_CLK_16MHZ: 180 | data = 16; 181 | break; 182 | case NRF905_CLK_20MHZ: 183 | data = 20; 184 | break; 185 | default: 186 | data = 0; 187 | break; 188 | } 189 | Serial.print(F("Xtal freq: ")); 190 | Serial.print(data); 191 | Serial.println(" MHz"); 192 | 193 | // Clock out freq 194 | data = regs[9] & ~NRF905_MASK_OUTCLK; 195 | switch(data) 196 | { 197 | case NRF905_OUTCLK_4MHZ: 198 | str = (char*)"4 MHz"; 199 | break; 200 | case NRF905_OUTCLK_2MHZ: 201 | str = (char*)"2 MHz"; 202 | break; 203 | case NRF905_OUTCLK_1MHZ: 204 | str = (char*)"1 MHz"; 205 | break; 206 | case NRF905_OUTCLK_500KHZ: 207 | str = (char*)"500 KHz"; 208 | break; 209 | default: 210 | str = (char*)"Disabled"; 211 | break; 212 | } 213 | Serial.print(F("Clock out freq: ")); 214 | Serial.println(str); 215 | 216 | Serial.println(F("---------------------")); 217 | 218 | delay(1000); 219 | } 220 | -------------------------------------------------------------------------------- /examples/lowpwr_node_baseStation/lowpwr_node_baseStation.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Project: nRF905 Radio Library for Arduino (Low power node base station example) 3 | * Author: Zak Kemble, contact@zakkemble.net 4 | * Copyright: (C) 2020 by Zak Kemble 5 | * License: GNU GPL v3 (see License.txt) 6 | * Web: https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 7 | */ 8 | 9 | // This examples requires the low power library from https://github.com/rocketscream/Low-Power 10 | 11 | // This examples configures the nRF905 library to only use 5 connections: 12 | // MOSI 13 | // MISO 14 | // SCK 15 | // SS -> 6 16 | // DR -> 3 17 | 18 | // The following pins on the nRF905 must be connected to VCC (3.3V) or GND: 19 | // CE (TRX_EN) -> VCC 20 | // TXE (TX_EN) -> GND 21 | // PWR -> VCC 22 | 23 | // The nRF905 will always be in low-power receive mode, waiting for packets from sensor nodes. 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #define BASE_STATION_ADDR 0xE7E7E7E7 30 | #define PAYLOAD_SIZE NRF905_MAX_PAYLOAD 31 | #define LED A5 32 | 33 | #define PACKET_NONE 0 34 | #define PACKET_OK 1 35 | #define PACKET_INVALID 2 36 | 37 | nRF905 transceiver = nRF905(); 38 | 39 | static volatile uint8_t packetStatus; // NOTE: In interrupt mode this must be volatile 40 | 41 | void nRF905_int_dr(){transceiver.interrupt_dr();} 42 | 43 | void nRF905_onRxComplete(nRF905* device) 44 | { 45 | packetStatus = PACKET_OK; 46 | } 47 | 48 | void nRF905_onRxInvalid(nRF905* device) 49 | { 50 | packetStatus = PACKET_INVALID; 51 | } 52 | 53 | void setup() 54 | { 55 | Serial.begin(115200); 56 | Serial.println(F("Base station starting...")); 57 | 58 | pinMode(LED, OUTPUT); 59 | 60 | 61 | // standby off TODO 62 | //pinMode(7, OUTPUT); 63 | //digitalWrite(7, HIGH); 64 | // pwr 65 | //pinMode(8, OUTPUT); 66 | //digitalWrite(8, HIGH); 67 | // trx 68 | //pinMode(9, OUTPUT); 69 | //digitalWrite(9, LOW); 70 | 71 | 72 | // This must be called first 73 | SPI.begin(); 74 | 75 | // Minimal wires (interrupt mode) 76 | transceiver.begin( 77 | SPI, 78 | 10000000, 79 | 6, 80 | NRF905_PIN_UNUSED, // CE (standby) pin must be connected to VCC (3.3V) 81 | NRF905_PIN_UNUSED, // TRX (RX/TX mode) pin must be connected to GND (force RX mode) 82 | NRF905_PIN_UNUSED, // PWR (power-down) pin must be connected to VCC (3.3V) 83 | NRF905_PIN_UNUSED, // Without the CD pin collision avoidance will be disabled 84 | 3, // DR 85 | NRF905_PIN_UNUSED, // Without the AM pin the library the library must poll the status register over SPI. 86 | nRF905_int_dr, 87 | NULL // No interrupt function 88 | ); 89 | 90 | // Register event functions 91 | // NOTE: In interrupt mode these events will run from the interrupt, so any global variables accessed inside the event function should be declared 'volatile'. 92 | // Also avoid doing things in the event functions that take a long time to complete or things that rely on interrupts (delay(), millis(), Serial.print())). 93 | transceiver.events( 94 | nRF905_onRxComplete, 95 | nRF905_onRxInvalid, 96 | NULL, 97 | NULL 98 | ); 99 | 100 | transceiver.setLowRxPower(true); 101 | 102 | Serial.println(F("Base station started")); 103 | } 104 | 105 | void loop() 106 | { 107 | static uint32_t good; 108 | static uint32_t invalids; 109 | static uint32_t badData; 110 | 111 | digitalWrite(LED, HIGH); 112 | 113 | // Atomically copy volatile global variable to local variable since the radio is still in RX mode and another packet could come in at any moment 114 | noInterrupts(); 115 | uint8_t pktStatus = packetStatus; 116 | packetStatus = PACKET_NONE; 117 | interrupts(); 118 | 119 | if(pktStatus == PACKET_NONE) 120 | { 121 | Serial.println("Woke for no reason?"); 122 | } 123 | else if(pktStatus == PACKET_INVALID) 124 | { 125 | Serial.println("Invalid packet"); 126 | invalids++; 127 | } 128 | else 129 | { 130 | Serial.println("Got packet"); 131 | 132 | // Make buffer for data 133 | uint8_t buffer[PAYLOAD_SIZE]; 134 | 135 | // Read payload 136 | transceiver.read(buffer, sizeof(buffer)); 137 | 138 | // Show received data 139 | Serial.print(F("Data from client:")); 140 | for(uint8_t i=0;i 6 16 | // PWR -> 8 17 | 18 | // The following pins on the nRF905 must be connected to VCC (3.3V) or GND: 19 | // CE (TRX_EN) -> VCC 20 | // TXE (TX_EN) -> VCC 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #define BASE_STATION_ADDR 0xE7E7E7E7 27 | #define NODE_ID 78 28 | #define LED A5 29 | 30 | nRF905 transceiver = nRF905(); 31 | 32 | static bool txDone; // NOTE: In polling mode this does not need to be volatile 33 | 34 | // Event function for TX completion 35 | void nRF905_onTxComplete(nRF905* device) 36 | { 37 | txDone = true; 38 | } 39 | 40 | void setup() 41 | { 42 | Serial.begin(115200); 43 | Serial.println(F("Sensor node starting...")); 44 | 45 | pinMode(LED, OUTPUT); 46 | 47 | 48 | // standby off TODO 49 | //pinMode(7, OUTPUT); 50 | //digitalWrite(7, HIGH); 51 | // pwr 52 | //pinMode(8, OUTPUT); 53 | //digitalWrite(8, HIGH); 54 | // trx 55 | //pinMode(9, OUTPUT); 56 | //digitalWrite(9, HIGH); 57 | 58 | 59 | // This must be called first 60 | SPI.begin(); 61 | 62 | // Minimal wires (polling mode) 63 | // Up to 5 wires can be disconnected, however this will reduce functionalliy and will put the library into polling mode instead of interrupt mode. 64 | // In polling mode the .poll() method must be called as often as possible. If .poll() is not called often enough then events may be missed. 65 | transceiver.begin( 66 | SPI, 67 | 10000000, 68 | 6, 69 | NRF905_PIN_UNUSED, // CE (standby) pin must be connected to VCC (3.3V) 70 | NRF905_PIN_UNUSED, // TRX (RX/TX mode) pin must be connected to VCC (3.3V) (force TX mode) 71 | 8, // PWR 72 | NRF905_PIN_UNUSED, // Without the CD pin collision avoidance will be disabled 73 | NRF905_PIN_UNUSED, // Without the DR pin the library will run in polling mode and poll the status register over SPI. This also means the nRF905 can not wake the MCU up from sleep mode 74 | NRF905_PIN_UNUSED, // Without the AM pin the library must poll the status register over SPI. 75 | NULL, // Running in polling mode so no interrupt function 76 | NULL // Running in polling mode so no interrupt function 77 | ); 78 | 79 | // Register event functions 80 | transceiver.events( 81 | NULL, 82 | NULL, 83 | nRF905_onTxComplete, 84 | NULL 85 | ); 86 | 87 | // Low-mid transmit level -2dBm (631uW) 88 | transceiver.setTransmitPower(NRF905_PWR_n2); 89 | 90 | Serial.println(F("Sensor node started")); 91 | } 92 | 93 | void loop() 94 | { 95 | digitalWrite(LED, HIGH); 96 | 97 | uint8_t buffer[NRF905_MAX_PAYLOAD]; 98 | 99 | // Read some digital pins and analog values 100 | int val1 = analogRead(A0); 101 | int val2 = analogRead(A1); 102 | int val3 = analogRead(A2); 103 | 104 | buffer[0] = NODE_ID; 105 | buffer[1] = digitalRead(5); 106 | buffer[2] = digitalRead(7); 107 | buffer[3] = digitalRead(9); 108 | buffer[4] = val1>>8; 109 | buffer[5] = val1; 110 | buffer[6] = val2>>8; 111 | buffer[7] = val2; 112 | buffer[8] = val3>>8; 113 | buffer[9] = val3; 114 | 115 | Serial.print(F("Analog values: ")); 116 | Serial.print(val1); 117 | Serial.print(F(" ")); 118 | Serial.print(val2); 119 | Serial.print(F(" ")); 120 | Serial.println(val3); 121 | 122 | Serial.print(F("Digital values: ")); 123 | Serial.print(buffer[1]); 124 | Serial.print(F(" ")); 125 | Serial.print(buffer[2]); 126 | Serial.print(F(" ")); 127 | Serial.println(buffer[3]); 128 | 129 | Serial.println("---"); 130 | 131 | // Write data to radio 132 | transceiver.write(BASE_STATION_ADDR, buffer, sizeof(buffer)); 133 | 134 | txDone = false; 135 | 136 | // This will power-up the radio and send the data 137 | transceiver.TX(NRF905_NEXTMODE_TX, false); 138 | 139 | // Transmission will take approx 6-7ms to complete (smaller paylaod sizes will be faster) 140 | while(!txDone) 141 | transceiver.poll(); 142 | 143 | // Transmission done, power-down the radio 144 | transceiver.powerDown(); 145 | 146 | // NOTE: 147 | // After the payload has been sent the radio will continue to transmit an empty carrier wave until .powerDown() is called. Since this is a sensor node that doesn't need to receive data, only transmit and go into low power mode, this example hard wires the radio into TX mode (TXE connected to VCC) to reduce number of connections to the Arduino. 148 | 149 | digitalWrite(LED, LOW); 150 | 151 | // TODO 152 | // Sleep for 64 seconds 153 | //uint8_t sleepCounter = 8; 154 | //while(sleepCounter--) 155 | // Sleep for 1 second 156 | LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); 157 | } 158 | -------------------------------------------------------------------------------- /examples/ping_client/ping_client.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Project: nRF905 Radio Library for Arduino (Ping client example) 3 | * Author: Zak Kemble, contact@zakkemble.net 4 | * Copyright: (C) 2020 by Zak Kemble 5 | * License: GNU GPL v3 (see License.txt) 6 | * Web: https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 7 | */ 8 | 9 | /* 10 | * Time how long it takes to send some data and get a reply. 11 | * Should be around 14-17ms with default settings. 12 | */ 13 | 14 | #include 15 | #include 16 | 17 | #define RXADDR 0xE7E7E7E7 // Address of this device 18 | #define TXADDR 0xE7E7E7E7 // Address of device to send to 19 | 20 | #define TIMEOUT 500 // 500ms ping timeout 21 | 22 | #define PACKET_NONE 0 23 | #define PACKET_OK 1 24 | #define PACKET_INVALID 2 25 | 26 | #define LED A5 27 | #define PAYLOAD_SIZE NRF905_MAX_PAYLOAD // 32 28 | 29 | nRF905 transceiver = nRF905(); 30 | 31 | static volatile uint8_t packetStatus; 32 | 33 | // Don't modify these 2 functions. They just pass the DR/AM interrupt to the correct nRF905 instance. 34 | void nRF905_int_dr(){transceiver.interrupt_dr();} 35 | void nRF905_int_am(){transceiver.interrupt_am();} 36 | 37 | // Event function for RX complete 38 | void nRF905_onRxComplete(nRF905* device) 39 | { 40 | packetStatus = PACKET_OK; 41 | transceiver.standby(); 42 | } 43 | 44 | // Event function for RX invalid 45 | void nRF905_onRxInvalid(nRF905* device) 46 | { 47 | packetStatus = PACKET_INVALID; 48 | transceiver.standby(); 49 | } 50 | 51 | void setup() 52 | { 53 | Serial.begin(115200); 54 | 55 | Serial.println(F("Client starting...")); 56 | 57 | pinMode(LED, OUTPUT); 58 | 59 | // standby off 60 | //pinMode(7, OUTPUT); 61 | //digitalWrite(7, HIGH); 62 | 63 | // This must be called first 64 | SPI.begin(); 65 | 66 | // All wires, maximum functionality 67 | transceiver.begin( 68 | SPI, // SPI bus to use (SPI, SPI1, SPI2 etc) 69 | 10000000, // SPI Clock speed (10MHz) 70 | 6, // SPI SS 71 | 7, // CE (standby) 72 | 9, // TRX (RX/TX mode) 73 | 8, // PWR (power down) 74 | 4, // CD (collision avoid) 75 | 3, // DR (data ready) 76 | 2, // AM (address match) 77 | nRF905_int_dr, // Interrupt function for DR 78 | nRF905_int_am // Interrupt function for AM 79 | ); 80 | 81 | /* 82 | // Minimal wires (polling) 83 | // Up to 5 wires can be disconnected, however this will reduce functionality and will put the library into polling mode instead of interrupt mode 84 | // In polling mode the .poll() method must be called as often as possible. If .poll() is not called often enough then events may be missed. (Search for .poll() in the loop() function below) 85 | transceiver.begin( 86 | SPI, 87 | 10000000, 88 | 6, 89 | NRF905_PIN_UNUSED, // CE (standby) pin must be connected to VCC (3.3V) - Will always be in RX or TX mode 90 | 9, // TRX (RX/TX mode) 91 | NRF905_PIN_UNUSED, // PWR pin must be connected to VCC (3.3V) - Will always be powered up 92 | NRF905_PIN_UNUSED, // Without the CD pin collision avoidance will be disabled 93 | NRF905_PIN_UNUSED, // Without the DR pin the library will run in polling mode and poll the status register over SPI. This also means the nRF905 can not wake the MCU up from sleep mode 94 | NRF905_PIN_UNUSED, // Without the AM pin the library the library must poll the status register over SPI. 95 | NULL, // No interrupt function 96 | NULL // No interrupt function 97 | ); 98 | */ 99 | 100 | /* 101 | // Minimal wires (interrupt) 102 | // Up to 4 wires can be disconnected, however this will reduce functionality. 103 | // onAddrMatch and onRxInvalid events will not work with this configuration as they rely on the AM interrupt. 104 | transceiver.begin( 105 | SPI, 106 | 10000000, 107 | 6, 108 | NRF905_PIN_UNUSED, // CE (standby) pin must be connected to VCC (3.3V) - Will always be in RX or TX mode 109 | 9, // TRX (RX/TX mode) 110 | NRF905_PIN_UNUSED, // PWR pin must be connected to VCC (3.3V) - Will always be powered up 111 | NRF905_PIN_UNUSED, // Without the CD pin collision avoidance will be disabled 112 | 3, // DR (data ready) 113 | NRF905_PIN_UNUSED, // Without the AM pin the library must poll the status register over SPI. 114 | nRF905_int_dr, 115 | NULL // No interrupt function 116 | ); 117 | */ 118 | 119 | // Register event functions 120 | transceiver.events( 121 | nRF905_onRxComplete, 122 | nRF905_onRxInvalid, 123 | NULL, 124 | NULL 125 | ); 126 | 127 | // Set address of this device 128 | transceiver.setListenAddress(RXADDR); 129 | 130 | Serial.println(F("Client started")); 131 | } 132 | 133 | void loop() 134 | { 135 | static uint8_t counter; 136 | static uint32_t sent; 137 | static uint32_t replies; 138 | static uint32_t timeouts; 139 | static uint32_t invalids; 140 | static uint32_t badData; 141 | 142 | // Make data 143 | uint8_t buffer[PAYLOAD_SIZE]; 144 | memset(buffer, counter, PAYLOAD_SIZE); 145 | counter++; 146 | 147 | packetStatus = PACKET_NONE; 148 | 149 | // Show data 150 | Serial.print(F("Sending data: ")); 151 | for(uint8_t i=0;i TIMEOUT) 182 | break; 183 | } 184 | 185 | if(success == PACKET_NONE) 186 | { 187 | Serial.println(F("Ping timed out")); 188 | timeouts++; 189 | } 190 | else if(success == PACKET_INVALID) 191 | { 192 | Serial.println(F("Invalid packet!")); 193 | invalids++; 194 | } 195 | else 196 | { 197 | uint16_t totalTime = millis() - startTime; 198 | replies++; 199 | 200 | // If success toggle LED and send ping time over serial 201 | digitalWrite(LED, digitalRead(LED) ? LOW : HIGH); 202 | 203 | Serial.print(F("Ping time: ")); 204 | Serial.print(totalTime); 205 | Serial.println(F("ms")); 206 | 207 | // Get the reply data 208 | uint8_t replyBuffer[PAYLOAD_SIZE]; 209 | transceiver.read(replyBuffer, sizeof(replyBuffer)); 210 | 211 | // Validate data 212 | for(uint8_t i=0;i 14 | #include 15 | 16 | #define RXADDR 0xE7E7E7E7 // Address of this device 17 | #define TXADDR 0xE7E7E7E7 // Address of device to send to 18 | 19 | #define PACKET_NONE 0 20 | #define PACKET_OK 1 21 | #define PACKET_INVALID 2 22 | 23 | #define LED A5 24 | #define PAYLOAD_SIZE NRF905_MAX_PAYLOAD 25 | 26 | nRF905 transceiver = nRF905(); 27 | 28 | static volatile uint8_t packetStatus; 29 | 30 | // Don't modify these 2 functions. They just pass the DR/AM interrupt to the correct nRF905 instance. 31 | void nRF905_int_dr(){transceiver.interrupt_dr();} 32 | void nRF905_int_am(){transceiver.interrupt_am();} 33 | 34 | // Event function for RX complete 35 | void nRF905_onRxComplete(nRF905* device) 36 | { 37 | packetStatus = PACKET_OK; 38 | transceiver.standby(); 39 | } 40 | 41 | // Event function for RX invalid 42 | void nRF905_onRxInvalid(nRF905* device) 43 | { 44 | packetStatus = PACKET_INVALID; 45 | transceiver.standby(); 46 | } 47 | 48 | void setup() 49 | { 50 | Serial.begin(115200); 51 | 52 | Serial.println(F("Server starting...")); 53 | 54 | pinMode(LED, OUTPUT); 55 | 56 | // This must be called first 57 | SPI.begin(); 58 | 59 | transceiver.begin( 60 | SPI, // SPI bus to use (SPI, SPI1, SPI2 etc) 61 | 10000000, // SPI Clock speed (10MHz) 62 | 6, // SPI SS 63 | 7, // CE (standby) 64 | 9, // TRX (RX/TX mode) 65 | 8, // PWR (power down) 66 | 4, // CD (collision avoid) 67 | 3, // DR (data ready) 68 | 2, // AM (address match) 69 | nRF905_int_dr, // Interrupt function for DR 70 | nRF905_int_am // Interrupt function for AM 71 | ); 72 | 73 | // Register event functions 74 | transceiver.events( 75 | nRF905_onRxComplete, 76 | nRF905_onRxInvalid, 77 | NULL, 78 | NULL 79 | ); 80 | 81 | // Set address of this device 82 | transceiver.setListenAddress(RXADDR); 83 | 84 | // Put into receive mode 85 | transceiver.RX(); 86 | 87 | Serial.println(F("Server started")); 88 | } 89 | 90 | void loop() 91 | { 92 | static uint32_t pings; 93 | static uint32_t invalids; 94 | static uint32_t badData; 95 | 96 | Serial.println(F("Waiting for ping...")); 97 | 98 | // Wait for data 99 | while(packetStatus == PACKET_NONE); 100 | 101 | if(packetStatus != PACKET_OK) 102 | { 103 | invalids++; 104 | packetStatus = PACKET_NONE; 105 | Serial.println(F("Invalid packet!")); 106 | transceiver.RX(); 107 | } 108 | else 109 | { 110 | pings++; 111 | packetStatus = PACKET_NONE; 112 | 113 | Serial.println(F("Got ping")); 114 | 115 | // Toggle LED 116 | digitalWrite(LED, digitalRead(LED) ? LOW : HIGH); 117 | 118 | // Make buffer for data 119 | uint8_t buffer[PAYLOAD_SIZE]; 120 | 121 | // Read payload 122 | transceiver.read(buffer, sizeof(buffer)); 123 | 124 | // Copy data into new buffer for modifying 125 | uint8_t replyBuffer[PAYLOAD_SIZE]; 126 | memcpy(replyBuffer, buffer, PAYLOAD_SIZE); 127 | 128 | // Validate data and modify 129 | // Each byte ofthe payload should be the same value, increment this value and send back to the client 130 | bool dataIsBad = false; 131 | uint8_t value = replyBuffer[0]; 132 | for(uint8_t i=0;i CE 22 | * 8 -> PWR 23 | * 9 -> TXE 24 | * 4 -> CD 25 | * 3 -> DR 26 | * 2 -> AM 27 | * 10 -> CSN 28 | * 12 -> SO 29 | * 11 -> SI 30 | * 13 -> SCK 31 | */ 32 | 33 | #include 34 | 35 | #define PACKET_TYPE_DATA 0 36 | #define PACKET_TYPE_ACK 1 37 | 38 | #define MAX_PACKET_SIZE (NRF905_MAX_PAYLOAD - 2) 39 | typedef struct { 40 | byte dstAddress[NRF905_ADDR_SIZE]; 41 | byte type; 42 | byte len; 43 | byte data[MAX_PACKET_SIZE]; 44 | } packet_t; 45 | 46 | static volatile byte newData[NRF905_MAX_PAYLOAD]; 47 | static volatile bool gotNewData; 48 | 49 | void NRF905_CB_RXCOMPLETE(void) 50 | { 51 | gotNewData = true; 52 | nRF905_read((byte*)newData, sizeof(newData)); 53 | 54 | // Still in RX mode 55 | } 56 | 57 | void NRF905_CB_TXCOMPLETE(void) 58 | { 59 | nRF905_RX(); 60 | } 61 | 62 | void setup() 63 | { 64 | // Start up 65 | nRF905_init(); 66 | 67 | // Put into receive mode 68 | nRF905_RX(); 69 | 70 | Serial.begin(19200); 71 | Serial.println(F("Ready")); 72 | } 73 | 74 | void loop() 75 | { 76 | packet_t packet; 77 | 78 | // Send serial data 79 | byte dataSize; 80 | while((dataSize = Serial.available())) 81 | { 82 | // Make sure we don't try to send more than max packet size 83 | if(dataSize > MAX_PACKET_SIZE) 84 | dataSize = MAX_PACKET_SIZE; 85 | 86 | packet.type = PACKET_TYPE_DATA; 87 | packet.len = dataSize; 88 | 89 | // Copy data from serial to packet buffer 90 | for(byte i=0;i 50) // 50ms timeout 106 | { 107 | timeout = true; 108 | break; 109 | } 110 | } 111 | 112 | if(timeout) // Timed out 113 | { 114 | Serial.println(F("TO")); 115 | break; 116 | } 117 | else if(packet.type == PACKET_TYPE_ACK) // Is packet type ACK? 118 | break; 119 | 120 | // drop DATA type packets 121 | } 122 | } 123 | 124 | // Wait for data 125 | while(1) 126 | { 127 | if(getPacket(&packet) && packet.type == PACKET_TYPE_DATA) // Got a packet and is it a data packet? 128 | { 129 | // Print data 130 | Serial.write(packet.data, packet.len); 131 | 132 | // Reply with ACK 133 | packet.type = PACKET_TYPE_ACK; 134 | packet.len = 0; 135 | sendPacket(&packet); 136 | } 137 | else if(Serial.available()) // We've got some serial data, need to send it 138 | break; 139 | 140 | // drop ACK type packets 141 | } 142 | } 143 | 144 | // Send a packet 145 | static void sendPacket(void* _packet) 146 | { 147 | // Void pointer to packet_t pointer hack 148 | // Arduino puts all the function defs at the top of the file before packet_t being declared :/ 149 | packet_t* packet = (packet_t*)_packet; 150 | 151 | // Convert packet data to plain byte array 152 | byte totalLength = packet->len + 2; 153 | byte tmpBuff[totalLength]; 154 | tmpBuff[0] = packet->type; 155 | tmpBuff[1] = packet->len; 156 | memcpy(&tmpBuff[2], packet->data, packet->len); 157 | 158 | // Set address of device to send to 159 | //nRF905_setTXAddress(packet->dstAddress); 160 | 161 | // Send payload (send fails if other transmissions are going on, keep trying until success) 162 | while(!nRF905_TX(NRF905_DEFAULT_TXADDR, tmpBuff, totalLength, NRF905_NEXTMODE_STANDBY)); 163 | } 164 | 165 | // Get a packet 166 | static bool getPacket(void* _packet) 167 | { 168 | // Void pointer to packet_t pointer hack 169 | // Arduino puts all the function defs at the top of the file before packet_t being declared :/ 170 | packet_t* packet = (packet_t*)_packet; 171 | 172 | // See if any data available 173 | if(!gotNewData) 174 | return false; 175 | 176 | NRF905_NO_INTERRUPT() 177 | { 178 | gotNewData = false; 179 | 180 | // Convert byte array to packet 181 | packet->type = newData[0]; 182 | packet->len = newData[1]; 183 | 184 | // Sanity check 185 | if(packet->len > MAX_PACKET_SIZE) 186 | packet->len = MAX_PACKET_SIZE; 187 | 188 | memcpy(packet->data, (byte*)&newData[2], packet->len); 189 | } 190 | 191 | return true; 192 | } -------------------------------------------------------------------------------- /extras/Product_Specification_nRF905_v1.5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZakKemble/nRF905-arduino/d75930d8bb6da2626112dbbac269b33147ea5d1a/extras/Product_Specification_nRF905_v1.5.pdf -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map nRF905 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | nRF905 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | otherSPIinterrupts KEYWORD2 16 | events KEYWORD2 17 | setChannel KEYWORD2 18 | setBand KEYWORD2 19 | setAutoRetransmit KEYWORD2 20 | setLowRxPower KEYWORD2 21 | setTransmitPower KEYWORD2 22 | setCRC KEYWORD2 23 | setClockOut KEYWORD2 24 | setPayloadSize KEYWORD2 25 | setAddressSize KEYWORD2 26 | receiveBusy KEYWORD2 27 | airwayBusy KEYWORD2 28 | setListenAddress KEYWORD2 29 | write KEYWORD2 30 | read KEYWORD2 31 | TX KEYWORD2 32 | RX KEYWORD2 33 | powerDown KEYWORD2 34 | standby KEYWORD2 35 | mode KEYWORD2 36 | getConfigRegisters KEYWORD2 37 | interrupt_dr KEYWORD2 38 | interrupt_am KEYWORD2 39 | poll KEYWORD2 40 | NRF905_CALC_CHANNEL KEYWORD2 41 | 42 | ####################################### 43 | # Constants (LITERAL1) 44 | ####################################### 45 | 46 | NRF905_NEXTMODE_STANDBY LITERAL1 47 | NRF905_NEXTMODE_RX LITERAL1 48 | NRF905_NEXTMODE_TX LITERAL1 49 | NRF905_MODE_POWERDOWN LITERAL1 50 | NRF905_MODE_STANDBY LITERAL1 51 | NRF905_MODE_RX LITERAL1 52 | NRF905_MODE_TX LITERAL1 53 | NRF905_MODE_ACTIVE LITERAL1 54 | NRF905_BAND_433MHZ LITERAL1 55 | NRF905_BAND_868MHZ LITERAL1 56 | NRF905_BAND_915MHZ LITERAL1 57 | NRF905_PWR_n10 LITERAL1 58 | NRF905_PWR_n2 LITERAL1 59 | NRF905_PWR_6 LITERAL1 60 | NRF905_PWR_10 LITERAL1 61 | NRF905_OUTCLK_DISABLE LITERAL1 62 | NRF905_OUTCLK_4MHZ LITERAL1 63 | NRF905_OUTCLK_2MHZ LITERAL1 64 | NRF905_OUTCLK_1MHZ LITERAL1 65 | NRF905_OUTCLK_500KHZ LITERAL1 66 | NRF905_CRC_DISABLE LITERAL1 67 | NRF905_CRC_MODE_8 LITERAL1 68 | NRF905_CRC_MODE_16 LITERAL1 69 | NRF905_MAX_PAYLOAD LITERAL1 70 | NRF905_REGISTER_COUNT LITERAL1 71 | NRF905_DEFAULT_RXADDR LITERAL1 72 | NRF905_DEFAULT_TXADDR LITERAL1 73 | NRF905_PIN_UNUSED LITERAL1 74 | 75 | NRF905_LOW_RX_ENABLE LITERAL1 76 | NRF905_LOW_RX_DISABLE LITERAL1 77 | NRF905_AUTO_RETRAN_ENABLE LITERAL1 78 | NRF905_AUTO_RETRAN_DISABLE LITERAL1 79 | NRF905_ADDR_SIZE_1 LITERAL1 80 | NRF905_ADDR_SIZE_4 LITERAL1 81 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nRF905 Radio Library", 3 | "version": "4.0.2", 4 | "keywords": "Arduino, Communication, nRF905, Nordic, 433Mhz, 868Mhz, 915Mhz, STM32, ESP8266, NodeMCU, ESP32, M5Stack", 5 | "description": "nRF905 Radio Library for Arduino", 6 | "repository": 7 | { 8 | "type": "git", 9 | "url": "https://github.com/zkemble/nRF905-arduino" 10 | }, 11 | "authors": 12 | [ 13 | { 14 | "name": "Zak Kemble", 15 | "email": "contact@zakkemble.net", 16 | "maintainer": true 17 | } 18 | ], 19 | "frameworks": "arduino", 20 | "platforms": "*" 21 | } 22 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=nRF905 Radio Library 2 | version=4.0.2 3 | author=Zak Kemble 4 | maintainer=Zak Kemble 5 | sentence=nRF905 Radio Library for Arduino 6 | paragraph= 7 | category=Communication 8 | url=https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 9 | architectures=* 10 | includes=nRF905.h 11 | -------------------------------------------------------------------------------- /src/nRF905.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Project: nRF905 Radio Library for Arduino 3 | * Author: Zak Kemble, contact@zakkemble.net 4 | * Copyright: (C) 2020 by Zak Kemble 5 | * License: GNU GPL v3 (see License.txt) 6 | * Web: https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include "nRF905.h" 13 | #include "nRF905_config.h" 14 | #include "nRF905_defs.h" 15 | 16 | #if defined(ESP32) 17 | #warning "ESP32 platforms don't seem to have a way of disabling and enabling interrupts. Try to avoid accessing the SPI bus from within the nRF905 event functions. That is, don't read the payload from inside the rxComplete event and make sure to connect the AM pin. See https://github.com/zkemble/nRF905-arduino/issues/1" 18 | #endif 19 | 20 | static const uint8_t config[] PROGMEM = { 21 | NRF905_CMD_W_CONFIG, 22 | NRF905_CHANNEL, 23 | NRF905_AUTO_RETRAN | NRF905_LOW_RX | NRF905_PWR | NRF905_BAND | ((NRF905_CHANNEL>>8) & 0x01), 24 | (NRF905_ADDR_SIZE_TX<<4) | NRF905_ADDR_SIZE_RX, 25 | NRF905_PAYLOAD_SIZE_RX, 26 | NRF905_PAYLOAD_SIZE_TX, 27 | (uint8_t)NRF905_ADDRESS, (uint8_t)(NRF905_ADDRESS>>8), (uint8_t)(NRF905_ADDRESS>>16), (uint8_t)(NRF905_ADDRESS>>24), 28 | NRF905_CRC | NRF905_CLK_FREQ | NRF905_OUTCLK 29 | }; 30 | 31 | inline uint8_t nRF905::cselect() 32 | { 33 | #if defined(ESP32) || defined(ESP8266) 34 | if(!isrBusy) 35 | noInterrupts(); 36 | #endif 37 | spi.beginTransaction(spiSettings); 38 | digitalWrite(csn, LOW); 39 | return 1; 40 | } 41 | 42 | inline uint8_t nRF905::cdeselect() 43 | { 44 | digitalWrite(csn, HIGH); 45 | spi.endTransaction(); 46 | #if defined(ESP32) || defined(ESP8266) 47 | if(!isrBusy) 48 | interrupts(); 49 | #endif 50 | return 0; 51 | } 52 | 53 | // Can be in any mode to write registers, but standby or power-down is recommended 54 | #define CHIPSELECT() for(uint8_t _cs = cselect(); _cs; _cs = cdeselect()) 55 | 56 | uint8_t nRF905::readConfigRegister(uint8_t reg) 57 | { 58 | uint8_t val = 0; 59 | CHIPSELECT() 60 | { 61 | spi.transfer(NRF905_CMD_R_CONFIG | reg); 62 | val = spi.transfer(NRF905_CMD_NOP); 63 | } 64 | return val; 65 | } 66 | 67 | void nRF905::writeConfigRegister(uint8_t reg, uint8_t val) 68 | { 69 | CHIPSELECT() 70 | { 71 | spi.transfer(NRF905_CMD_W_CONFIG | reg); 72 | spi.transfer(val); 73 | } 74 | } 75 | 76 | void nRF905::setConfigReg1(uint8_t val, uint8_t mask, uint8_t reg) 77 | { 78 | // TODO atomic read/write? 79 | writeConfigRegister(reg, (readConfigRegister(NRF905_REG_CONFIG1) & mask) | val); 80 | } 81 | 82 | void nRF905::setConfigReg2(uint8_t val, uint8_t mask, uint8_t reg) 83 | { 84 | // TODO atomic read/write? 85 | writeConfigRegister(reg, (readConfigRegister(NRF905_REG_CONFIG2) & mask) | val); 86 | } 87 | 88 | void nRF905::defaultConfig() 89 | { 90 | // Should be in standby mode 91 | 92 | // Set control registers 93 | CHIPSELECT() 94 | { 95 | for(uint8_t i=0;i>16); 155 | for(uint8_t i=0;i<4;i++) 156 | spi.transfer(address>>(8 * i)); 157 | //spi.transfer(&address, 4); 158 | } 159 | } 160 | 161 | uint8_t nRF905::readStatus() 162 | { 163 | uint8_t status = 0; 164 | CHIPSELECT() 165 | status = spi.transfer(NRF905_CMD_NOP); 166 | return status; 167 | } 168 | 169 | // TODO not used 170 | /* 171 | bool nRF905::dataReady() 172 | { 173 | if(dr_mode == 1) 174 | return (readStatus() & (1<spi = spi; 205 | this->spiSettings = SPISettings(spiClock, MSBFIRST, SPI_MODE0); 206 | 207 | this->csn = csn; 208 | this->trx = trx; 209 | this->tx = tx; 210 | this->pwr = pwr; 211 | this->cd = cd; 212 | this->dr = dr; 213 | this->am = am; 214 | 215 | digitalWrite(csn, HIGH); 216 | pinMode(csn, OUTPUT); 217 | if(trx != NRF905_PIN_UNUSED) 218 | pinMode(trx, OUTPUT); 219 | if(tx != NRF905_PIN_UNUSED) 220 | pinMode(tx, OUTPUT); 221 | if(pwr != NRF905_PIN_UNUSED) 222 | pinMode(pwr, OUTPUT); 223 | 224 | #if !defined(ESP32) && !defined(ESP8266) 225 | // SPI.usingInterrupts() is not supported on ESP platforms. More info: https://github.com/zkemble/nRF905-arduino/issues/1 226 | if(dr != NRF905_PIN_UNUSED) 227 | spi.usingInterrupt(digitalPinToInterrupt(dr)); 228 | if(am != NRF905_PIN_UNUSED) 229 | spi.usingInterrupt(digitalPinToInterrupt(am)); 230 | #endif 231 | 232 | powerOn(false); 233 | standbyMode(true); 234 | txMode(false); 235 | delay(3); 236 | defaultConfig(); 237 | 238 | if(dr == NRF905_PIN_UNUSED || callback_interrupt_dr == NULL) 239 | polledMode = true; 240 | else 241 | { 242 | attachInterrupt(digitalPinToInterrupt(dr), callback_interrupt_dr, RISING); 243 | if(am != NRF905_PIN_UNUSED && callback_interrupt_am != NULL) 244 | attachInterrupt(digitalPinToInterrupt(am), callback_interrupt_am, CHANGE); 245 | } 246 | } 247 | 248 | void nRF905::otherSPIinterrupts() 249 | { 250 | #if !defined(ESP32) && !defined(ESP8266) 251 | spi.usingInterrupt(255); 252 | #endif 253 | } 254 | 255 | void nRF905::events( 256 | void (*onRxComplete)(nRF905* device), 257 | void (*onRxInvalid)(nRF905* device), 258 | void (*onTxComplete)(nRF905* device), 259 | void (*onAddrMatch)(nRF905* device) 260 | ) 261 | { 262 | this->onRxComplete = onRxComplete; 263 | this->onRxInvalid = onRxInvalid; 264 | this->onTxComplete = onTxComplete; 265 | this->onAddrMatch = onAddrMatch; 266 | } 267 | 268 | void nRF905::setChannel(uint16_t channel) 269 | { 270 | if(channel > 511) 271 | channel = 511; 272 | 273 | // TODO atomic read/write? 274 | uint8_t reg = (readConfigRegister(NRF905_REG_CONFIG1) & NRF905_MASK_CHANNEL) | (channel>>8); 275 | 276 | CHIPSELECT() 277 | { 278 | spi.transfer(NRF905_CMD_W_CONFIG | NRF905_REG_CHANNEL); 279 | spi.transfer(channel); 280 | spi.transfer(reg); 281 | } 282 | } 283 | 284 | void nRF905::setBand(nRF905_band_t band) 285 | { 286 | // TODO atomic read/write? 287 | uint8_t reg = (readConfigRegister(NRF905_REG_CONFIG1) & NRF905_MASK_BAND) | band; 288 | 289 | CHIPSELECT() 290 | { 291 | spi.transfer(NRF905_CMD_W_CONFIG | NRF905_REG_CONFIG1); 292 | spi.transfer(reg); 293 | } 294 | } 295 | 296 | void nRF905::setAutoRetransmit(bool val) 297 | { 298 | setConfigReg1( 299 | val ? NRF905_AUTO_RETRAN_ENABLE : NRF905_AUTO_RETRAN_DISABLE, 300 | NRF905_MASK_AUTO_RETRAN, 301 | NRF905_REG_AUTO_RETRAN 302 | ); 303 | } 304 | 305 | void nRF905::setLowRxPower(bool val) 306 | { 307 | setConfigReg1( 308 | val ? NRF905_LOW_RX_ENABLE : NRF905_LOW_RX_DISABLE, 309 | NRF905_MASK_LOW_RX, 310 | NRF905_REG_LOW_RX 311 | ); 312 | } 313 | 314 | void nRF905::setTransmitPower(nRF905_pwr_t val) 315 | { 316 | setConfigReg1(val, NRF905_MASK_PWR, NRF905_REG_PWR); 317 | } 318 | 319 | void nRF905::setCRC(nRF905_crc_t val) 320 | { 321 | setConfigReg2(val, NRF905_MASK_CRC, NRF905_REG_CRC); 322 | } 323 | 324 | void nRF905::setClockOut(nRF905_outclk_t val) 325 | { 326 | setConfigReg2(val, NRF905_MASK_OUTCLK, NRF905_REG_OUTCLK); 327 | } 328 | 329 | void nRF905::setPayloadSize(uint8_t sizeTX, uint8_t sizeRX) 330 | { 331 | if(sizeTX > NRF905_MAX_PAYLOAD) 332 | sizeTX = NRF905_MAX_PAYLOAD; 333 | 334 | if(sizeRX > NRF905_MAX_PAYLOAD) 335 | sizeRX = NRF905_MAX_PAYLOAD; 336 | 337 | CHIPSELECT() 338 | { 339 | spi.transfer(NRF905_CMD_W_CONFIG | NRF905_REG_RX_PAYLOAD_SIZE); 340 | spi.transfer(sizeRX); 341 | spi.transfer(sizeTX); 342 | } 343 | } 344 | 345 | void nRF905::setAddressSize(uint8_t sizeTX, uint8_t sizeRX) 346 | { 347 | if(sizeTX != 1 && sizeTX != 4) 348 | sizeTX = 4; 349 | 350 | if(sizeRX != 1 && sizeRX != 4) 351 | sizeRX = 4; 352 | 353 | CHIPSELECT() 354 | { 355 | spi.transfer(NRF905_CMD_W_CONFIG | NRF905_REG_ADDR_WIDTH); 356 | spi.transfer((sizeTX<<4) | sizeRX); 357 | } 358 | } 359 | 360 | bool nRF905::receiveBusy() 361 | { 362 | return addressMatched(); 363 | } 364 | 365 | bool nRF905::airwayBusy() 366 | { 367 | if(cd != NRF905_PIN_UNUSED) 368 | return digitalRead(cd); 369 | return false; 370 | } 371 | 372 | void nRF905::setListenAddress(uint32_t address) 373 | { 374 | setAddress(address, NRF905_CMD_W_CONFIG | NRF905_REG_RX_ADDRESS); 375 | } 376 | 377 | void nRF905::write(uint32_t sendTo, void* data, uint8_t len) 378 | { 379 | setAddress(sendTo, NRF905_CMD_W_TX_ADDRESS); 380 | 381 | if(len > 0 && data != NULL) 382 | { 383 | if(len > NRF905_MAX_PAYLOAD) 384 | len = NRF905_MAX_PAYLOAD; 385 | 386 | CHIPSELECT() 387 | { 388 | spi.transfer(NRF905_CMD_W_TX_PAYLOAD); 389 | //spi.transfer(data, len); 390 | for(uint8_t i=0;i NRF905_MAX_PAYLOAD) 399 | len = NRF905_MAX_PAYLOAD; 400 | 401 | CHIPSELECT() 402 | { 403 | spi.transfer(NRF905_CMD_R_RX_PAYLOAD); 404 | 405 | // Get received payload 406 | //spi.transfer(data, len); 407 | for(uint8_t i=0;i 13 | #include 14 | #include 15 | #include "nRF905_config.h" 16 | 17 | /** 18 | * @brief Available modes after transmission complete. 19 | */ 20 | typedef enum 21 | { 22 | // TODO use nRF905_mode_t instead of nRF905_nextmode_t? 23 | 24 | NRF905_NEXTMODE_STANDBY, ///< Standby mode 25 | NRF905_NEXTMODE_RX, ///< Receive mode 26 | NRF905_NEXTMODE_TX ///< Transmit mode (will auto-retransmit if enabled, otherwise will transmit a carrier wave with no data) 27 | } nRF905_nextmode_t; 28 | 29 | /** 30 | * @brief Current radio mode 31 | */ 32 | typedef enum 33 | { 34 | NRF905_MODE_POWERDOWN, ///< Power-down mode 35 | NRF905_MODE_STANDBY, ///< Standby mode 36 | NRF905_MODE_RX, ///< Receive mode 37 | NRF905_MODE_TX, ///< Transmit mode 38 | NRF905_MODE_ACTIVE ///< Receive or transmit mode (when unable to tell due to the tx pin being unused, hardwired to VCC (TX) or GND (RX)) 39 | } nRF905_mode_t; 40 | 41 | /** 42 | * @brief Frequency bands. 43 | */ 44 | typedef enum 45 | { 46 | // NOTE: 47 | // When using NRF905_BAND_868 and NRF905_BAND_915 for calculating channel (NRF905_CALC_CHANNEL(f, b)) they should be value 0x01, 48 | // but when using them for setting registers their value should be 0x02. 49 | // They're defined as 0x02 here so when used for calculating channel they're right shifted by 1 50 | 51 | NRF905_BAND_433 = 0x00, ///< 433MHz band 52 | NRF905_BAND_868 = 0x02, ///< 868/915MHz band 53 | NRF905_BAND_915 = 0x02 ///< 868/915MHz band 54 | } nRF905_band_t; 55 | 56 | /** 57 | * @brief Output power (n means negative, n10 = -10). 58 | */ 59 | typedef enum 60 | { 61 | NRF905_PWR_n10 = 0x00, ///< -10dBm = 100uW 62 | NRF905_PWR_n2 = 0x04, ///< -2dBm = 631uW 63 | NRF905_PWR_6 = 0x08, ///< 6dBm = 4mW 64 | NRF905_PWR_10 = 0x0C ///< 10dBm = 10mW 65 | } nRF905_pwr_t; 66 | 67 | /** 68 | * @brief Output a clock signal on pin 3 of IC. 69 | */ 70 | typedef enum 71 | { 72 | NRF905_OUTCLK_DISABLE = 0x00, ///< Disable output clock 73 | NRF905_OUTCLK_4MHZ = 0x04, ///< 4MHz clock 74 | NRF905_OUTCLK_2MHZ = 0x05, ///< 2MHz clock 75 | NRF905_OUTCLK_1MHZ = 0x06, ///< 1MHz clock 76 | NRF905_OUTCLK_500KHZ = 0x07, ///< 500KHz clock (default) 77 | } nRF905_outclk_t; 78 | 79 | /** 80 | * @brief CRC Checksum. 81 | * 82 | * The CRC is calculated across the address (SYNC word) and payload 83 | */ 84 | typedef enum 85 | { 86 | NRF905_CRC_DISABLE = 0x00, ///< Disable CRC 87 | NRF905_CRC_8 = 0x40, ///< 8bit CRC (Don't know what algorithm is used for this one) 88 | NRF905_CRC_16 = 0xC0, ///< 16bit CRC (CRC16-CCITT-FALSE (0xFFFF)) 89 | } nRF905_crc_t; 90 | 91 | #define NRF905_MAX_PAYLOAD 32 ///< Maximum payload size 92 | #define NRF905_REGISTER_COUNT 10 ///< Configuration register count 93 | #define NRF905_DEFAULT_RXADDR 0xE7E7E7E7 ///< Default receive address 94 | #define NRF905_DEFAULT_TXADDR 0xE7E7E7E7 ///< Default transmit/destination address 95 | #define NRF905_PIN_UNUSED 255 ///< Mark a pin as not used or not connected 96 | 97 | #define NRF905_CALC_CHANNEL(f, b) ((((f) / (1 + (b>>1))) - 422400000UL) / 100000UL) ///< Workout channel from frequency & band 98 | 99 | class nRF905 //: public Stream // TODO see Wire library 100 | { 101 | private: 102 | SPIClass spi; 103 | SPISettings spiSettings; 104 | 105 | #if defined(ESP32) || defined(ESP8266) 106 | volatile uint8_t isrBusy; 107 | #endif 108 | 109 | // Pins 110 | uint8_t csn; // SPI SS 111 | uint8_t trx; // Standby (CE/TRX_EN) 112 | uint8_t tx; // TX or RX mode (TXE/TX_EN) 113 | uint8_t pwr; // Power-down control (PWR) 114 | uint8_t cd; // Carrier detect (CD) 115 | uint8_t dr; // Data ready (DR) 116 | uint8_t am; // Address match (AM) 117 | 118 | // Events 119 | void (*onRxComplete)(nRF905* device); 120 | void (*onRxInvalid)(nRF905* device); 121 | void (*onTxComplete)(nRF905* device); 122 | void (*onAddrMatch)(nRF905* device); 123 | 124 | volatile uint8_t validPacket; 125 | bool polledMode; 126 | 127 | inline uint8_t cselect(); 128 | inline uint8_t cdeselect(); 129 | uint8_t readConfigRegister(uint8_t reg); 130 | void writeConfigRegister(uint8_t reg, uint8_t val); 131 | void setConfigReg1(uint8_t val, uint8_t mask, uint8_t reg); 132 | void setConfigReg2(uint8_t val, uint8_t mask, uint8_t reg); 133 | void defaultConfig(); 134 | inline void powerOn(bool val); 135 | inline void standbyMode(bool val); 136 | inline void txMode(bool val); 137 | void setAddress(uint32_t address, uint8_t cmd); 138 | uint8_t readStatus(); 139 | //bool dataReady(); 140 | bool addressMatched(); 141 | 142 | public: 143 | /*virtual size_t write(uint8_t); 144 | virtual size_t write(const uint8_t *, size_t); 145 | virtual int available(); 146 | virtual int read(); 147 | virtual int peek(); 148 | virtual void flush(); 149 | using Print::write;*/ 150 | 151 | nRF905(); 152 | 153 | /** 154 | * @brief Initialise, must be called after SPI.begin() and before any other nRF905 stuff 155 | * 156 | * \p trx, \p tx, \p pwr, \p cd, \p dr and \p am pins are optional. Use ::NRF905_PIN_UNUSED if the pin is not connected, but some functionally will be lost. 157 | * 158 | * Have a look at the examples to see how things work (or not work) when some pins are not used. If \p tx is not used and connected to VCC (TX) then either \p trx or \p pwr must be used otherwise the radio will always be transmitting either an empty carrier wave or if auto-retransmit is enabled then the payload is retransmitted over and over again, though updating the payload on-the-fly does work in auto-retransmit mode if that's what you're after. 159 | * 160 | * If \p dr pin is not used or \p callback_interrupt_dr is \p NULL then the library will run in polling mode. See .poll(). 161 | * 162 | * If \p am pin is not used then the onAddrMatch event will not work. 163 | * 164 | * @param [spi] SPI bus (usually SPI, SPI1, SPI2 etc) 165 | * @param [spiClock] SPI clock rate, max 10000000 (10MHz) 166 | * @param [csn] SPI Slave select pin 167 | * @param [trx] CE/TRX_EN pin (standby control) (optional - must be connected to VCC if not used) 168 | * @param [tx] TXE/TX_EN pin (RX/TX mode control) (optional - must be connected to VCC (TX) or GND (RX) if not used depending on what the radio should do) 169 | * @param [pwr] PWR pin (power-down control) (optional - must be connected to VCC if not used) 170 | * @param [cd] CD pin (carrier detect) (optional) 171 | * @param [dr] DR pin (data ready) (optional) 172 | * @param [am] AM pin (address match) (optional) 173 | * @param [callback_interrupt_dr] Callback for DR interrupt (optional) 174 | * @param [callback_interrupt_am] Callback for AM interrupt (optional) 175 | * 176 | * @return (none) 177 | */ 178 | void begin( 179 | SPIClass spi, 180 | uint32_t spiClock, 181 | int csn, 182 | int trx, 183 | int tx, 184 | int pwr, 185 | int cd, 186 | int dr, 187 | int am, 188 | void (*callback_interrupt_dr)(), 189 | void (*callback_interrupt_am)() 190 | ); 191 | 192 | /** 193 | * @brief If your sketch uses libraries that access the SPI bus from inside an interrupt then this method should be called after the .begin() method 194 | * 195 | * This will disable all interrupts when accessing the nRF905 via SPI instead of only disabling our own DR/AM pin interrupts. This will prevent other libraries from accessing the SPI at the same time as this library. 196 | * 197 | * Example: `transceiver.otherSPIinterrupts();` 198 | * 199 | * @return (none) 200 | */ 201 | void otherSPIinterrupts(); 202 | 203 | /** 204 | * @brief Register event functions 205 | * 206 | * Example: `transceiver.events(onRxComplete, onRxInvalid, onTxComplete, NULL);` 207 | * 208 | * @param [onRxComplete] Function to run on new payload received 209 | * @param [onRxInvalid] Function to run on corrupted payload received 210 | * @param [onTxComplete] Function to run on transmission completion (only works when calling .TX() with ::NRF905_NEXTMODE_TX or ::NRF905_NEXTMODE_STANDBY) 211 | * @param [onAddrMatch] Function to run on address match (beginning of payload reception) 212 | * 213 | * @return (none) 214 | */ 215 | void events( 216 | void (*onRxComplete)(nRF905* device), 217 | void (*onRxInvalid)(nRF905* device), 218 | void (*onTxComplete)(nRF905* device), 219 | void (*onAddrMatch)(nRF905* device) 220 | ); 221 | 222 | /** 223 | * @brief Channel to listen and transmit on 224 | * 225 | * 433MHz band: Channel 0 is 422.4MHz up to 511 which is 473.5MHz (Each channel is 100KHz apart) 226 | * 227 | * 868/915MHz band: Channel 0 is 844.8MHz up to 511 which is 947MHz (Each channel is 200KHz apart) 228 | * 229 | * Example: `transceiver.setChannel(50);` 230 | * 231 | * @param [channel] The channel (0 - 511) 232 | * @return (none) 233 | * 234 | * @see .setBand() 235 | */ 236 | void setChannel(uint16_t channel); 237 | 238 | /** 239 | * @brief Frequency band 240 | * 241 | * Radio modules are usually only tuned for a specific band, either 433MHz or 868/915MHz. Using the wrong frequency band will result in very short range of less than a meter, sometimes they have to be touching each other before anything happens. 242 | * 243 | * Example: `transceiver.setBand(NRF905_BAND_433);` 244 | * 245 | * @param [band] Frequency band, see ::nRF905_band_t 246 | * @return (none) 247 | * 248 | * @see .setChannel() ::nRF905_band_t 249 | */ 250 | void setBand(nRF905_band_t band); 251 | 252 | /** 253 | * @brief Set auto-retransmit 254 | * 255 | * If \p nextMode is set to ::NRF905_NEXTMODE_TX when calling .TX() and auto-retransmit is enabled then the radio will continuously retransmit the payload. If auto-retransmit is disabled then a carrier wave with no data will be transmitted instead (kinda useless).\n 256 | * Transmission will continue until the radio is put into standby, power-down or RX mode. 257 | * 258 | * Can be useful in areas with lots of interference, but you'll need to make sure you can differentiate between retransmitted packets and new packets (like an ID number). 259 | * 260 | * Other transmissions will be blocked if collision avoidance is enabled. 261 | * 262 | * Example: `transceiver.setAutoRetransmit(true);` 263 | * 264 | * @param [val] \p true = enable, \p false = disable 265 | * @return (none) 266 | */ 267 | void setAutoRetransmit(bool val); 268 | 269 | /** 270 | * @brief Set low power receive mode 271 | * 272 | * Reduces receive current from 12.2mA to 10.5mA, but also reduces sensitivity. 273 | * 274 | * Example: `transceiver.setLowRxPower(true);` 275 | * 276 | * @param [val] \p true = enable, \p false = disable 277 | * @return (none) 278 | */ 279 | void setLowRxPower(bool val); 280 | 281 | /** 282 | * @brief Set transmit output power 283 | * 284 | * Example: `transceiver.setTransmitPower(NRF905_PWR_10);` 285 | * 286 | * @param [val] Output power level, see ::nRF905_pwr_t 287 | * @return (none) 288 | * 289 | * @see ::nRF905_pwr_t 290 | */ 291 | void setTransmitPower(nRF905_pwr_t val); 292 | 293 | /** 294 | * @brief Set CRC algorithm 295 | * 296 | * Example: `transceiver.setCRC(NRF905_CRC_16);` 297 | * 298 | * @param [val] CRC Type, see ::nRF905_crc_t 299 | * @return (none) 300 | * 301 | * @see ::nRF905_crc_t 302 | */ 303 | void setCRC(nRF905_crc_t val); 304 | 305 | /** 306 | * @brief Set clock output 307 | * 308 | * Example: `transceiver.setClockOut(NRF905_OUTCLK_4MHZ);` 309 | * 310 | * @param [val] Clock out frequency, see ::nRF905_outclk_t 311 | * @return (none) 312 | * 313 | * @see ::nRF905_outclk_t 314 | */ 315 | void setClockOut(nRF905_outclk_t val); 316 | 317 | /** 318 | * @brief Payload sizes 319 | * 320 | * The nRF905 only supports fixed sized payloads. The receiving end must be configured for the same payload size as the transmitting end. 321 | * 322 | * Example: This will send 5 byte payloads in one direction, and 32 byte payloads in the other direction:\n 323 | * `transceiver1.setPayloadSize(5, 32); // Will transmit 5 byte payloads, receive 32 byte payloads`\n 324 | * `transceiver2.setPayloadSize(32, 5); // Will transmit 32 byte payloads, receive 5 byte payloads` 325 | * 326 | * @param [sizeTX] Transmit payload size (1 - 32) 327 | * @param [sizeRX] Recivie payload size (1 - 32) 328 | * @return (none) 329 | * 330 | * @see ::NRF905_MAX_PAYLOAD 331 | */ 332 | void setPayloadSize(uint8_t sizeTX, uint8_t sizeRX); 333 | 334 | /** 335 | * @brief Address sizes 336 | * 337 | * The address is actually the SYNC part of the packet, just after the preamble and before the data. The SYNC word is used to mark the beginning of the payload data. 338 | * 339 | * A 1 byte address is not recommended, a lot of false invalid packets will be received. 340 | * 341 | * Example: `transceiver.setAddressSize(4, 4);` 342 | * 343 | * @param [sizeTX] Transmit address size, either 1 or 4 bytes only 344 | * @param [sizeRX] Receive address size, either 1 or 4 bytes only 345 | * @return (none) 346 | */ 347 | void setAddressSize(uint8_t sizeTX, uint8_t sizeRX); 348 | 349 | /** 350 | * @brief See if the address match (AM) is asserted 351 | * 352 | * Example: `if(transceiver.receiveBusy())` 353 | * 354 | * @return \p true if currently receiving payload or payload is ready to be read, otherwise \p false 355 | */ 356 | bool receiveBusy(); 357 | 358 | /** 359 | * @brief See if airway is busy (carrier detect pin asserted). 360 | * 361 | * Example: `if(transceiver.airwayBusy())` 362 | * 363 | * @return \p true if other transmissions detected, otherwise \p false 364 | */ 365 | bool airwayBusy(); 366 | 367 | /** 368 | * @brief Set address to listen to 369 | * 370 | * Some good addresses would be \p 0xA94EC554 and \p 0xB54CAB34, bad address would be \p 0xC201043F and \p 0xFF00FF00 371 | * 372 | * Example: `transceiver.setListenAddress(0xA94EC554);` 373 | * 374 | * @note From the datasheet: Each byte within the address should be unique. Repeating bytes within the address reduces the effectiveness of the address and increases its susceptibility to noise which increases the packet error rate. The address should also have several level shifts (that is, 10101100) reducing the statistical effect of noise and the packet error rate. 375 | * @param [address] The address, a 32 bit integer (default address is 0xE7E7E7E7) 376 | * @return (none) 377 | */ 378 | void setListenAddress(uint32_t address); 379 | 380 | /** 381 | * @brief Write payload data and set destination address 382 | * 383 | * If \p data is \p NULL and/or \p len is \p 0 then the payload will not be modified, only the destination address will be updated. Useful to sending the same data to multiple addresses. 384 | * 385 | * If the radio is still transmitting then the payload and address will be updated as it is being sent, this means the payload on the receiving end may contain old and new data.\n 386 | * This also means that a node may receive part of a payload that was meant for a node with a different address.\n 387 | * Use the \p onTxComplete event to set a flag or something to ensure the transmission is complete before writing another payload. However this only works if \p nextMode is set to ::NRF905_NEXTMODE_TX or ::NRF905_NEXTMODE_STANDBY. 388 | * 389 | * Example: `transceiver.write(0xB54CAB34, buffer, sizeof(buffer));` 390 | * 391 | * @param [sendTo] Address to send the payload to 392 | * @param [data] The data 393 | * @param [len] Data length (max ::NRF905_MAX_PAYLOAD) 394 | * @return (none) 395 | */ 396 | void write(uint32_t sendTo, void* data, uint8_t len); 397 | 398 | /** 399 | * @brief Read received payload. 400 | * 401 | * This method can be called multiple times to read a few bytes at a time.\n 402 | * The payload is cleared when the radio enters power-down, RX or TX mode. Entering standby mode from RX mode does not clear the payload.\n 403 | * The radio will not receive any more data until all of the payload has been read or cleared. 404 | * 405 | * Example: `transceiver.read(buffer, 4);` 406 | * 407 | * @param [data] Buffer for the data 408 | * @param [len] How many bytes to read 409 | * @return (none) 410 | */ 411 | void read(void* data, uint8_t len); 412 | 413 | //uint32_t readUInt32(); // TODO 414 | //uint8_t readUInt8(); // TODO 415 | //char readChar(); // TODO 416 | //uint8_t readString(char str, uint8_t size); // TODO 417 | 418 | /** 419 | * @brief Begin a transmission 420 | * 421 | * If the radio is in power-down mode then this function will take an additional 3ms to complete.\n 422 | * If 3ms is too long then call .standby() and do whatever you need to do for at least 3ms before calling .TX(). 423 | * 424 | * If \p nextMode is set to ::NRF905_NEXTMODE_RX and the radio was in standby mode then this function will take an additional 700us to complete.\n 425 | * If 700us is too long then set \p nextMode to ::NRF905_NEXTMODE_STANDBY and call .RX() in the \p onTxComplete event instead. 426 | * 427 | * The onTxComplete event does not work when \p nextMode is set to ::NRF905_NEXTMODE_RX. 428 | * 429 | * For the collision avoidance to work the radio should be in RX mode for around 5ms before attempting to transmit. 430 | * 431 | * Example: `transceiver.TX(NRF905_NEXTMODE_STANDBY, true);` 432 | * 433 | * @param [nextMode] What mode to enter once the transmission is complete, see ::nRF905_nextmode_t 434 | * @param [collisionAvoid] \p true = check for other transmissions before transmitting (CD pin must be connected), \p false = skip the check and just transmit 435 | * @return \p false if collision avoidance is enabled and other transmissions are going on, \p true if transmission has successfully begun 436 | * 437 | * @see ::nRF905_nextmode_t 438 | */ 439 | bool TX(nRF905_nextmode_t nextMode, bool collisionAvoid); 440 | 441 | /** 442 | * @brief Enter receive mode. 443 | * 444 | * If the radio is currently transmitting then receive mode will be entered once it has finished. 445 | * This function will also automatically power-up the radio and leave standby mode. 446 | * 447 | * Example: `transceiver.RX();` 448 | * 449 | * @return (none) 450 | */ 451 | void RX(); 452 | 453 | /** 454 | * @brief Sleep. 455 | * 456 | * Current consumption will be 2.5uA in this mode. 457 | * Cancels any ongoing transmissions and clears the RX payload. 458 | * 459 | * Example: `transceiver.powerDown();` 460 | * 461 | * @return (none) 462 | */ 463 | void powerDown(); 464 | 465 | /** 466 | * @brief Enter standby mode. 467 | * 468 | * Radio will wait for any ongoing transmissions to complete before entering standby mode. 469 | * 470 | * If the radio was in power-down mode then there must be a 3ms delay between entering standby mode and beginning a transmission using .TX() with \p nextMode as ::NRF905_NEXTMODE_STANDBY or ::NRF905_NEXTMODE_RX otherwise the transmission will not start. 471 | * Calling .TX() while the radio is in power-down mode will automatically power-up the radio and wait 3ms before starting the transmission. 472 | * 473 | * Example: `transceiver.standby();` 474 | * 475 | * @return (none) 476 | */ 477 | void standby(); 478 | 479 | /** 480 | * @brief Get current radio mode 481 | * 482 | * Example: `if(transceiver.mode() == NRF905_MODE_POWERDOWN)` 483 | * 484 | * @return Current mode, see ::nRF905_mode_t 485 | * 486 | * @see ::nRF905_mode_t 487 | */ 488 | nRF905_mode_t mode(); 489 | 490 | /** 491 | * @brief Read configuration registers into byte array of ::NRF905_REGISTER_COUNT elements, mainly for debugging. 492 | * 493 | * Example: `transceiver.getConfigRegisters(regs);` 494 | * 495 | * @param [regs] Buffer for register data, size must be at least ::NRF905_REGISTER_COUNT bytes. 496 | * @return (none) 497 | */ 498 | void getConfigRegisters(void* regs); 499 | 500 | /** 501 | * @brief When running in interrupt mode this method must be called from the DR interrupt callback function. 502 | * 503 | * Example: `transceiver.interrupt_dr();` 504 | * 505 | * @return (none) 506 | */ 507 | void interrupt_dr(); 508 | 509 | /** 510 | * @brief When running in interrupt mode this method must be called from the AM interrupt callback function. 511 | * 512 | * Example: `transceiver.interrupt_am();` 513 | * 514 | * @return (none) 515 | */ 516 | void interrupt_am(); 517 | 518 | /** 519 | * @brief When running in polled mode this method should be called as often as possible. 520 | * 521 | * Maximum interval depends on how long it takes to receive a payload, which is around 6ms for 32 bytes, down to around 1.1ms for a 1 byte payload. If .poll() is not called often enough then events will be missed, the worse one being a missed \p onRxComplete event caused by reading a received payload, then another payload is received again without a .poll() call in between. 522 | * 523 | * Example: `transceiver.poll();` 524 | * 525 | * @return (none) 526 | */ 527 | void poll(); 528 | }; 529 | 530 | #endif /* NRF905_H_ */ 531 | -------------------------------------------------------------------------------- /src/nRF905_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Project: nRF905 Radio Library for Arduino 3 | * Author: Zak Kemble, contact@zakkemble.net 4 | * Copyright: (C) 2020 by Zak Kemble 5 | * License: GNU GPL v3 (see License.txt) 6 | * Web: https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 7 | */ 8 | 9 | #ifndef NRF905_CONFIG_H_ 10 | #define NRF905_CONFIG_H_ 11 | 12 | // Crystal frequency (the one the radio module is using) 13 | // NRF905_CLK_4MHZ 14 | // NRF905_CLK_8MHZ 15 | // NRF905_CLK_12MHZ 16 | // NRF905_CLK_16MHZ 17 | // NRF905_CLK_20MHZ 18 | #define NRF905_CLK_FREQ NRF905_CLK_16MHZ 19 | 20 | 21 | /////////////////// 22 | // Default radio settings 23 | /////////////////// 24 | 25 | // Frequency 26 | // Channel 0 is 422.4MHz for the 433MHz band, each channel increments the frequency by 100KHz, so channel 10 would be 423.4MHz 27 | // Channel 0 is 844.8MHz for the 868/915MHz band, each channel increments the frequency by 200KHz, so channel 10 would be 846.8MHz 28 | // Max channel is 511 (473.5MHz / 947.0MHz) 29 | #define NRF905_CHANNEL 10 30 | 31 | // Frequency band 32 | // 868 and 915 are actually the same thing 33 | // NRF905_BAND_433 34 | // NRF905_BAND_868 35 | // NRF905_BAND_915 36 | #define NRF905_BAND NRF905_BAND_433 37 | 38 | // Output power 39 | // n means negative, n10 = -10 40 | // NRF905_PWR_n10 (-10dBm = 100uW) 41 | // NRF905_PWR_n2 (-2dBm = 631uW) 42 | // NRF905_PWR_6 (6dBm = 4mW) 43 | // NRF905_PWR_10 (10dBm = 10mW) 44 | #define NRF905_PWR NRF905_PWR_10 45 | 46 | // Save a few mA by reducing receive sensitivity 47 | // NRF905_LOW_RX_DISABLE (Normal sensitivity) 48 | // NRF905_LOW_RX_ENABLE (Lower sensitivity) 49 | #define NRF905_LOW_RX NRF905_LOW_RX_DISABLE 50 | 51 | // Constantly retransmit payload while in transmit mode 52 | // Can be useful in areas with lots of interference, but you'll need to make sure you can differentiate between re-transmitted packets and new packets (like an ID number). 53 | // It will also block other transmissions if collision avoidance is enabled. 54 | // NRF905_AUTO_RETRAN_DISABLE 55 | // NRF905_AUTO_RETRAN_ENABLE 56 | #define NRF905_AUTO_RETRAN NRF905_AUTO_RETRAN_DISABLE 57 | 58 | // Output a clock signal on pin 3 of IC 59 | // NRF905_OUTCLK_DISABLE 60 | // NRF905_OUTCLK_500KHZ 61 | // NRF905_OUTCLK_1MHZ 62 | // NRF905_OUTCLK_2MHZ 63 | // NRF905_OUTCLK_4MHZ 64 | #define NRF905_OUTCLK NRF905_OUTCLK_DISABLE 65 | 66 | // CRC checksum 67 | // NRF905_CRC_DISABLE 68 | // NRF905_CRC_8 69 | // NRF905_CRC_16 70 | #define NRF905_CRC NRF905_CRC_16 71 | 72 | // Address size 73 | // The address is actually the SYNC part of the packet, just after the preamble and before the data. 74 | // Size should be either 1 or 4 bytes. 75 | // 1 byte is not recommended, a lot of false invalid packets will be received. 76 | #define NRF905_ADDR_SIZE_RX 4 77 | #define NRF905_ADDR_SIZE_TX 4 78 | 79 | // Payload size (1 - 32) 80 | #define NRF905_PAYLOAD_SIZE_RX 32 //NRF905_MAX_PAYLOAD 81 | #define NRF905_PAYLOAD_SIZE_TX 32 //NRF905_MAX_PAYLOAD 82 | 83 | #define NRF905_ADDRESS 0xE7E7E7E7 84 | 85 | #endif /* NRF905_CONFIG_H_ */ 86 | -------------------------------------------------------------------------------- /src/nRF905_defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Project: nRF905 Radio Library for Arduino 3 | * Author: Zak Kemble, contact@zakkemble.net 4 | * Copyright: (C) 2020 by Zak Kemble 5 | * License: GNU GPL v3 (see License.txt) 6 | * Web: https://blog.zakkemble.net/nrf905-avrarduino-librarydriver/ 7 | */ 8 | 9 | #ifndef NRF905_DEFS_H_ 10 | #define NRF905_DEFS_H_ 11 | 12 | // Instructions 13 | #define NRF905_CMD_NOP 0xFF 14 | #define NRF905_CMD_W_CONFIG 0x00 15 | #define NRF905_CMD_R_CONFIG 0x10 16 | #define NRF905_CMD_W_TX_PAYLOAD 0x20 17 | #define NRF905_CMD_R_TX_PAYLOAD 0x21 18 | #define NRF905_CMD_W_TX_ADDRESS 0x22 19 | #define NRF905_CMD_R_TX_ADDRESS 0x23 20 | #define NRF905_CMD_R_RX_PAYLOAD 0x24 21 | #define NRF905_CMD_CHAN_CONFIG 0x80 22 | 23 | // Registers 24 | #define NRF905_REG_CHANNEL 0x00 25 | #define NRF905_REG_CONFIG1 0x01 26 | #define NRF905_REG_ADDR_WIDTH 0x02 27 | #define NRF905_REG_RX_PAYLOAD_SIZE 0x03 28 | #define NRF905_REG_TX_PAYLOAD_SIZE 0x04 29 | #define NRF905_REG_RX_ADDRESS 0x05 30 | #define NRF905_REG_CONFIG2 0x09 31 | 32 | 33 | // TODO remove 34 | #define NRF905_REG_AUTO_RETRAN NRF905_REG_CONFIG1 35 | #define NRF905_REG_LOW_RX NRF905_REG_CONFIG1 36 | #define NRF905_REG_PWR NRF905_REG_CONFIG1 37 | #define NRF905_REG_BAND NRF905_REG_CONFIG1 38 | #define NRF905_REG_CRC NRF905_REG_CONFIG2 39 | #define NRF905_REG_CLK NRF905_REG_CONFIG2 40 | #define NRF905_REG_OUTCLK NRF905_REG_CONFIG2 41 | #define NRF905_REG_OUTCLK_FREQ NRF905_REG_CONFIG2 42 | 43 | 44 | // Clock options 45 | #define NRF905_CLK_4MHZ 0x00 46 | #define NRF905_CLK_8MHZ 0x08 47 | #define NRF905_CLK_12MHZ 0x10 48 | #define NRF905_CLK_16MHZ 0x18 49 | #define NRF905_CLK_20MHZ 0x20 50 | 51 | // Register masks 52 | #define NRF905_MASK_CHANNEL 0xFE 53 | #define NRF905_MASK_AUTO_RETRAN ~(NRF905_AUTO_RETRAN_ENABLE | NRF905_AUTO_RETRAN_DISABLE) //0xDF 54 | #define NRF905_MASK_LOW_RX ~(NRF905_LOW_RX_ENABLE | NRF905_LOW_RX_DISABLE) //0xEF 55 | #define NRF905_MASK_PWR ~(NRF905_PWR_n10 | NRF905_PWR_n2 | NRF905_PWR_6 | NRF905_PWR_10) //0xF3 56 | #define NRF905_MASK_BAND ~(NRF905_BAND_433 | NRF905_BAND_868 | NRF905_BAND_915) //0xFD 57 | #define NRF905_MASK_CRC (uint8_t)(~(NRF905_CRC_DISABLE | NRF905_CRC_8 | NRF905_CRC_16)) //0x3F // typecast to stop compiler moaning about large integer truncation 58 | #define NRF905_MASK_CLK ~(NRF905_CLK_4MHZ | NRF905_CLK_8MHZ | NRF905_CLK_12MHZ | NRF905_CLK_16MHZ | NRF905_CLK_20MHZ) //0xC7 59 | #define NRF905_MASK_OUTCLK ~(NRF905_OUTCLK_DISABLE | NRF905_OUTCLK_4MHZ | NRF905_OUTCLK_2MHZ | NRF905_OUTCLK_1MHZ | NRF905_OUTCLK_500KHZ) // 0xF8 60 | 61 | // Bit positions 62 | #define NRF905_STATUS_DR 5 63 | #define NRF905_STATUS_AM 7 64 | 65 | /** 66 | * @brief Save a few mA by reducing receive sensitivity. 67 | */ 68 | typedef enum 69 | { 70 | NRF905_LOW_RX_DISABLE = 0x00, ///< Disable low power receive 71 | NRF905_LOW_RX_ENABLE = 0x10 ///< Enable low power receive 72 | } nRF905_low_rx_t; 73 | 74 | /** 75 | * @brief Auto re-transmit options. 76 | */ 77 | typedef enum 78 | { 79 | NRF905_AUTO_RETRAN_DISABLE = 0x00, ///< Disable auto re-transmit 80 | NRF905_AUTO_RETRAN_ENABLE = 0x20 ///< Enable auto re-transmit 81 | } nRF905_auto_retran_t; 82 | 83 | /** 84 | * @brief Address size. 85 | * 86 | * This is actually used as the SYNC word 87 | */ 88 | typedef enum 89 | { 90 | NRF905_ADDR_SIZE_1 = 0x01, ///< 1 byte (not recommended, a lot of false invalid packets will be received) 91 | NRF905_ADDR_SIZE_4 = 0x04, ///< 4 bytes 92 | } nRF905_addr_size_t; 93 | 94 | #endif /* NRF905_DEFS_H_ */ 95 | --------------------------------------------------------------------------------