Library for HopeRF RFM22 / RFM22B transceiver module ported to mbed. Original Software from Mike McCauley (mikem@open.com.au) . See http://www.open.com.au/mikem/arduino/RF22/

Dependents:   RF22_MAX_test_Send Geofence_receiver Geofence_sender Geofence_sender ... more

More Info about RFM22-modules like connecting and a demo-program see RF22-Notebook

Committer:
charly
Date:
Tue Feb 14 19:39:36 2012 +0000
Revision:
0:79c6d0071c4c
Child:
5:0386600f3408
Initial Port - Quick and Dirty !!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charly 0:79c6d0071c4c 1 // RF22.h
charly 0:79c6d0071c4c 2 // Author: Mike McCauley (mikem@open.com.au)
charly 0:79c6d0071c4c 3 // Copyright (C) 2011 Mike McCauley
charly 0:79c6d0071c4c 4 // $Id: RF22.h,v 1.19 2011/10/09 21:22:24 mikem Exp mikem $
charly 0:79c6d0071c4c 5 // ported to mbed by Karl Zweimueller
charly 0:79c6d0071c4c 6 //
charly 0:79c6d0071c4c 7 /// \mainpage RF22 library for Arduino
charly 0:79c6d0071c4c 8 ///
charly 0:79c6d0071c4c 9 /// This is the Arduino RF22 library.
charly 0:79c6d0071c4c 10 /// It provides an object-oriented interface for sending and receiving data messages with Hope-RF
charly 0:79c6d0071c4c 11 /// RF22B based radio modules, and compatible chips and modules, including the RFM22B transceiver module such as
charly 0:79c6d0071c4c 12 /// this one: http://www.sparkfun.com/products/10153
charly 0:79c6d0071c4c 13 ///
charly 0:79c6d0071c4c 14 /// RF22 also supports some of the features of ZigBee and XBee,
charly 0:79c6d0071c4c 15 /// (such as mesh routing and automatic route discovery),
charly 0:79c6d0071c4c 16 /// but with a much less complicated system and less expensive radios.
charly 0:79c6d0071c4c 17 ///
charly 0:79c6d0071c4c 18 /// The Hope-RF (http://www.hoperf.com) RFM22B (http://www.hoperf.com/rf_fsk/fsk/RFM22B.htm)
charly 0:79c6d0071c4c 19 /// is a low-cost ISM transceiver module. It supports FSK, GFSK, OOK over a wide
charly 0:79c6d0071c4c 20 /// range of frequencies and programmable data rates.
charly 0:79c6d0071c4c 21 ///
charly 0:79c6d0071c4c 22 /// This library provides functions for sending and receiving messages of up to 255 octets on any
charly 0:79c6d0071c4c 23 /// frequency supported by the RF22B, in a range of predefined data rates and frequency deviations.
charly 0:79c6d0071c4c 24 /// Frequency can be set with 312Hz precision to any frequency from 240.0MHz to 960.0MHz.
charly 0:79c6d0071c4c 25 ///
charly 0:79c6d0071c4c 26 /// Up to 2 RF22B modules can be connected to an Arduino, permitting the construction of translators
charly 0:79c6d0071c4c 27 /// and frequency changers, etc.
charly 0:79c6d0071c4c 28 ///
charly 0:79c6d0071c4c 29 /// This library provides classes for
charly 0:79c6d0071c4c 30 /// - RF22: unaddressed, unreliable messages
charly 0:79c6d0071c4c 31 /// - RF22Datagram: addressed, unreliable messages
charly 0:79c6d0071c4c 32 /// - RF22ReliableDatagram: addressed, reliable, retransmitted, acknowledged messages.
charly 0:79c6d0071c4c 33 /// - RF22Router: multi hop delivery from source node to destination node via 0 or more intermediate nodes
charly 0:79c6d0071c4c 34 /// - RF22Mesh: multi hop delivery with automatic route discovery and rediscovery.
charly 0:79c6d0071c4c 35 ///
charly 0:79c6d0071c4c 36 /// The following modulation types are suppported with a range of modem configurations for
charly 0:79c6d0071c4c 37 /// common data rates and frequency deviations:
charly 0:79c6d0071c4c 38 /// - GFSK Gaussian Frequency Shift Keying
charly 0:79c6d0071c4c 39 /// - FSK Frequency Shift Keying
charly 0:79c6d0071c4c 40 /// - OOK On-Off Keying
charly 0:79c6d0071c4c 41 ///
charly 0:79c6d0071c4c 42 /// Support for other RF22B features such as on-chip temperature measurement, analog-digital
charly 0:79c6d0071c4c 43 /// converter, transmitter power control etc is also provided.
charly 0:79c6d0071c4c 44 ///
charly 0:79c6d0071c4c 45 /// The latest version of this documentation can be downloaded from
charly 0:79c6d0071c4c 46 /// http://www.open.com.au/mikem/arduino/RF22
charly 0:79c6d0071c4c 47 ///
charly 0:79c6d0071c4c 48 /// Example Arduino programs are included to show the main modes of use.
charly 0:79c6d0071c4c 49 ///
charly 0:79c6d0071c4c 50 /// The version of the package that this documentation refers to can be downloaded
charly 0:79c6d0071c4c 51 /// from http://www.open.com.au/mikem/arduino/RF22/RF22-1.10.zip
charly 0:79c6d0071c4c 52 /// You can find the latest version at http://www.open.com.au/mikem/arduino/RF22
charly 0:79c6d0071c4c 53 ///
charly 0:79c6d0071c4c 54 /// Tested on Arduino Diecimila and Mega with arduino-0021
charly 0:79c6d0071c4c 55 /// on OpenSuSE 11.1 and avr-libc-1.6.1-1.15,
charly 0:79c6d0071c4c 56 /// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5.
charly 0:79c6d0071c4c 57 /// With HopeRF RFM22 modules that appear to have RF22B chips on board:
charly 0:79c6d0071c4c 58 /// - Device Type Code = 0x08 (RX/TRX)
charly 0:79c6d0071c4c 59 /// - Version Code = 0x06
charly 0:79c6d0071c4c 60 /// It is known not to work on Diecimila. Dont bother trying.
charly 0:79c6d0071c4c 61 ///
charly 0:79c6d0071c4c 62 /// \par Packet Format
charly 0:79c6d0071c4c 63 ///
charly 0:79c6d0071c4c 64 /// All messages sent and received by this RF22 library must conform to this packet format:
charly 0:79c6d0071c4c 65 ///
charly 0:79c6d0071c4c 66 /// - 8 nibbles (4 octets) PREAMBLE
charly 0:79c6d0071c4c 67 /// - 2 octets SYNC 0x2d, 0xd4
charly 0:79c6d0071c4c 68 /// - 4 octets HEADER: (TO, FROM, ID, FLAGS)
charly 0:79c6d0071c4c 69 /// - 1 octet LENGTH (0 to 255), number of octets in DATA
charly 0:79c6d0071c4c 70 /// - 0 to 255 octets DATA
charly 0:79c6d0071c4c 71 /// - 2 octets CRC computed with CRC16(IBM), computed on HEADER, LENGTH and DATA
charly 0:79c6d0071c4c 72 ///
charly 0:79c6d0071c4c 73 /// For technical reasons, the message format is not compatible with the
charly 0:79c6d0071c4c 74 /// 'HopeRF Radio Transceiver Message Library for Arduino' http://www.open.com.au/mikem/arduino/HopeRF from the same author. Nor is it compatible with
charly 0:79c6d0071c4c 75 /// 'Virtual Wire' http://www.open.com.au/mikem/arduino/VirtualWire.pdf also from the same author.
charly 0:79c6d0071c4c 76 ///
charly 0:79c6d0071c4c 77 /// \par Connecting RFM-22 to Arduino
charly 0:79c6d0071c4c 78 /// The physical connection between the RF22B and the Arduino require 3.3V, the 3 x SPI pins (SCK, SDI, SDO),
charly 0:79c6d0071c4c 79 /// a Slave Select pin and an interrupt pin.
charly 0:79c6d0071c4c 80 /// Note also that on the RFF22B, it is required to control the TX_ANT and X_ANT pins of the RFM22 in order to enable the
charly 0:79c6d0071c4c 81 /// antenna connection. The RF22 library is configured so that GPIO0 and GPIO1 outputs can control TX_ANT and RX_ANT input pins
charly 0:79c6d0071c4c 82 /// automatically. You must connect GPIO0 to TX_ANT and GPIO1 to RX_ANT for this automatic antenna switching to occur.
charly 0:79c6d0071c4c 83 ///
charly 0:79c6d0071c4c 84 /// Connect the RFM-22 to most Arduino's like this (Caution, Arduino Mega has different pins for SPI,
charly 0:79c6d0071c4c 85 /// see below):
charly 0:79c6d0071c4c 86 /// \code
charly 0:79c6d0071c4c 87 /// Arduino RFM-22B
charly 0:79c6d0071c4c 88 /// GND----------GND-\ (ground in)
charly 0:79c6d0071c4c 89 /// SDN-/ (shutdown in)
charly 0:79c6d0071c4c 90 /// 3V3----------VCC (3.3V in)
charly 0:79c6d0071c4c 91 /// interrupt 0 pin D2-----------NIRQ (interrupt request out)
charly 0:79c6d0071c4c 92 /// SS pin D10----------NSEL (chip select in)
charly 0:79c6d0071c4c 93 /// SCK pin D13----------SCK (SPI clock in)
charly 0:79c6d0071c4c 94 /// MOSI pin D11----------SDI (SPI Data in)
charly 0:79c6d0071c4c 95 /// MISO pin D12----------SDO (SPI data out)
charly 0:79c6d0071c4c 96 /// /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT
charly 0:79c6d0071c4c 97 /// \--TX_ANT (TX antenna control in)
charly 0:79c6d0071c4c 98 /// /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT
charly 0:79c6d0071c4c 99 /// \--RX_ANT (RX antenna control in)
charly 0:79c6d0071c4c 100 /// \endcode
charly 0:79c6d0071c4c 101 /// For an Arduino Mega:
charly 0:79c6d0071c4c 102 /// \code
charly 0:79c6d0071c4c 103 /// Mega RFM-22B
charly 0:79c6d0071c4c 104 /// GND----------GND-\ (ground in)
charly 0:79c6d0071c4c 105 /// SDN-/ (shutdown in)
charly 0:79c6d0071c4c 106 /// 3V3----------VCC (3.3V in)
charly 0:79c6d0071c4c 107 /// interrupt 0 pin D2-----------NIRQ (interrupt request out)
charly 0:79c6d0071c4c 108 /// SS pin D10----------NSEL (chip select in)
charly 0:79c6d0071c4c 109 /// SCK pin D52----------SCK (SPI clock in)
charly 0:79c6d0071c4c 110 /// MOSI pin D51----------SDI (SPI Data in)
charly 0:79c6d0071c4c 111 /// MISO pin D50----------SDO (SPI data out)
charly 0:79c6d0071c4c 112 /// /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT
charly 0:79c6d0071c4c 113 /// \--TX_ANT (TX antenna control in)
charly 0:79c6d0071c4c 114 /// /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT
charly 0:79c6d0071c4c 115 /// \--RX_ANT (RX antenna control in)
charly 0:79c6d0071c4c 116 /// \endcode
charly 0:79c6d0071c4c 117 /// and you can then use the default constructor RF22().
charly 0:79c6d0071c4c 118 /// You can override the default settings for the SS pin and the interrupt
charly 0:79c6d0071c4c 119 /// in the RF22 constructor if you wish to connect the slave select SS to other than pin D10
charly 0:79c6d0071c4c 120 /// or the interrupt request to other than pin D2.
charly 0:79c6d0071c4c 121 /// It is possible to have 2 radios conected to one arduino, provided each radio has its own
charly 0:79c6d0071c4c 122 /// SS and interrupt line (SCK, SDI and SDO are common to both radios)
charly 0:79c6d0071c4c 123 ///
charly 0:79c6d0071c4c 124 /// \par Example programs
charly 0:79c6d0071c4c 125 ///
charly 0:79c6d0071c4c 126 /// The following example programs are provided:
charly 0:79c6d0071c4c 127 /// - rf22_client, rf22_server: Simple client/server pair using RF22 class
charly 0:79c6d0071c4c 128 /// - rf22_datagram_client, rf22_datagram_server: Simple client/server pair using RF22Datagram class
charly 0:79c6d0071c4c 129 /// - rf22_reliable_datagram_client, rf22_reliable_datagram_server:
charly 0:79c6d0071c4c 130 /// Simple client/server pair using RF22ReliableDatagram class
charly 0:79c6d0071c4c 131 /// - rf22_router_client, rf22_router_server1, rf22_router_server2, rf22_router_server3:
charly 0:79c6d0071c4c 132 /// Simple RF22Router network. Requires Arduino Mega.
charly 0:79c6d0071c4c 133 /// - rf22_mesh_client, rf22_mesh_server1, rf22_mesh_server2, rf22_mesh_server3:
charly 0:79c6d0071c4c 134 /// Simple RF22Mesh network. Requires Arduino Mega.
charly 0:79c6d0071c4c 135 /// - rf22_test: Some test code used during development, shows how to call some support functions
charly 0:79c6d0071c4c 136 /// - rf22_snoop: Dumps in ASCII the contents of all RF22 messages received
charly 0:79c6d0071c4c 137 /// - rf22_specan: Simple spectrum analyser using the RSSI measurements of the RF22
charly 0:79c6d0071c4c 138 /// (see <a href="specan1.png">Sample output</a> showing a plot from 395.0MHz to 396.0MHz of a
charly 0:79c6d0071c4c 139 /// signal generator at 395.5MHz amplitude modulated at 100% 1kHz)
charly 0:79c6d0071c4c 140 ///
charly 0:79c6d0071c4c 141 /// \par Memory
charly 0:79c6d0071c4c 142 ///
charly 0:79c6d0071c4c 143 /// The RF22 library requires non-trivial amounts of memory. The sample programs above all compile to
charly 0:79c6d0071c4c 144 /// about 9 to 14kbytes each, which will fit in the flash proram memory of most Arduinos. However,
charly 0:79c6d0071c4c 145 /// the RAM requirements are more critical. Most sample programs above will run on Duemilanova,
charly 0:79c6d0071c4c 146 /// but not on Diecimila. Even on Duemilanova, the RAM requirements are very close to the
charly 0:79c6d0071c4c 147 /// available memory of 2kbytes. Therefore, you should be vary sparing with RAM use in programs that use
charly 0:79c6d0071c4c 148 /// the RF22 library on Duemilanova.
charly 0:79c6d0071c4c 149 ///
charly 0:79c6d0071c4c 150 /// The sample RF22Router and RF22Mesh programs compile to about 14kbytes,
charly 0:79c6d0071c4c 151 /// and require more RAM than the others.
charly 0:79c6d0071c4c 152 /// They will not run on Duemilanova or Diecimila, but will run on Arduino Mega.
charly 0:79c6d0071c4c 153 ///
charly 0:79c6d0071c4c 154 /// It is often hard to accurately identify when you are hitting RAM limits on Arduino.
charly 0:79c6d0071c4c 155 /// The symptoms can include:
charly 0:79c6d0071c4c 156 /// - Mysterious crashes and restarts
charly 0:79c6d0071c4c 157 /// - Changes in behaviour when seemingly unrelated changes are made (such as adding print() statements)
charly 0:79c6d0071c4c 158 /// - Hanging
charly 0:79c6d0071c4c 159 /// - Output from Serial.print() not appearing
charly 0:79c6d0071c4c 160 ///
charly 0:79c6d0071c4c 161 /// With an Arduino Mega, with 8 kbytes of SRAM, there is much more RAM headroom for
charly 0:79c6d0071c4c 162 /// your own elaborate programs.
charly 0:79c6d0071c4c 163 /// This library is reported not to work with Arduino Pro Mini and Arduino UNO, but these have not been tested here.
charly 0:79c6d0071c4c 164 ///
charly 0:79c6d0071c4c 165 /// \par Installation
charly 0:79c6d0071c4c 166 ///
charly 0:79c6d0071c4c 167 /// Install in the usual way: unzip the distribution zip file to the libraries
charly 0:79c6d0071c4c 168 /// sub-folder of your sketchbook.
charly 0:79c6d0071c4c 169 ///
charly 0:79c6d0071c4c 170 /// This software is Copyright (C) 2011 Mike McCauley. Use is subject to license
charly 0:79c6d0071c4c 171 /// conditions. The main licensing options available are GPL V2 or Commercial:
charly 0:79c6d0071c4c 172 ///
charly 0:79c6d0071c4c 173 /// \par Open Source Licensing GPL V2
charly 0:79c6d0071c4c 174 ///
charly 0:79c6d0071c4c 175 /// This is the appropriate option if you want to share the source code of your
charly 0:79c6d0071c4c 176 /// application with everyone you distribute it to, and you also want to give them
charly 0:79c6d0071c4c 177 /// the right to share who uses it. If you wish to use this software under Open
charly 0:79c6d0071c4c 178 /// Source Licensing, you must contribute all your source code to the open source
charly 0:79c6d0071c4c 179 /// community in accordance with the GPL Version 2 when your application is
charly 0:79c6d0071c4c 180 /// distributed. See http://www.gnu.org/copyleft/gpl.html
charly 0:79c6d0071c4c 181 ///
charly 0:79c6d0071c4c 182 /// \par Commercial Licensing
charly 0:79c6d0071c4c 183 ///
charly 0:79c6d0071c4c 184 /// This is the appropriate option if you are creating proprietary applications
charly 0:79c6d0071c4c 185 /// and you are not prepared to distribute and share the source code of your
charly 0:79c6d0071c4c 186 /// application. Contact info@open.com.au for details.
charly 0:79c6d0071c4c 187 ///
charly 0:79c6d0071c4c 188 /// \par Revision History
charly 0:79c6d0071c4c 189 ///
charly 0:79c6d0071c4c 190 /// \version 1.0 Initial release
charly 0:79c6d0071c4c 191 ///
charly 0:79c6d0071c4c 192 /// \version 1.1 Added rf22_snoop and rf22_specan examples
charly 0:79c6d0071c4c 193 ///
charly 0:79c6d0071c4c 194 /// \version 1.2 Changed default modulation to FSK_Rb2_4Fd36
charly 0:79c6d0071c4c 195 /// Some internal reorganisation.
charly 0:79c6d0071c4c 196 /// Added RF22Router and RF22Mesh classes plus sample programs to support multi-hop and
charly 0:79c6d0071c4c 197 /// automatic route discovery.
charly 0:79c6d0071c4c 198 /// \version 1.3 Removed some unnecessary debug messages. Added virtual doArp and isPhysicalAddress
charly 0:79c6d0071c4c 199 /// functions to RF22Mesh to support other physical address interpretation schemes (IPV4/IPV6?)
charly 0:79c6d0071c4c 200 /// \version 1.4 RF22Router and RF22Mesh were inadvertently left out of the distro.
charly 0:79c6d0071c4c 201 /// \version 1.5 Improvements contributed by Peter Mousley: Modem config table is now in flash rather than SRAM,
charly 0:79c6d0071c4c 202 /// saving 400 bytes of SRAM. Allow a user-defined buffer size. Thanks Peter.
charly 0:79c6d0071c4c 203 /// \version 1.6 Fixed some minor typos on doc and clarified that this code is for the RF22B. Fixed errors in the
charly 0:79c6d0071c4c 204 /// definition of the power output constants which were incorrectly set to the values for the RF22.
charly 0:79c6d0071c4c 205 /// Reported by Fred Slamen. If you were using a previous version of RF22, you probably were not getting the output
charly 0:79c6d0071c4c 206 /// power you thought.
charly 0:79c6d0071c4c 207 /// \version 1.7 Added code to initialise GPIO0 and GPIO1 so they can automatically control the TX_ANT and RX_ANT
charly 0:79c6d0071c4c 208 /// antenna switching inputs. You must connect GPIO0 to TX_ANT and GPIO1 to RX_ANT for this automatic
charly 0:79c6d0071c4c 209 /// antenna switching to occur. Updated doc to reflect this new connection requirement
charly 0:79c6d0071c4c 210 /// \version 1.8 Changed the name of RF22_ENLBD in RF22_REG_06_INTERRUPT_ENABLE2 to RF22_ENLBDI because it collided
charly 0:79c6d0071c4c 211 /// with a define of the same name in RF22_REG_07_OPERATING_MODE. RF22_REG_05_INTERRUPT_ENABLE1 enable mask
charly 0:79c6d0071c4c 212 /// incorrectly used RF22_IFFERROR instead of RF22_ENFFERR. Reported by Steffan Woltjer.
charly 0:79c6d0071c4c 213 /// \version 1.9 Fixed typos in RF22_REG_21_CLOCk*. Reported by Steffan Woltjer.
charly 0:79c6d0071c4c 214 /// \version 1.10 Fixed a problem where a IFFERR during transmission could cause an infinite loop and a hang.
charly 0:79c6d0071c4c 215 /// Reported by Raymond Gilbert.
charly 0:79c6d0071c4c 216 ///
charly 0:79c6d0071c4c 217 ///
charly 0:79c6d0071c4c 218 /// \author Mike McCauley (mikem@open.com.au)
charly 0:79c6d0071c4c 219
charly 0:79c6d0071c4c 220 #ifndef RF22_h
charly 0:79c6d0071c4c 221 #define RF22_h
charly 0:79c6d0071c4c 222 #include "mbed.h"
charly 0:79c6d0071c4c 223
charly 0:79c6d0071c4c 224 #define boolean bool
charly 0:79c6d0071c4c 225
charly 0:79c6d0071c4c 226 //#include <wiring.h>
charly 0:79c6d0071c4c 227 // These defs cause trouble on some versions of Arduino
charly 0:79c6d0071c4c 228 #undef round
charly 0:79c6d0071c4c 229 #undef double
charly 0:79c6d0071c4c 230
charly 0:79c6d0071c4c 231 // This is the bit in the SPI address that marks it as a write
charly 0:79c6d0071c4c 232 #define RF22_SPI_WRITE_MASK 0x80
charly 0:79c6d0071c4c 233
charly 0:79c6d0071c4c 234 // This is the maximum message length that can be supported by this library. Limited by
charly 0:79c6d0071c4c 235 // the message length octet in the header. Yes, 255 is correct even though the FIFO size in the RF22 is only
charly 0:79c6d0071c4c 236 // 64 octets. We use interrupts to refil the Tx FIFO during transmission and to empty the
charly 0:79c6d0071c4c 237 // Rx FIF during reception
charly 0:79c6d0071c4c 238 // Can be pre-defined to a smaller size (to save SRAM) prior to including this header
charly 0:79c6d0071c4c 239 #ifndef RF22_MAX_MESSAGE_LEN
charly 0:79c6d0071c4c 240 #define RF22_MAX_MESSAGE_LEN 255
charly 0:79c6d0071c4c 241 #endif
charly 0:79c6d0071c4c 242
charly 0:79c6d0071c4c 243 // Max number of octets the RF22 Rx and Tx FIFOs can hold
charly 0:79c6d0071c4c 244 #define RF22_FIFO_SIZE 64
charly 0:79c6d0071c4c 245
charly 0:79c6d0071c4c 246 // Keep track of the mode the RF22 is in
charly 0:79c6d0071c4c 247 #define RF22_MODE_IDLE 0
charly 0:79c6d0071c4c 248 #define RF22_MODE_RX 1
charly 0:79c6d0071c4c 249 #define RF22_MODE_TX 2
charly 0:79c6d0071c4c 250
charly 0:79c6d0071c4c 251 // These values we set for FIFO thresholds are actually the same as the POR values
charly 0:79c6d0071c4c 252 #define RF22_TXFFAEM_THRESHOLD 4
charly 0:79c6d0071c4c 253 #define RF22_RXFFAFULL_THRESHOLD 55
charly 0:79c6d0071c4c 254
charly 0:79c6d0071c4c 255 // This is the default node address,
charly 0:79c6d0071c4c 256 #define RF22_DEFAULT_NODE_ADDRESS 0
charly 0:79c6d0071c4c 257
charly 0:79c6d0071c4c 258 // This address in the TO addreess signifies a broadcast
charly 0:79c6d0071c4c 259 #define RF22_BROADCAST_ADDRESS 0xff
charly 0:79c6d0071c4c 260
charly 0:79c6d0071c4c 261 // Number of registers to be passed to setModemConfig()
charly 0:79c6d0071c4c 262 #define RF22_NUM_MODEM_CONFIG_REGS 18
charly 0:79c6d0071c4c 263
charly 0:79c6d0071c4c 264 // Register names
charly 0:79c6d0071c4c 265 #define RF22_REG_00_DEVICE_TYPE 0x00
charly 0:79c6d0071c4c 266 #define RF22_REG_01_VERSION_CODE 0x01
charly 0:79c6d0071c4c 267 #define RF22_REG_02_DEVICE_STATUS 0x02
charly 0:79c6d0071c4c 268 #define RF22_REG_03_INTERRUPT_STATUS1 0x03
charly 0:79c6d0071c4c 269 #define RF22_REG_04_INTERRUPT_STATUS2 0x04
charly 0:79c6d0071c4c 270 #define RF22_REG_05_INTERRUPT_ENABLE1 0x05
charly 0:79c6d0071c4c 271 #define RF22_REG_06_INTERRUPT_ENABLE2 0x06
charly 0:79c6d0071c4c 272 #define RF22_REG_07_OPERATING_MODE1 0x07
charly 0:79c6d0071c4c 273 #define RF22_REG_08_OPERATING_MODE2 0x08
charly 0:79c6d0071c4c 274 #define RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE 0x09
charly 0:79c6d0071c4c 275 #define RF22_REG_0A_UC_OUTPUT_CLOCK 0x0a
charly 0:79c6d0071c4c 276 #define RF22_REG_0B_GPIO_CONFIGURATION0 0x0b
charly 0:79c6d0071c4c 277 #define RF22_REG_0C_GPIO_CONFIGURATION1 0x0c
charly 0:79c6d0071c4c 278 #define RF22_REG_0D_GPIO_CONFIGURATION2 0x0d
charly 0:79c6d0071c4c 279 #define RF22_REG_0E_IO_PORT_CONFIGURATION 0x0e
charly 0:79c6d0071c4c 280 #define RF22_REG_0F_ADC_CONFIGURATION 0x0f
charly 0:79c6d0071c4c 281 #define RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10
charly 0:79c6d0071c4c 282 #define RF22_REG_11_ADC_VALUE 0x11
charly 0:79c6d0071c4c 283 #define RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12
charly 0:79c6d0071c4c 284 #define RF22_REG_13_TEMPERATURE_VALUE_OFFSET 0x13
charly 0:79c6d0071c4c 285 #define RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14
charly 0:79c6d0071c4c 286 #define RF22_REG_15_WAKEUP_TIMER_PERIOD2 0x15
charly 0:79c6d0071c4c 287 #define RF22_REG_16_WAKEUP_TIMER_PERIOD3 0x16
charly 0:79c6d0071c4c 288 #define RF22_REG_17_WAKEUP_TIMER_VALUE1 0x17
charly 0:79c6d0071c4c 289 #define RF22_REG_18_WAKEUP_TIMER_VALUE2 0x18
charly 0:79c6d0071c4c 290 #define RF22_REG_19_LDC_MODE_DURATION 0x19
charly 0:79c6d0071c4c 291 #define RF22_REG_1A_LOW_BATTERY_DETECTOR_THRESHOLD 0x1a
charly 0:79c6d0071c4c 292 #define RF22_REG_1B_BATTERY_VOLTAGE_LEVEL 0x1b
charly 0:79c6d0071c4c 293 #define RF22_REG_1C_IF_FILTER_BANDWIDTH 0x1c
charly 0:79c6d0071c4c 294 #define RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d
charly 0:79c6d0071c4c 295 #define RF22_REG_1E_AFC_TIMING_CONTROL 0x1e
charly 0:79c6d0071c4c 296 #define RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE 0x1f
charly 0:79c6d0071c4c 297 #define RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE 0x20
charly 0:79c6d0071c4c 298 #define RF22_REG_21_CLOCK_RECOVERY_OFFSET2 0x21
charly 0:79c6d0071c4c 299 #define RF22_REG_22_CLOCK_RECOVERY_OFFSET1 0x22
charly 0:79c6d0071c4c 300 #define RF22_REG_23_CLOCK_RECOVERY_OFFSET0 0x23
charly 0:79c6d0071c4c 301 #define RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1 0x24
charly 0:79c6d0071c4c 302 #define RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0 0x25
charly 0:79c6d0071c4c 303 #define RF22_REG_26_RSSI 0x26
charly 0:79c6d0071c4c 304 #define RF22_REG_27_RSSI_THRESHOLD 0x27
charly 0:79c6d0071c4c 305 #define RF22_REG_28_ANTENNA_DIVERSITY1 0x28
charly 0:79c6d0071c4c 306 #define RF22_REG_29_ANTENNA_DIVERSITY2 0x29
charly 0:79c6d0071c4c 307 #define RF22_REG_2A_AFC_LIMITER 0x2a
charly 0:79c6d0071c4c 308 #define RF22_REG_2B_AFC_CORRECTION_READ 0x2b
charly 0:79c6d0071c4c 309 #define RF22_REG_2C_OOK_COUNTER_VALUE_1 0x2c
charly 0:79c6d0071c4c 310 #define RF22_REG_2D_OOK_COUNTER_VALUE_2 0x2d
charly 0:79c6d0071c4c 311 #define RF22_REG_2E_SLICER_PEAK_HOLD 0x2e
charly 0:79c6d0071c4c 312 #define RF22_REG_30_DATA_ACCESS_CONTROL 0x30
charly 0:79c6d0071c4c 313 #define RF22_REG_31_EZMAC_STATUS 0x31
charly 0:79c6d0071c4c 314 #define RF22_REG_32_HEADER_CONTROL1 0x32
charly 0:79c6d0071c4c 315 #define RF22_REG_33_HEADER_CONTROL2 0x33
charly 0:79c6d0071c4c 316 #define RF22_REG_34_PREAMBLE_LENGTH 0x34
charly 0:79c6d0071c4c 317 #define RF22_REG_35_PREAMBLE_DETECTION_CONTROL1 0x35
charly 0:79c6d0071c4c 318 #define RF22_REG_36_SYNC_WORD3 0x36
charly 0:79c6d0071c4c 319 #define RF22_REG_37_SYNC_WORD2 0x37
charly 0:79c6d0071c4c 320 #define RF22_REG_38_SYNC_WORD1 0x38
charly 0:79c6d0071c4c 321 #define RF22_REG_39_SYNC_WORD0 0x39
charly 0:79c6d0071c4c 322 #define RF22_REG_3A_TRANSMIT_HEADER3 0x3a
charly 0:79c6d0071c4c 323 #define RF22_REG_3B_TRANSMIT_HEADER2 0x3b
charly 0:79c6d0071c4c 324 #define RF22_REG_3C_TRANSMIT_HEADER1 0x3c
charly 0:79c6d0071c4c 325 #define RF22_REG_3D_TRANSMIT_HEADER0 0x3d
charly 0:79c6d0071c4c 326 #define RF22_REG_3E_PACKET_LENGTH 0x3e
charly 0:79c6d0071c4c 327 #define RF22_REG_3F_CHECK_HEADER3 0x3f
charly 0:79c6d0071c4c 328 #define RF22_REG_40_CHECK_HEADER2 0x40
charly 0:79c6d0071c4c 329 #define RF22_REG_41_CHECK_HEADER1 0x41
charly 0:79c6d0071c4c 330 #define RF22_REG_42_CHECK_HEADER0 0x42
charly 0:79c6d0071c4c 331 #define RF22_REG_43_HEADER_ENABLE3 0x43
charly 0:79c6d0071c4c 332 #define RF22_REG_44_HEADER_ENABLE2 0x44
charly 0:79c6d0071c4c 333 #define RF22_REG_45_HEADER_ENABLE1 0x45
charly 0:79c6d0071c4c 334 #define RF22_REG_46_HEADER_ENABLE0 0x46
charly 0:79c6d0071c4c 335 #define RF22_REG_47_RECEIVED_HEADER3 0x47
charly 0:79c6d0071c4c 336 #define RF22_REG_48_RECEIVED_HEADER2 0x48
charly 0:79c6d0071c4c 337 #define RF22_REG_49_RECEIVED_HEADER1 0x49
charly 0:79c6d0071c4c 338 #define RF22_REG_4A_RECEIVED_HEADER0 0x4a
charly 0:79c6d0071c4c 339 #define RF22_REG_4B_RECEIVED_PACKET_LENGTH 0x4b
charly 0:79c6d0071c4c 340 #define RF22_REG_50_ANALOG_TEST_BUS_SELECT 0x50
charly 0:79c6d0071c4c 341 #define RF22_REG_51_DIGITAL_TEST_BUS_SELECT 0x51
charly 0:79c6d0071c4c 342 #define RF22_REG_52_TX_RAMP_CONTROL 0x52
charly 0:79c6d0071c4c 343 #define RF22_REG_53_PLL_TUNE_TIME 0x53
charly 0:79c6d0071c4c 344 #define RF22_REG_55_CALIBRATION_CONTROL 0x55
charly 0:79c6d0071c4c 345 #define RF22_REG_56_MODEM_TEST 0x56
charly 0:79c6d0071c4c 346 #define RF22_REG_57_CHARGE_PUMP_TEST 0x57
charly 0:79c6d0071c4c 347 #define RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING 0x58
charly 0:79c6d0071c4c 348 #define RF22_REG_59_DIVIDER_CURRENT_TRIMMING 0x59
charly 0:79c6d0071c4c 349 #define RF22_REG_5A_VCO_CURRENT_TRIMMING 0x5a
charly 0:79c6d0071c4c 350 #define RF22_REG_5B_VCO_CALIBRATION 0x5b
charly 0:79c6d0071c4c 351 #define RF22_REG_5C_SYNTHESIZER_TEST 0x5c
charly 0:79c6d0071c4c 352 #define RF22_REG_5D_BLOCK_ENABLE_OVERRIDE1 0x5d
charly 0:79c6d0071c4c 353 #define RF22_REG_5E_BLOCK_ENABLE_OVERRIDE2 0x5e
charly 0:79c6d0071c4c 354 #define RF22_REG_5F_BLOCK_ENABLE_OVERRIDE3 0x5f
charly 0:79c6d0071c4c 355 #define RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS 0x60
charly 0:79c6d0071c4c 356 #define RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE 0x61
charly 0:79c6d0071c4c 357 #define RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL 0x62
charly 0:79c6d0071c4c 358 #define RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION 0x63
charly 0:79c6d0071c4c 359 #define RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION 0x64
charly 0:79c6d0071c4c 360 #define RF22_REG_65_LDO_CONTROL_OVERRIDE 0x65
charly 0:79c6d0071c4c 361 #define RF22_REG_66_LDO_LEVEL_SETTINGS 0x66
charly 0:79c6d0071c4c 362 #define RF22_REG_67_DELTA_SIGMA_ADC_TUNING1 0x67
charly 0:79c6d0071c4c 363 #define RF22_REG_68_DELTA_SIGMA_ADC_TUNING2 0x68
charly 0:79c6d0071c4c 364 #define RF22_REG_69_AGC_OVERRIDE1 0x69
charly 0:79c6d0071c4c 365 #define RF22_REG_6A_AGC_OVERRIDE2 0x6a
charly 0:79c6d0071c4c 366 #define RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b
charly 0:79c6d0071c4c 367 #define RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE 0x6c
charly 0:79c6d0071c4c 368 #define RF22_REG_6D_TX_POWER 0x6d
charly 0:79c6d0071c4c 369 #define RF22_REG_6E_TX_DATA_RATE1 0x6e
charly 0:79c6d0071c4c 370 #define RF22_REG_6F_TX_DATA_RATE0 0x6f
charly 0:79c6d0071c4c 371 #define RF22_REG_70_MODULATION_CONTROL1 0x70
charly 0:79c6d0071c4c 372 #define RF22_REG_71_MODULATION_CONTROL2 0x71
charly 0:79c6d0071c4c 373 #define RF22_REG_72_FREQUENCY_DEVIATION 0x72
charly 0:79c6d0071c4c 374 #define RF22_REG_73_FREQUENCY_OFFSET1 0x73
charly 0:79c6d0071c4c 375 #define RF22_REG_74_FREQUENCY_OFFSET2 0x74
charly 0:79c6d0071c4c 376 #define RF22_REG_75_FREQUENCY_BAND_SELECT 0x75
charly 0:79c6d0071c4c 377 #define RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1 0x76
charly 0:79c6d0071c4c 378 #define RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0 0x77
charly 0:79c6d0071c4c 379 #define RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT 0x79
charly 0:79c6d0071c4c 380 #define RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE 0x7a
charly 0:79c6d0071c4c 381 #define RF22_REG_7C_TX_FIFO_CONTROL1 0x7c
charly 0:79c6d0071c4c 382 #define RF22_REG_7D_TX_FIFO_CONTROL2 0x7d
charly 0:79c6d0071c4c 383 #define RF22_REG_7E_RX_FIFO_CONTROL 0x7e
charly 0:79c6d0071c4c 384 #define RF22_REG_7F_FIFO_ACCESS 0x7f
charly 0:79c6d0071c4c 385
charly 0:79c6d0071c4c 386 // These register masks etc are named wherever possible
charly 0:79c6d0071c4c 387 // corresponding to the bit and field names in the RF-22 Manual
charly 0:79c6d0071c4c 388 // RF22_REG_00_DEVICE_TYPE 0x00
charly 0:79c6d0071c4c 389 #define RF22_DEVICE_TYPE_RX_TRX 0x08
charly 0:79c6d0071c4c 390 #define RF22_DEVICE_TYPE_TX 0x07
charly 0:79c6d0071c4c 391
charly 0:79c6d0071c4c 392 // RF22_REG_02_DEVICE_STATUS 0x02
charly 0:79c6d0071c4c 393 #define RF22_FFOVL 0x80
charly 0:79c6d0071c4c 394 #define RF22_FFUNFL 0x40
charly 0:79c6d0071c4c 395 #define RF22_RXFFEM 0x20
charly 0:79c6d0071c4c 396 #define RF22_HEADERR 0x10
charly 0:79c6d0071c4c 397 #define RF22_FREQERR 0x08
charly 0:79c6d0071c4c 398 #define RF22_LOCKDET 0x04
charly 0:79c6d0071c4c 399 #define RF22_CPS 0x03
charly 0:79c6d0071c4c 400 #define RF22_CPS_IDLE 0x00
charly 0:79c6d0071c4c 401 #define RF22_CPS_RX 0x01
charly 0:79c6d0071c4c 402 #define RF22_CPS_TX 0x10
charly 0:79c6d0071c4c 403
charly 0:79c6d0071c4c 404 // RF22_REG_03_INTERRUPT_STATUS1 0x03
charly 0:79c6d0071c4c 405 #define RF22_IFFERROR 0x80
charly 0:79c6d0071c4c 406 #define RF22_ITXFFAFULL 0x40
charly 0:79c6d0071c4c 407 #define RF22_ITXFFAEM 0x20
charly 0:79c6d0071c4c 408 #define RF22_IRXFFAFULL 0x10
charly 0:79c6d0071c4c 409 #define RF22_IEXT 0x08
charly 0:79c6d0071c4c 410 #define RF22_IPKSENT 0x04
charly 0:79c6d0071c4c 411 #define RF22_IPKVALID 0x02
charly 0:79c6d0071c4c 412 #define RF22_ICRCERROR 0x01
charly 0:79c6d0071c4c 413
charly 0:79c6d0071c4c 414 // RF22_REG_04_INTERRUPT_STATUS2 0x04
charly 0:79c6d0071c4c 415 #define RF22_ISWDET 0x80
charly 0:79c6d0071c4c 416 #define RF22_IPREAVAL 0x40
charly 0:79c6d0071c4c 417 #define RF22_IPREAINVAL 0x20
charly 0:79c6d0071c4c 418 #define RF22_IRSSI 0x10
charly 0:79c6d0071c4c 419 #define RF22_IWUT 0x08
charly 0:79c6d0071c4c 420 #define RF22_ILBD 0x04
charly 0:79c6d0071c4c 421 #define RF22_ICHIPRDY 0x02
charly 0:79c6d0071c4c 422 #define RF22_IPOR 0x01
charly 0:79c6d0071c4c 423
charly 0:79c6d0071c4c 424 // RF22_REG_05_INTERRUPT_ENABLE1 0x05
charly 0:79c6d0071c4c 425 #define RF22_ENFFERR 0x80
charly 0:79c6d0071c4c 426 #define RF22_ENTXFFAFULL 0x40
charly 0:79c6d0071c4c 427 #define RF22_ENTXFFAEM 0x20
charly 0:79c6d0071c4c 428 #define RF22_ENRXFFAFULL 0x10
charly 0:79c6d0071c4c 429 #define RF22_ENEXT 0x08
charly 0:79c6d0071c4c 430 #define RF22_ENPKSENT 0x04
charly 0:79c6d0071c4c 431 #define RF22_ENPKVALID 0x02
charly 0:79c6d0071c4c 432 #define RF22_ENCRCERROR 0x01
charly 0:79c6d0071c4c 433
charly 0:79c6d0071c4c 434 // RF22_REG_06_INTERRUPT_ENABLE2 0x06
charly 0:79c6d0071c4c 435 #define RF22_ENSWDET 0x80
charly 0:79c6d0071c4c 436 #define RF22_ENPREAVAL 0x40
charly 0:79c6d0071c4c 437 #define RF22_ENPREAINVAL 0x20
charly 0:79c6d0071c4c 438 #define RF22_ENRSSI 0x10
charly 0:79c6d0071c4c 439 #define RF22_ENWUT 0x08
charly 0:79c6d0071c4c 440 #define RF22_ENLBDI 0x04
charly 0:79c6d0071c4c 441 #define RF22_ENCHIPRDY 0x02
charly 0:79c6d0071c4c 442 #define RF22_ENPOR 0x01
charly 0:79c6d0071c4c 443
charly 0:79c6d0071c4c 444 // RF22_REG_07_OPERATING_MODE 0x07
charly 0:79c6d0071c4c 445 #define RF22_SWRES 0x80
charly 0:79c6d0071c4c 446 #define RF22_ENLBD 0x40
charly 0:79c6d0071c4c 447 #define RF22_ENWT 0x20
charly 0:79c6d0071c4c 448 #define RF22_X32KSEL 0x10
charly 0:79c6d0071c4c 449 #define RF22_TXON 0x08
charly 0:79c6d0071c4c 450 #define RF22_RXON 0x04
charly 0:79c6d0071c4c 451 #define RF22_PLLON 0x02
charly 0:79c6d0071c4c 452 #define RF22_XTON 0x01
charly 0:79c6d0071c4c 453
charly 0:79c6d0071c4c 454 // RF22_REG_08_OPERATING_MODE2 0x08
charly 0:79c6d0071c4c 455 #define RF22_ANTDIV 0xc0
charly 0:79c6d0071c4c 456 #define RF22_RXMPK 0x10
charly 0:79c6d0071c4c 457 #define RF22_AUTOTX 0x08
charly 0:79c6d0071c4c 458 #define RF22_ENLDM 0x04
charly 0:79c6d0071c4c 459 #define RF22_FFCLRRX 0x02
charly 0:79c6d0071c4c 460 #define RF22_FFCLRTX 0x01
charly 0:79c6d0071c4c 461
charly 0:79c6d0071c4c 462 // RF22_REG_0F_ADC_CONFIGURATION 0x0f
charly 0:79c6d0071c4c 463 #define RF22_ADCSTART 0x80
charly 0:79c6d0071c4c 464 #define RF22_ADCDONE 0x80
charly 0:79c6d0071c4c 465 #define RF22_ADCSEL 0x70
charly 0:79c6d0071c4c 466 #define RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR 0x00
charly 0:79c6d0071c4c 467 #define RF22_ADCSEL_GPIO0_SINGLE_ENDED 0x10
charly 0:79c6d0071c4c 468 #define RF22_ADCSEL_GPIO1_SINGLE_ENDED 0x20
charly 0:79c6d0071c4c 469 #define RF22_ADCSEL_GPIO2_SINGLE_ENDED 0x30
charly 0:79c6d0071c4c 470 #define RF22_ADCSEL_GPIO0_GPIO1_DIFFERENTIAL 0x40
charly 0:79c6d0071c4c 471 #define RF22_ADCSEL_GPIO1_GPIO2_DIFFERENTIAL 0x50
charly 0:79c6d0071c4c 472 #define RF22_ADCSEL_GPIO0_GPIO2_DIFFERENTIAL 0x60
charly 0:79c6d0071c4c 473 #define RF22_ADCSEL_GND 0x70
charly 0:79c6d0071c4c 474 #define RF22_ADCREF 0x0c
charly 0:79c6d0071c4c 475 #define RF22_ADCREF_BANDGAP_VOLTAGE 0x00
charly 0:79c6d0071c4c 476 #define RF22_ADCREF_VDD_ON_3 0x08
charly 0:79c6d0071c4c 477 #define RF22_ADCREF_VDD_ON_2 0x0c
charly 0:79c6d0071c4c 478 #define RF22_ADCGAIN 0x03
charly 0:79c6d0071c4c 479
charly 0:79c6d0071c4c 480 // RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10
charly 0:79c6d0071c4c 481 #define RF22_ADCOFFS 0x0f
charly 0:79c6d0071c4c 482
charly 0:79c6d0071c4c 483 // RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12
charly 0:79c6d0071c4c 484 #define RF22_TSRANGE 0xc0
charly 0:79c6d0071c4c 485 #define RF22_TSRANGE_M64_64C 0x00
charly 0:79c6d0071c4c 486 #define RF22_TSRANGE_M64_192C 0x40
charly 0:79c6d0071c4c 487 #define RF22_TSRANGE_0_128C 0x80
charly 0:79c6d0071c4c 488 #define RF22_TSRANGE_M40_216F 0xc0
charly 0:79c6d0071c4c 489 #define RF22_ENTSOFFS 0x20
charly 0:79c6d0071c4c 490 #define RF22_ENTSTRIM 0x10
charly 0:79c6d0071c4c 491 #define RF22_TSTRIM 0x0f
charly 0:79c6d0071c4c 492
charly 0:79c6d0071c4c 493 // RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14
charly 0:79c6d0071c4c 494 #define RF22_WTR 0x3c
charly 0:79c6d0071c4c 495 #define RF22_WTD 0x03
charly 0:79c6d0071c4c 496
charly 0:79c6d0071c4c 497 // RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d
charly 0:79c6d0071c4c 498 #define RF22_AFC_EN 0x40
charly 0:79c6d0071c4c 499
charly 0:79c6d0071c4c 500 // Reg RF22_REG_1E_AFC_TIMING_CONTROL 0x1e
charly 0:79c6d0071c4c 501 #define RF22_AFC_TC 0x0a
charly 0:79c6d0071c4c 502
charly 0:79c6d0071c4c 503 // Reg RF22_REG_2A_AFC_LIMITER 0x2a
charly 0:79c6d0071c4c 504 #define RF22_AFC_LIMIT 0x50
charly 0:79c6d0071c4c 505
charly 0:79c6d0071c4c 506 // RF22_REG_30_DATA_ACCESS_CONTROL 0x30
charly 0:79c6d0071c4c 507 #define RF22_ENPACRX 0x80
charly 0:79c6d0071c4c 508 #define RF22_LSBFRST 0x40
charly 0:79c6d0071c4c 509 #define RF22_CRCDONLY 0x20
charly 0:79c6d0071c4c 510 #define RF22_ENPACTX 0x08
charly 0:79c6d0071c4c 511 #define RF22_ENCRC 0x04
charly 0:79c6d0071c4c 512 #define RF22_CRC 0x03
charly 0:79c6d0071c4c 513 #define RF22_CRC_CCITT 0x00
charly 0:79c6d0071c4c 514 #define RF22_CRC_CRC_16_IBM 0x01
charly 0:79c6d0071c4c 515 #define RF22_CRC_IEC_16 0x02
charly 0:79c6d0071c4c 516 #define RF22_CRC_BIACHEVA 0x03
charly 0:79c6d0071c4c 517
charly 0:79c6d0071c4c 518 // RF22_REG_32_HEADER_CONTROL1 0x32
charly 0:79c6d0071c4c 519 #define RF22_BCEN 0xf0
charly 0:79c6d0071c4c 520 #define RF22_BCEN_NONE 0x00
charly 0:79c6d0071c4c 521 #define RF22_BCEN_HEADER0 0x10
charly 0:79c6d0071c4c 522 #define RF22_BCEN_HEADER1 0x20
charly 0:79c6d0071c4c 523 #define RF22_BCEN_HEADER2 0x40
charly 0:79c6d0071c4c 524 #define RF22_BCEN_HEADER3 0x80
charly 0:79c6d0071c4c 525 #define RF22_HDCH 0x0f
charly 0:79c6d0071c4c 526 #define RF22_HDCH_NONE 0x00
charly 0:79c6d0071c4c 527 #define RF22_HDCH_HEADER0 0x01
charly 0:79c6d0071c4c 528 #define RF22_HDCH_HEADER1 0x02
charly 0:79c6d0071c4c 529 #define RF22_HDCH_HEADER2 0x04
charly 0:79c6d0071c4c 530 #define RF22_HDCH_HEADER3 0x08
charly 0:79c6d0071c4c 531
charly 0:79c6d0071c4c 532 // RF22_REG_33_HEADER_CONTROL2 0x33
charly 0:79c6d0071c4c 533 #define RF22_HDLEN 0x70
charly 0:79c6d0071c4c 534 #define RF22_HDLEN_0 0x00
charly 0:79c6d0071c4c 535 #define RF22_HDLEN_1 0x10
charly 0:79c6d0071c4c 536 #define RF22_HDLEN_2 0x20
charly 0:79c6d0071c4c 537 #define RF22_HDLEN_3 0x30
charly 0:79c6d0071c4c 538 #define RF22_HDLEN_4 0x40
charly 0:79c6d0071c4c 539 #define RF22_FIXPKLEN 0x08
charly 0:79c6d0071c4c 540 #define RF22_SYNCLEN 0x06
charly 0:79c6d0071c4c 541 #define RF22_SYNCLEN_1 0x00
charly 0:79c6d0071c4c 542 #define RF22_SYNCLEN_2 0x02
charly 0:79c6d0071c4c 543 #define RF22_SYNCLEN_3 0x04
charly 0:79c6d0071c4c 544 #define RF22_SYNCLEN_4 0x06
charly 0:79c6d0071c4c 545 #define RF22_PREALEN8 0x01
charly 0:79c6d0071c4c 546
charly 0:79c6d0071c4c 547 // RF22_REG_6D_TX_POWER 0x6d
charly 0:79c6d0071c4c 548 #define RF22_TXPOW 0x07
charly 0:79c6d0071c4c 549 #define RF22_TXPOW_4X31 0x08 // Not used in RFM22B
charly 0:79c6d0071c4c 550 #define RF22_TXPOW_1DBM 0x00
charly 0:79c6d0071c4c 551 #define RF22_TXPOW_2DBM 0x01
charly 0:79c6d0071c4c 552 #define RF22_TXPOW_5DBM 0x02
charly 0:79c6d0071c4c 553 #define RF22_TXPOW_8DBM 0x03
charly 0:79c6d0071c4c 554 #define RF22_TXPOW_11DBM 0x04
charly 0:79c6d0071c4c 555 #define RF22_TXPOW_14DBM 0x05
charly 0:79c6d0071c4c 556 #define RF22_TXPOW_17DBM 0x06
charly 0:79c6d0071c4c 557 #define RF22_TXPOW_20DBM 0x07
charly 0:79c6d0071c4c 558 // IN RFM23B
charly 0:79c6d0071c4c 559 #define RF22_TXPOW_LNA_SW 0x08
charly 0:79c6d0071c4c 560
charly 0:79c6d0071c4c 561 // RF22_REG_71_MODULATION_CONTROL2 0x71
charly 0:79c6d0071c4c 562 #define RF22_TRCLK 0xc0
charly 0:79c6d0071c4c 563 #define RF22_TRCLK_NONE 0x00
charly 0:79c6d0071c4c 564 #define RF22_TRCLK_GPIO 0x40
charly 0:79c6d0071c4c 565 #define RF22_TRCLK_SDO 0x80
charly 0:79c6d0071c4c 566 #define RF22_TRCLK_NIRQ 0xc0
charly 0:79c6d0071c4c 567 #define RF22_DTMOD 0x30
charly 0:79c6d0071c4c 568 #define RF22_DTMOD_DIRECT_GPIO 0x00
charly 0:79c6d0071c4c 569 #define RF22_DTMOD_DIRECT_SDI 0x10
charly 0:79c6d0071c4c 570 #define RF22_DTMOD_FIFO 0x20
charly 0:79c6d0071c4c 571 #define RF22_DTMOD_PN9 0x30
charly 0:79c6d0071c4c 572 #define RF22_ENINV 0x08
charly 0:79c6d0071c4c 573 #define RF22_FD8 0x04
charly 0:79c6d0071c4c 574 #define RF22_MODTYP 0x30
charly 0:79c6d0071c4c 575 #define RF22_MODTYP_UNMODULATED 0x00
charly 0:79c6d0071c4c 576 #define RF22_MODTYP_OOK 0x01
charly 0:79c6d0071c4c 577 #define RF22_MODTYP_FSK 0x02
charly 0:79c6d0071c4c 578 #define RF22_MODTYP_GFSK 0x03
charly 0:79c6d0071c4c 579
charly 0:79c6d0071c4c 580 // RF22_REG_75_FREQUENCY_BAND_SELECT 0x75
charly 0:79c6d0071c4c 581 #define RF22_SBSEL 0x40
charly 0:79c6d0071c4c 582 #define RF22_HBSEL 0x20
charly 0:79c6d0071c4c 583 #define RF22_FB 0x1f
charly 0:79c6d0071c4c 584
charly 0:79c6d0071c4c 585 /////////////////////////////////////////////////////////////////////
charly 0:79c6d0071c4c 586 /// \class RF22 RF22.h <RF22.h>
charly 0:79c6d0071c4c 587 /// \brief Send and receive unaddressed, unreliable datagrams.
charly 0:79c6d0071c4c 588 ///
charly 0:79c6d0071c4c 589 /// This base class provides basic functions for sending and receiving unaddressed,
charly 0:79c6d0071c4c 590 /// unreliable datagrams of arbitrary length to 255 octets per packet.
charly 0:79c6d0071c4c 591 ///
charly 0:79c6d0071c4c 592 /// Subclasses may use this class to implement reliable, addressed datagrams and streams,
charly 0:79c6d0071c4c 593 /// mesh routers, repeaters, translators etc.
charly 0:79c6d0071c4c 594 ///
charly 0:79c6d0071c4c 595 /// On transmission, the TO and FROM addresses default to 0x00, unless changed by a subclass.
charly 0:79c6d0071c4c 596 /// On reception the TO addressed is checked against the node address (defaults to 0x00) or the
charly 0:79c6d0071c4c 597 /// broadcast address (which is 0xff). The ID and FLAGS are set to 0, and not checked by this class.
charly 0:79c6d0071c4c 598 /// This permits use of the this base RF22 class as an
charly 0:79c6d0071c4c 599 /// unaddresed, unreliable datagram service. Subclasses are expected to change this behaviour to
charly 0:79c6d0071c4c 600 /// add node address, ids, retransmission etc
charly 0:79c6d0071c4c 601 ///
charly 0:79c6d0071c4c 602 /// Naturally, for any 2 radios to communicate that must be configured to use the same frequence and
charly 0:79c6d0071c4c 603 /// modulation scheme.
charly 0:79c6d0071c4c 604 class RF22
charly 0:79c6d0071c4c 605 {
charly 0:79c6d0071c4c 606 public:
charly 0:79c6d0071c4c 607
charly 0:79c6d0071c4c 608 /// \brief Defines register values for a set of modem configuration registers
charly 0:79c6d0071c4c 609 ///
charly 0:79c6d0071c4c 610 /// Defines register values for a set of modem configuration registers
charly 0:79c6d0071c4c 611 /// that can be passed to setModemConfig()
charly 0:79c6d0071c4c 612 /// if none of the choices in ModemConfigChoice suit your need
charly 0:79c6d0071c4c 613 /// setModemConfig() writes the register values to the appropriate RF22 registers
charly 0:79c6d0071c4c 614 /// to set the desired modulation type, data rate and deviation/bandwidth.
charly 0:79c6d0071c4c 615 /// Suitable values for these registers can be computed using the register calculator at
charly 0:79c6d0071c4c 616 /// "http://www.hoperf.com/upfile/RF22B 23B 31B 42B 43B Register Settings_RevB1-v5.xls"
charly 0:79c6d0071c4c 617 typedef struct
charly 0:79c6d0071c4c 618 {
charly 0:79c6d0071c4c 619 uint8_t reg_1c; ///< Value for register RF22_REG_1C_IF_FILTER_BANDWIDTH
charly 0:79c6d0071c4c 620 uint8_t reg_1f; ///< Value for register RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE
charly 0:79c6d0071c4c 621 uint8_t reg_20; ///< Value for register RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE
charly 0:79c6d0071c4c 622 uint8_t reg_21; ///< Value for register RF22_REG_21_CLOCK_RECOVERY_OFFSET2
charly 0:79c6d0071c4c 623 uint8_t reg_22; ///< Value for register RF22_REG_22_CLOCK_RECOVERY_OFFSET1
charly 0:79c6d0071c4c 624 uint8_t reg_23; ///< Value for register RF22_REG_23_CLOCK_RECOVERY_OFFSET0
charly 0:79c6d0071c4c 625 uint8_t reg_24; ///< Value for register RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1
charly 0:79c6d0071c4c 626 uint8_t reg_25; ///< Value for register RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0
charly 0:79c6d0071c4c 627 uint8_t reg_2c; ///< Value for register RF22_REG_2C_OOK_COUNTER_VALUE_1
charly 0:79c6d0071c4c 628 uint8_t reg_2d; ///< Value for register RF22_REG_2D_OOK_COUNTER_VALUE_2
charly 0:79c6d0071c4c 629 uint8_t reg_2e; ///< Value for register RF22_REG_2E_SLICER_PEAK_HOLD
charly 0:79c6d0071c4c 630 uint8_t reg_58; ///< Value for register RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING
charly 0:79c6d0071c4c 631 uint8_t reg_69; ///< Value for register RF22_REG_69_AGC_OVERRIDE1
charly 0:79c6d0071c4c 632 uint8_t reg_6e; ///< Value for register RF22_REG_6E_TX_DATA_RATE1
charly 0:79c6d0071c4c 633 uint8_t reg_6f; ///< Value for register RF22_REG_6F_TX_DATA_RATE0
charly 0:79c6d0071c4c 634 uint8_t reg_70; ///< Value for register RF22_REG_70_MODULATION_CONTROL1
charly 0:79c6d0071c4c 635 uint8_t reg_71; ///< Value for register RF22_REG_71_MODULATION_CONTROL2
charly 0:79c6d0071c4c 636 uint8_t reg_72; ///< Value for register RF22_REG_72_FREQUENCY_DEVIATION
charly 0:79c6d0071c4c 637 } ModemConfig;
charly 0:79c6d0071c4c 638
charly 0:79c6d0071c4c 639 /// Choices for setModemConfig() for a selected subset of common modulation types,
charly 0:79c6d0071c4c 640 /// and data rates. If you need another configuration, use the register calculator at
charly 0:79c6d0071c4c 641 /// "http://www.hoperf.com/upfile/RF22B 23B 31B 42B 43B Register Settings_RevB1-v5.xls"
charly 0:79c6d0071c4c 642 /// and call setModemRegisters() with your desired settings
charly 0:79c6d0071c4c 643 /// These are indexes into _modemConfig
charly 0:79c6d0071c4c 644 typedef enum
charly 0:79c6d0071c4c 645 {
charly 0:79c6d0071c4c 646 UnmodulatedCarrier = 0, ///< Unmodulated carrier for testing
charly 0:79c6d0071c4c 647 FSK_PN9_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz, PN9 random modulation for testing
charly 0:79c6d0071c4c 648
charly 0:79c6d0071c4c 649 FSK_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz
charly 0:79c6d0071c4c 650 FSK_Rb2_4Fd36, ///< FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz
charly 0:79c6d0071c4c 651 FSK_Rb4_8Fd45, ///< FSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz
charly 0:79c6d0071c4c 652 FSK_Rb9_6Fd45, ///< FSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz
charly 0:79c6d0071c4c 653 FSK_Rb19_2Fd9_6, ///< FSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz
charly 0:79c6d0071c4c 654 FSK_Rb38_4Fd19_6, ///< FSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz
charly 0:79c6d0071c4c 655 FSK_Rb57_6Fd28_8, ///< FSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz
charly 0:79c6d0071c4c 656 FSK_Rb125Fd125, ///< FSK, No Manchester, Rb = 125kbs, Fd = 125kHz
charly 0:79c6d0071c4c 657
charly 0:79c6d0071c4c 658 GFSK_Rb2Fd5, ///< GFSK, No Manchester, Rb = 2kbs, Fd = 5kHz
charly 0:79c6d0071c4c 659 GFSK_Rb2_4Fd36, ///< GFSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz
charly 0:79c6d0071c4c 660 GFSK_Rb4_8Fd45, ///< GFSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz
charly 0:79c6d0071c4c 661 GFSK_Rb9_6Fd45, ///< GFSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz
charly 0:79c6d0071c4c 662 GFSK_Rb19_2Fd9_6, ///< GFSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz
charly 0:79c6d0071c4c 663 GFSK_Rb38_4Fd19_6, ///< GFSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz
charly 0:79c6d0071c4c 664 GFSK_Rb57_6Fd28_8, ///< GFSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz
charly 0:79c6d0071c4c 665 GFSK_Rb125Fd125, ///< GFSK, No Manchester, Rb = 125kbs, Fd = 125kHz
charly 0:79c6d0071c4c 666
charly 0:79c6d0071c4c 667 OOK_Rb1_2Bw75, ///< OOK, No Manchester, Rb = 1.2kbs, Rx Bandwidth = 75kHz
charly 0:79c6d0071c4c 668 OOK_Rb2_4Bw335, ///< OOK, No Manchester, Rb = 2.4kbs, Rx Bandwidth = 335kHz
charly 0:79c6d0071c4c 669 OOK_Rb4_8Bw335, ///< OOK, No Manchester, Rb = 4.8kbs, Rx Bandwidth = 335kHz
charly 0:79c6d0071c4c 670 OOK_Rb9_6Bw335, ///< OOK, No Manchester, Rb = 9.6kbs, Rx Bandwidth = 335kHz
charly 0:79c6d0071c4c 671 OOK_Rb19_2Bw335, ///< OOK, No Manchester, Rb = 19.2kbs, Rx Bandwidth = 335kHz
charly 0:79c6d0071c4c 672 OOK_Rb38_4Bw335, ///< OOK, No Manchester, Rb = 38.4kbs, Rx Bandwidth = 335kHz
charly 0:79c6d0071c4c 673 OOK_Rb40Bw335 ///< OOK, No Manchester, Rb = 40kbs, Rx Bandwidth = 335kHz
charly 0:79c6d0071c4c 674 } ModemConfigChoice;
charly 0:79c6d0071c4c 675
charly 0:79c6d0071c4c 676 /// Constructor. You can have multiple instances, but each instance must have its own
charly 0:79c6d0071c4c 677 /// interrupt and slave select pin. After constructing, you must call init() to initialise the intnerface
charly 0:79c6d0071c4c 678 /// and the radio module
charly 0:79c6d0071c4c 679 /// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RF22 before
charly 0:79c6d0071c4c 680 /// accessing it
charly 0:79c6d0071c4c 681 /// \param[in] interrupt The interrupt number to use. Default is interrupt 0 (Arduino input pin 2)
charly 0:79c6d0071c4c 682 RF22(PinName slaveSelectPin , PinName mosi, PinName miso, PinName sclk, PinName interrupt );
charly 0:79c6d0071c4c 683
charly 0:79c6d0071c4c 684 /// Initialises this instance and the radio module connected to it.
charly 0:79c6d0071c4c 685 /// The following steps are taken:
charly 0:79c6d0071c4c 686 /// - Initialise the slave select pin and the SPI interface library
charly 0:79c6d0071c4c 687 /// - Software reset the RF22 module
charly 0:79c6d0071c4c 688 /// - Checks the connected RF22 module is either a RF22_DEVICE_TYPE_RX_TRX or a RF22_DEVICE_TYPE_TX
charly 0:79c6d0071c4c 689 /// - Attaches an interrupt handler
charly 0:79c6d0071c4c 690 /// - Configures the RF22 module
charly 0:79c6d0071c4c 691 /// - Sets the frequncy to 434.0 MHz
charly 0:79c6d0071c4c 692 /// - Sets the modem data rate to FSK_Rb2_4Fd36
charly 0:79c6d0071c4c 693 /// \return true if everything was successful
charly 0:79c6d0071c4c 694 boolean init();
charly 0:79c6d0071c4c 695
charly 0:79c6d0071c4c 696 /// Issues a software reset to the
charly 0:79c6d0071c4c 697 /// RF22 module. Blocks for 1ms to ensure the reset is complete.
charly 0:79c6d0071c4c 698 void reset();
charly 0:79c6d0071c4c 699
charly 0:79c6d0071c4c 700 /// Reads a single register from the RF22
charly 0:79c6d0071c4c 701 /// \param[in] reg Register number, one of RF22_REG_*
charly 0:79c6d0071c4c 702 /// \return The value of the register
charly 0:79c6d0071c4c 703 uint8_t spiRead(uint8_t reg);
charly 0:79c6d0071c4c 704
charly 0:79c6d0071c4c 705 /// Writes a single byte to the RF22
charly 0:79c6d0071c4c 706 /// \param[in] reg Register number, one of RF22_REG_*
charly 0:79c6d0071c4c 707 /// \param[in] val The value to write
charly 0:79c6d0071c4c 708 void spiWrite(uint8_t reg, uint8_t val);
charly 0:79c6d0071c4c 709
charly 0:79c6d0071c4c 710 /// Reads a number of consecutive registers from the RF22 using burst read mode
charly 0:79c6d0071c4c 711 /// \param[in] reg Register number of the first register, one of RF22_REG_*
charly 0:79c6d0071c4c 712 /// \param[in] dest Array to write the register values to. Must be at least len bytes
charly 0:79c6d0071c4c 713 /// \param[in] len Number of bytes to read
charly 0:79c6d0071c4c 714 void spiBurstRead(uint8_t reg, uint8_t* dest, uint8_t len);
charly 0:79c6d0071c4c 715
charly 0:79c6d0071c4c 716 /// Write a number of consecutive registers using burst write mode
charly 0:79c6d0071c4c 717 /// \param[in] reg Register number of the first register, one of RF22_REG_*
charly 0:79c6d0071c4c 718 /// \param[in] src Array of new register values to write. Must be at least len bytes
charly 0:79c6d0071c4c 719 /// \param[in] len Number of bytes to write
charly 0:79c6d0071c4c 720 void spiBurstWrite(uint8_t reg, uint8_t* src, uint8_t len);
charly 0:79c6d0071c4c 721
charly 0:79c6d0071c4c 722 /// Reads and returns the device status register RF22_REG_02_DEVICE_STATUS
charly 0:79c6d0071c4c 723 /// \return The value of the device status register
charly 0:79c6d0071c4c 724 uint8_t statusRead();
charly 0:79c6d0071c4c 725
charly 0:79c6d0071c4c 726 /// Reads a value from the on-chip analog-digital converter
charly 0:79c6d0071c4c 727 /// \param[in] adcsel Selects the ADC input to measure. One of RF22_ADCSEL_*. Defaults to the
charly 0:79c6d0071c4c 728 /// internal temperature sensor
charly 0:79c6d0071c4c 729 /// \param[in] adcref Specifies the refernce voltage to use. One of RF22_ADCREF_*.
charly 0:79c6d0071c4c 730 /// Defaults to the internal bandgap voltage.
charly 0:79c6d0071c4c 731 /// \param[in] adcgain Amplifier gain selection.
charly 0:79c6d0071c4c 732 /// \param[in] adcoffs Amplifier offseet (0 to 15).
charly 0:79c6d0071c4c 733 /// \return The analog value. 0 to 255.
charly 0:79c6d0071c4c 734 uint8_t adcRead(uint8_t adcsel = RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR,
charly 0:79c6d0071c4c 735 uint8_t adcref = RF22_ADCREF_BANDGAP_VOLTAGE,
charly 0:79c6d0071c4c 736 uint8_t adcgain = 0,
charly 0:79c6d0071c4c 737 uint8_t adcoffs = 0);
charly 0:79c6d0071c4c 738
charly 0:79c6d0071c4c 739 /// Reads the on-chip temperature sensoer
charly 0:79c6d0071c4c 740 /// \param[in] tsrange Specifies the temperature range to use. One of RF22_TSRANGE_*
charly 0:79c6d0071c4c 741 /// \param[in] tvoffs Specifies the temperature value offset. This is actually signed value
charly 0:79c6d0071c4c 742 /// added to the measured temperature value
charly 0:79c6d0071c4c 743 /// \return The measured temperature.
charly 0:79c6d0071c4c 744 uint8_t temperatureRead(uint8_t tsrange = RF22_TSRANGE_M64_64C, uint8_t tvoffs = 0);
charly 0:79c6d0071c4c 745
charly 0:79c6d0071c4c 746 /// Reads the wakeup timer value in registers RF22_REG_17_WAKEUP_TIMER_VALUE1
charly 0:79c6d0071c4c 747 /// and RF22_REG_18_WAKEUP_TIMER_VALUE2
charly 0:79c6d0071c4c 748 /// \return The wakeup timer value
charly 0:79c6d0071c4c 749 uint16_t wutRead();
charly 0:79c6d0071c4c 750
charly 0:79c6d0071c4c 751 /// Sets the wakeup timer period registers RF22_REG_14_WAKEUP_TIMER_PERIOD1,
charly 0:79c6d0071c4c 752 /// RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RF22_REG_16_WAKEUP_TIMER_PERIOD3
charly 0:79c6d0071c4c 753 /// \param[in] wtm Wakeup timer mantissa value
charly 0:79c6d0071c4c 754 /// \param[in] wtr Wakeup timer exponent R value
charly 0:79c6d0071c4c 755 /// \param[in] wtd Wakeup timer exponent D value
charly 0:79c6d0071c4c 756 void setWutPeriod(uint16_t wtm, uint8_t wtr = 0, uint8_t wtd = 0);
charly 0:79c6d0071c4c 757
charly 0:79c6d0071c4c 758 /// Sets the transmitter and receiver centre frequency
charly 0:79c6d0071c4c 759 /// \param[in] centre Frequency in MHz. 240.0 to 960.0. Caution, some versions of RF22 and derivatives
charly 0:79c6d0071c4c 760 /// implemented more restricted frequency ranges.
charly 0:79c6d0071c4c 761 /// \return true if the selected frquency centre + (fhch * fhs) is within range
charly 0:79c6d0071c4c 762 boolean setFrequency(float centre);
charly 0:79c6d0071c4c 763
charly 0:79c6d0071c4c 764 /// Sets the frequency hopping step size.
charly 0:79c6d0071c4c 765 /// \param[in] fhs Frequency Hopping step size in 10kHz increments
charly 0:79c6d0071c4c 766 /// \return true if centre + (fhch * fhs) is within limits
charly 0:79c6d0071c4c 767 boolean setFHStepSize(uint8_t fhs);
charly 0:79c6d0071c4c 768
charly 0:79c6d0071c4c 769 /// Sets the frequncy hopping channel. Adds fhch * fhs to centre frequency
charly 0:79c6d0071c4c 770 /// \param[in] fhch The channel number
charly 0:79c6d0071c4c 771 /// \return true if the selected frquency centre + (fhch * fhs) is within range
charly 0:79c6d0071c4c 772 boolean setFHChannel(uint8_t fhch);
charly 0:79c6d0071c4c 773
charly 0:79c6d0071c4c 774 /// Reads and returns the current RSSI value from register RF22_REG_26_RSSI
charly 0:79c6d0071c4c 775 /// \return The current RSSI value
charly 0:79c6d0071c4c 776 uint8_t rssiRead();
charly 0:79c6d0071c4c 777
charly 0:79c6d0071c4c 778 /// Reads and returns the current EZMAC value from register RF22_REG_31_EZMAC_STATUS
charly 0:79c6d0071c4c 779 /// \return The current EZMAC value
charly 0:79c6d0071c4c 780 uint8_t ezmacStatusRead();
charly 0:79c6d0071c4c 781
charly 0:79c6d0071c4c 782 /// Sets the parameters for the RF22 Idle mode in register RF22_REG_07_OPERATING_MODE.
charly 0:79c6d0071c4c 783 /// Idle mode is the mode the RF22 wil be in when not transmitting or receiving. The default idle mode
charly 0:79c6d0071c4c 784 /// is RF22_XTON ie READY mode.
charly 0:79c6d0071c4c 785 /// \param[in] mode MAsk of mode bits, using RF22_SWRES, RF22_ENLBD, RF22_ENWT,
charly 0:79c6d0071c4c 786 /// RF22_X32KSEL, RF22_PLLON, RF22_XTON.
charly 0:79c6d0071c4c 787 void setMode(uint8_t mode);
charly 0:79c6d0071c4c 788
charly 0:79c6d0071c4c 789 /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running,
charly 0:79c6d0071c4c 790 /// disables them.
charly 0:79c6d0071c4c 791 void setModeIdle();
charly 0:79c6d0071c4c 792
charly 0:79c6d0071c4c 793 /// If current mode is Tx or Idle, changes it to Rx.
charly 0:79c6d0071c4c 794 /// Starts the receiver in the RF22.
charly 0:79c6d0071c4c 795 void setModeRx();
charly 0:79c6d0071c4c 796
charly 0:79c6d0071c4c 797 /// If current mode is Rx or Idle, changes it to Rx.
charly 0:79c6d0071c4c 798 /// Starts the transmitter in the RF22.
charly 0:79c6d0071c4c 799 void setModeTx();
charly 0:79c6d0071c4c 800
charly 0:79c6d0071c4c 801 /// Sets the transmitter power output level in register RF22_REG_6D_TX_POWER.
charly 0:79c6d0071c4c 802 /// Be a good neighbour and set the lowest power level you need.
charly 0:79c6d0071c4c 803 /// After init(), the power wil be set to RF22_TXPOW_8DBM.
charly 0:79c6d0071c4c 804 /// Caution: In some countries you may only select RF22_TXPOW_17DBM if you
charly 0:79c6d0071c4c 805 /// are also using frequency hopping.
charly 0:79c6d0071c4c 806 /// \param[in] power Transmitter power level, one of RF22_TXPOW_*
charly 0:79c6d0071c4c 807 void setTxPower(uint8_t power);
charly 0:79c6d0071c4c 808
charly 0:79c6d0071c4c 809 /// Sets all the registered required to configure the data modem in the RF22, including the data rate,
charly 0:79c6d0071c4c 810 /// bandwidths etc. You cas use this to configure the modem with custom configuraitons if none of the
charly 0:79c6d0071c4c 811 /// canned configurations in ModemConfigChoice suit you.
charly 0:79c6d0071c4c 812 /// \param[in] config A ModemConfig structure containing values for the modem configuration registers.
charly 0:79c6d0071c4c 813 void setModemRegisters(ModemConfig* config);
charly 0:79c6d0071c4c 814
charly 0:79c6d0071c4c 815 /// Select one of the predefined modem configurations. If you need a modem configuration not provided
charly 0:79c6d0071c4c 816 /// here, use setModemRegisters() with your own ModemConfig.
charly 0:79c6d0071c4c 817 /// \param[in] index The configuration choice.
charly 0:79c6d0071c4c 818 /// \return true if index is a valid choice.
charly 0:79c6d0071c4c 819 boolean setModemConfig(ModemConfigChoice index);
charly 0:79c6d0071c4c 820
charly 0:79c6d0071c4c 821 /// Starts the receiver and checks whether a received message is available.
charly 0:79c6d0071c4c 822 /// This can be called multiple times in a timeout loop
charly 0:79c6d0071c4c 823 /// \return true if a complete, valid message has been received and is able to be retrieved by
charly 0:79c6d0071c4c 824 /// recv()
charly 0:79c6d0071c4c 825 boolean available();
charly 0:79c6d0071c4c 826
charly 0:79c6d0071c4c 827 /// Starts the receiver and blocks until a valid received
charly 0:79c6d0071c4c 828 /// message is available.
charly 0:79c6d0071c4c 829 void waitAvailable();
charly 0:79c6d0071c4c 830
charly 0:79c6d0071c4c 831 /// Starts the receiver and blocks until a received message is available or a timeout
charly 0:79c6d0071c4c 832 /// \param[in] timeout Maximum time to wait in milliseconds.
charly 0:79c6d0071c4c 833 /// \return true if a message is available
charly 0:79c6d0071c4c 834 bool waitAvailableTimeout(uint16_t timeout);
charly 0:79c6d0071c4c 835
charly 0:79c6d0071c4c 836 /// Turns the receiver on if it not already on.
charly 0:79c6d0071c4c 837 /// If there is a valid message available, copy it to buf and return true
charly 0:79c6d0071c4c 838 /// else return false.
charly 0:79c6d0071c4c 839 /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted).
charly 0:79c6d0071c4c 840 /// You should be sure to call this function frequently enough to not miss any messages
charly 0:79c6d0071c4c 841 /// It is recommended that you call it in your main loop.
charly 0:79c6d0071c4c 842 /// \param[in] buf Location to copy the received message
charly 0:79c6d0071c4c 843 /// \param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied.
charly 0:79c6d0071c4c 844 /// \return true if a valid message was copied to buf
charly 0:79c6d0071c4c 845 boolean recv(uint8_t* buf, uint8_t* len);
charly 0:79c6d0071c4c 846
charly 0:79c6d0071c4c 847 /// Loads a message into the transmitter and starts the transmitter. Note that a message length
charly 0:79c6d0071c4c 848 /// of 0 is permitted, in which case data may be NULL.
charly 0:79c6d0071c4c 849 /// \param[in] data Array of data to be sent
charly 0:79c6d0071c4c 850 /// \param[in] len Number of bytes of data to send.
charly 0:79c6d0071c4c 851 /// \return true
charly 0:79c6d0071c4c 852 boolean send(uint8_t* data, uint8_t len);
charly 0:79c6d0071c4c 853
charly 0:79c6d0071c4c 854 /// Blocks until the current message
charly 0:79c6d0071c4c 855 /// (if any) has been completely sent
charly 0:79c6d0071c4c 856 void waitPacketSent();
charly 0:79c6d0071c4c 857
charly 0:79c6d0071c4c 858 /// Tells the receiver to accept messages with any TO address, not just messages
charly 0:79c6d0071c4c 859 /// addressed to this node or the broadcast address
charly 0:79c6d0071c4c 860 /// \param[in] promiscuous true if you wish to receive messages with any TO address
charly 0:79c6d0071c4c 861 void setPromiscuous(boolean promiscuous);
charly 0:79c6d0071c4c 862
charly 0:79c6d0071c4c 863 /// Returns the TO header of the last received message
charly 0:79c6d0071c4c 864 /// \return The TO header
charly 0:79c6d0071c4c 865 uint8_t headerTo();
charly 0:79c6d0071c4c 866
charly 0:79c6d0071c4c 867 /// Returns the FROM header of the last received message
charly 0:79c6d0071c4c 868 /// \return The FROM header
charly 0:79c6d0071c4c 869 /// \return
charly 0:79c6d0071c4c 870 uint8_t headerFrom();
charly 0:79c6d0071c4c 871
charly 0:79c6d0071c4c 872 /// Returns the ID header of the last received message
charly 0:79c6d0071c4c 873 /// \return The ID header
charly 0:79c6d0071c4c 874 /// \return
charly 0:79c6d0071c4c 875 uint8_t headerId();
charly 0:79c6d0071c4c 876
charly 0:79c6d0071c4c 877 /// Returns the FLAGS header of the last received message
charly 0:79c6d0071c4c 878 /// \return The FLAGS header
charly 0:79c6d0071c4c 879 /// \return
charly 0:79c6d0071c4c 880 uint8_t headerFlags();
charly 0:79c6d0071c4c 881
charly 0:79c6d0071c4c 882 /// Returns the RSSI (Receiver Signal Strength Indicator)
charly 0:79c6d0071c4c 883 /// of the last received message. This measurement is taken when
charly 0:79c6d0071c4c 884 /// the preamble has been received. It is a (non-linear) measure of the received signal strength.
charly 0:79c6d0071c4c 885 /// \return The RSSI
charly 0:79c6d0071c4c 886 uint8_t lastRssi();
charly 0:79c6d0071c4c 887
charly 0:79c6d0071c4c 888 protected:
charly 0:79c6d0071c4c 889 /// Sets the message preamble length in RF22_REG_34_PREAMBLE_LENGTH
charly 0:79c6d0071c4c 890 /// \param[in] nibbles Preamble length in nibbles of 4 bits each.
charly 0:79c6d0071c4c 891 void setPreambleLength(uint8_t nibbles);
charly 0:79c6d0071c4c 892
charly 0:79c6d0071c4c 893 /// Sets the sync words for transmit and receive in registers RF22_REG_36_SYNC_WORD3
charly 0:79c6d0071c4c 894 /// to RF22_REG_39_SYNC_WORD0
charly 0:79c6d0071c4c 895 /// \param[in] syncWords Array of sync words
charly 0:79c6d0071c4c 896 /// \param[in] len Number of sync words to set
charly 0:79c6d0071c4c 897 void setSyncWords(uint8_t* syncWords, uint8_t len);
charly 0:79c6d0071c4c 898
charly 0:79c6d0071c4c 899 /// This is a low level function to handle the interrupts for one instance of RF22.
charly 0:79c6d0071c4c 900 /// Called automatically by isr0() and isr1()
charly 0:79c6d0071c4c 901 /// Should not need to be called.
charly 0:79c6d0071c4c 902 void handleInterrupt();
charly 0:79c6d0071c4c 903
charly 0:79c6d0071c4c 904 /// Clears the receiver buffer.
charly 0:79c6d0071c4c 905 /// Internal use only
charly 0:79c6d0071c4c 906 void clearRxBuf();
charly 0:79c6d0071c4c 907
charly 0:79c6d0071c4c 908 /// Clears the transmitter buffer
charly 0:79c6d0071c4c 909 /// Internal use only
charly 0:79c6d0071c4c 910 void clearTxBuf();
charly 0:79c6d0071c4c 911
charly 0:79c6d0071c4c 912 /// Fills the transmitter buffer with the data of a mesage to be sent
charly 0:79c6d0071c4c 913 /// \param[in] data Array of data bytes to be sent (0 to 255)
charly 0:79c6d0071c4c 914 /// \param[in] len Number of data bytes in data
charly 0:79c6d0071c4c 915 /// \return true
charly 0:79c6d0071c4c 916 boolean fillTxBuf(uint8_t* data, uint8_t len);
charly 0:79c6d0071c4c 917
charly 0:79c6d0071c4c 918 /// Appends the transmitter buffer with the data of a mesage to be sent
charly 0:79c6d0071c4c 919 /// \param[in] data Array of data bytes to be sent (0 to 255)
charly 0:79c6d0071c4c 920 /// \param[in] len Number of data bytes in data
charly 0:79c6d0071c4c 921 /// \return false if the resulting message would exceed RF22_MAX_MESSAGE_LEN, else true
charly 0:79c6d0071c4c 922 boolean appendTxBuf(uint8_t* data, uint8_t len);
charly 0:79c6d0071c4c 923
charly 0:79c6d0071c4c 924 /// Internal function to load the next fragment of
charly 0:79c6d0071c4c 925 /// the current message into the transmitter FIFO
charly 0:79c6d0071c4c 926 /// Internal use only
charly 0:79c6d0071c4c 927 void sendNextFragment();
charly 0:79c6d0071c4c 928
charly 0:79c6d0071c4c 929 /// function to copy the next fragment from
charly 0:79c6d0071c4c 930 /// the receiver FIF) into the receiver buffer
charly 0:79c6d0071c4c 931 void readNextFragment();
charly 0:79c6d0071c4c 932
charly 0:79c6d0071c4c 933 /// Clears the RF22 Rx and Tx FIFOs
charly 0:79c6d0071c4c 934 /// Internal use only
charly 0:79c6d0071c4c 935 void resetFifos();
charly 0:79c6d0071c4c 936
charly 0:79c6d0071c4c 937 /// Clears the RF22 Rx FIFO
charly 0:79c6d0071c4c 938 /// Internal use only
charly 0:79c6d0071c4c 939 void resetRxFifo();
charly 0:79c6d0071c4c 940
charly 0:79c6d0071c4c 941 /// Clears the RF22 Tx FIFO
charly 0:79c6d0071c4c 942 /// Internal use only
charly 0:79c6d0071c4c 943 void resetTxFifo();
charly 0:79c6d0071c4c 944
charly 0:79c6d0071c4c 945 /// This function will be called by handleInterrupt() if an RF22 external interrupt occurs.
charly 0:79c6d0071c4c 946 /// This can only happen if external interrupts are enabled in the RF22
charly 0:79c6d0071c4c 947 /// (which they are not by default).
charly 0:79c6d0071c4c 948 /// Subclasses may override this function to get control when an RF22 external interrupt occurs.
charly 0:79c6d0071c4c 949 virtual void handleExternalInterrupt();
charly 0:79c6d0071c4c 950
charly 0:79c6d0071c4c 951 /// This function will be called by handleInterrupt() if an RF22 wakeup timer interrupt occurs.
charly 0:79c6d0071c4c 952 /// This can only happen if wakeup timer interrupts are enabled in the RF22
charly 0:79c6d0071c4c 953 /// (which they are not by default).
charly 0:79c6d0071c4c 954 /// Subclasses may override this function to get control when an RF22 wakeup timer interrupt occurs.
charly 0:79c6d0071c4c 955 virtual void handleWakeupTimerInterrupt();
charly 0:79c6d0071c4c 956
charly 0:79c6d0071c4c 957 /// Sets the TO header to be sent in all subsequent messages
charly 0:79c6d0071c4c 958 /// \param[in] to The new TO header value
charly 0:79c6d0071c4c 959 void setHeaderTo(uint8_t to);
charly 0:79c6d0071c4c 960
charly 0:79c6d0071c4c 961 /// Sets the FROM header to be sent in all subsequent messages
charly 0:79c6d0071c4c 962 /// \param[in] from The new FROM header value
charly 0:79c6d0071c4c 963 void setHeaderFrom(uint8_t from);
charly 0:79c6d0071c4c 964
charly 0:79c6d0071c4c 965 /// Sets the ID header to be sent in all subsequent messages
charly 0:79c6d0071c4c 966 /// \param[in] id The new ID header value
charly 0:79c6d0071c4c 967 void setHeaderId(uint8_t id);
charly 0:79c6d0071c4c 968
charly 0:79c6d0071c4c 969 /// Sets the FLAGS header to be sent in all subsequent messages
charly 0:79c6d0071c4c 970 /// \param[in] flags The new FLAGS header value
charly 0:79c6d0071c4c 971 void setHeaderFlags(uint8_t flags);
charly 0:79c6d0071c4c 972
charly 0:79c6d0071c4c 973 /// Start the transmission of the contents
charly 0:79c6d0071c4c 974 /// of the Tx buffer
charly 0:79c6d0071c4c 975 void startTransmit();
charly 0:79c6d0071c4c 976
charly 0:79c6d0071c4c 977 /// ReStart the transmission of the contents
charly 0:79c6d0071c4c 978 /// of the Tx buffer after a atransmission failure
charly 0:79c6d0071c4c 979 void restartTransmit();
charly 0:79c6d0071c4c 980
charly 0:79c6d0071c4c 981 //private:
charly 0:79c6d0071c4c 982 /// Low level interrupt service routine for RF22 connected to interrupt 0
charly 0:79c6d0071c4c 983 //static void isr0();
charly 0:79c6d0071c4c 984 void isr0();
charly 0:79c6d0071c4c 985
charly 0:79c6d0071c4c 986 /// Low level interrupt service routine for RF22 connected to interrupt 1
charly 0:79c6d0071c4c 987 //static void isr1();
charly 0:79c6d0071c4c 988 private:
charly 0:79c6d0071c4c 989 /// Array of instances connected to interrupts 0 and 1
charly 0:79c6d0071c4c 990 //static RF22* _RF22ForInterrupt[];
charly 0:79c6d0071c4c 991
charly 0:79c6d0071c4c 992
charly 0:79c6d0071c4c 993 uint8_t _mode; // One of RF22_MODE_*
charly 0:79c6d0071c4c 994
charly 0:79c6d0071c4c 995 uint8_t _idleMode;
charly 0:79c6d0071c4c 996 DigitalOut _slaveSelectPin;
charly 0:79c6d0071c4c 997 SPI _spi;
charly 0:79c6d0071c4c 998 InterruptIn _interrupt;
charly 0:79c6d0071c4c 999 uint8_t _deviceType;
charly 0:79c6d0071c4c 1000
charly 0:79c6d0071c4c 1001 DigitalOut led1;
charly 0:79c6d0071c4c 1002 DigitalOut led2;
charly 0:79c6d0071c4c 1003 DigitalOut led3;
charly 0:79c6d0071c4c 1004 DigitalOut led4;
charly 0:79c6d0071c4c 1005
charly 0:79c6d0071c4c 1006 // These volatile members may get changed in the interrupt service routine
charly 0:79c6d0071c4c 1007 uint8_t _buf[RF22_MAX_MESSAGE_LEN];
charly 0:79c6d0071c4c 1008 volatile uint8_t _bufLen;
charly 0:79c6d0071c4c 1009
charly 0:79c6d0071c4c 1010 volatile boolean _rxBufValid;
charly 0:79c6d0071c4c 1011
charly 0:79c6d0071c4c 1012 volatile boolean _txPacketSent;
charly 0:79c6d0071c4c 1013 volatile uint8_t _txBufSentIndex;
charly 0:79c6d0071c4c 1014
charly 0:79c6d0071c4c 1015 volatile uint16_t _rxBad;
charly 0:79c6d0071c4c 1016 volatile uint16_t _rxGood;
charly 0:79c6d0071c4c 1017 volatile uint16_t _txGood;
charly 0:79c6d0071c4c 1018
charly 0:79c6d0071c4c 1019 volatile uint8_t _lastRssi;
charly 0:79c6d0071c4c 1020
charly 0:79c6d0071c4c 1021 };
charly 0:79c6d0071c4c 1022
charly 0:79c6d0071c4c 1023
charly 0:79c6d0071c4c 1024 #endif