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