final

Dependencies:   mbed FATFileSystem

Fork of KL46Z-USBHostMSD_HelloWorld by Norimasa Okamoto

Committer:
homzovam
Date:
Sat Apr 04 20:16:39 2015 +0000
Revision:
4:77d6450f34d7
prijimac-funkcni final

Who changed what in which revision?

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