This is for ICRS\' second generation Quadcopter

Dependencies:   mbed

Committer:
madcowswe
Date:
Fri Nov 18 18:23:33 2011 +0000
Revision:
0:0bbf2f16da9c

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
madcowswe 0:0bbf2f16da9c 1 /*
madcowswe 0:0bbf2f16da9c 2 * Open HR20
madcowswe 0:0bbf2f16da9c 3 *
madcowswe 0:0bbf2f16da9c 4 * target: ATmega169 @ 4 MHz in Honnywell Rondostat HR20E
madcowswe 0:0bbf2f16da9c 5 *
madcowswe 0:0bbf2f16da9c 6 * compiler: WinAVR-20071221
madcowswe 0:0bbf2f16da9c 7 * avr-libc 1.6.0
madcowswe 0:0bbf2f16da9c 8 * GCC 4.2.2
madcowswe 0:0bbf2f16da9c 9 *
madcowswe 0:0bbf2f16da9c 10 * copyright: 2008 Dario Carluccio (hr20-at-carluccio-dot-de)
madcowswe 0:0bbf2f16da9c 11 * 2008 Jiri Dobry (jdobry-at-centrum-dot-cz)
madcowswe 0:0bbf2f16da9c 12 * 2008 Mario Fischer (MarioFischer-at-gmx-dot-net)
madcowswe 0:0bbf2f16da9c 13 * 2007 Michael Smola (Michael-dot-Smola-at-gmx-dot-net)
madcowswe 0:0bbf2f16da9c 14 *
madcowswe 0:0bbf2f16da9c 15 * license: This program is free software; you can redistribute it and/or
madcowswe 0:0bbf2f16da9c 16 * modify it under the terms of the GNU Library General Public
madcowswe 0:0bbf2f16da9c 17 * License as published by the Free Software Foundation; either
madcowswe 0:0bbf2f16da9c 18 * version 2 of the License, or (at your option) any later version.
madcowswe 0:0bbf2f16da9c 19 *
madcowswe 0:0bbf2f16da9c 20 * This program is distributed in the hope that it will be useful,
madcowswe 0:0bbf2f16da9c 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
madcowswe 0:0bbf2f16da9c 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
madcowswe 0:0bbf2f16da9c 23 * GNU General Public License for more details.
madcowswe 0:0bbf2f16da9c 24 *
madcowswe 0:0bbf2f16da9c 25 * You should have received a copy of the GNU General Public License
madcowswe 0:0bbf2f16da9c 26 * along with this program. If not, see http:*www.gnu.org/licenses
madcowswe 0:0bbf2f16da9c 27 */
madcowswe 0:0bbf2f16da9c 28
madcowswe 0:0bbf2f16da9c 29 /*
madcowswe 0:0bbf2f16da9c 30 * \file rfm.h
madcowswe 0:0bbf2f16da9c 31 * \brief functions to control the RFM12 Radio Transceiver Module
madcowswe 0:0bbf2f16da9c 32 * \author Mario Fischer <MarioFischer-at-gmx-dot-net>; Michael Smola <Michael-dot-Smola-at-gmx-dot-net>
madcowswe 0:0bbf2f16da9c 33 * \date $Date: 2010/04/17 17:57:02 $
madcowswe 0:0bbf2f16da9c 34 * $Rev: 260 $
madcowswe 0:0bbf2f16da9c 35 */
madcowswe 0:0bbf2f16da9c 36
madcowswe 0:0bbf2f16da9c 37
madcowswe 0:0bbf2f16da9c 38 //#pragma once // multi-iclude prevention. gcc knows this pragma
madcowswe 0:0bbf2f16da9c 39 #ifndef rfm_H
madcowswe 0:0bbf2f16da9c 40 #define rfm_H
madcowswe 0:0bbf2f16da9c 41
madcowswe 0:0bbf2f16da9c 42
madcowswe 0:0bbf2f16da9c 43 #define RFM_SPI_16(OUTVAL) rfm_spi16(OUTVAL) //<! a function that gets a uint16_t (clocked out value) and returns a uint16_t (clocked in value)
madcowswe 0:0bbf2f16da9c 44
madcowswe 0:0bbf2f16da9c 45 #define RFM_CLK_OUTPUT 0
madcowswe 0:0bbf2f16da9c 46
madcowswe 0:0bbf2f16da9c 47 /*
madcowswe 0:0bbf2f16da9c 48 #define RFM_TESTPIN_INIT
madcowswe 0:0bbf2f16da9c 49 #define RFM_TESTPIN_ON
madcowswe 0:0bbf2f16da9c 50 #define RFM_TESTPIN_OFF
madcowswe 0:0bbf2f16da9c 51 #define RFM_TESTPIN_TOG
madcowswe 0:0bbf2f16da9c 52
madcowswe 0:0bbf2f16da9c 53 #define RFM_CONFIG_DISABLE 0x00 //<! RFM_CONFIG_*** are combinable flags, what the RFM shold do
madcowswe 0:0bbf2f16da9c 54 #define RFM_CONFIG_BROADCASTSTATUS 0x01 //<! Flag that enables the HR20's status broadcast every minute
madcowswe 0:0bbf2f16da9c 55
madcowswe 0:0bbf2f16da9c 56 #define RFM_CONFIG_ENABLEALL 0xff
madcowswe 0:0bbf2f16da9c 57 */
madcowswe 0:0bbf2f16da9c 58
madcowswe 0:0bbf2f16da9c 59
madcowswe 0:0bbf2f16da9c 60 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 61 //
madcowswe 0:0bbf2f16da9c 62 // RFM status bits
madcowswe 0:0bbf2f16da9c 63 //
madcowswe 0:0bbf2f16da9c 64 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 65
madcowswe 0:0bbf2f16da9c 66 // Interrupt bits, latched ////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 67
madcowswe 0:0bbf2f16da9c 68 #define RFM_STATUS_FFIT 0x8000 // RX FIFO reached the progr. number of bits
madcowswe 0:0bbf2f16da9c 69 // Cleared by any FIFO read method
madcowswe 0:0bbf2f16da9c 70
madcowswe 0:0bbf2f16da9c 71 #define RFM_STATUS_RGIT 0x8000 // TX register is ready to receive
madcowswe 0:0bbf2f16da9c 72 // Cleared by TX write
madcowswe 0:0bbf2f16da9c 73
madcowswe 0:0bbf2f16da9c 74 #define RFM_STATUS_POR 0x4000 // Power On reset
madcowswe 0:0bbf2f16da9c 75 // Cleared by read status
madcowswe 0:0bbf2f16da9c 76
madcowswe 0:0bbf2f16da9c 77 #define RFM_STATUS_RGUR 0x2000 // TX register underrun, register over write
madcowswe 0:0bbf2f16da9c 78 // Cleared by read status
madcowswe 0:0bbf2f16da9c 79
madcowswe 0:0bbf2f16da9c 80 #define RFM_STATUS_FFOV 0x2000 // RX FIFO overflow
madcowswe 0:0bbf2f16da9c 81 // Cleared by read status
madcowswe 0:0bbf2f16da9c 82
madcowswe 0:0bbf2f16da9c 83 #define RFM_STATUS_WKUP 0x1000 // Wake up timer overflow
madcowswe 0:0bbf2f16da9c 84 // Cleared by read status
madcowswe 0:0bbf2f16da9c 85
madcowswe 0:0bbf2f16da9c 86 #define RFM_STATUS_EXT 0x0800 // Interupt changed to low
madcowswe 0:0bbf2f16da9c 87 // Cleared by read status
madcowswe 0:0bbf2f16da9c 88
madcowswe 0:0bbf2f16da9c 89 #define RFM_STATUS_LBD 0x0400 // Low battery detect
madcowswe 0:0bbf2f16da9c 90
madcowswe 0:0bbf2f16da9c 91 // Status bits ////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 92
madcowswe 0:0bbf2f16da9c 93 #define RFM_STATUS_FFEM 0x0200 // FIFO is empty
madcowswe 0:0bbf2f16da9c 94 #define RFM_STATUS_ATS 0x0100 // TX mode: Strong enough RF signal
madcowswe 0:0bbf2f16da9c 95 #define RFM_STATUS_RSSI 0x0100 // RX mode: signal strength above programmed limit
madcowswe 0:0bbf2f16da9c 96 #define RFM_STATUS_DQD 0x0080 // Data Quality detector output
madcowswe 0:0bbf2f16da9c 97 #define RFM_STATUS_CRL 0x0040 // Clock recovery lock
madcowswe 0:0bbf2f16da9c 98 #define RFM_STATUS_ATGL 0x0020 // Toggling in each AFC cycle
madcowswe 0:0bbf2f16da9c 99
madcowswe 0:0bbf2f16da9c 100 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 101 //
madcowswe 0:0bbf2f16da9c 102 // 1. Configuration Setting Command
madcowswe 0:0bbf2f16da9c 103 //
madcowswe 0:0bbf2f16da9c 104 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 105
madcowswe 0:0bbf2f16da9c 106 #define RFM_CONFIG 0x8000
madcowswe 0:0bbf2f16da9c 107
madcowswe 0:0bbf2f16da9c 108 #define RFM_CONFIG_EL 0x8080 // Enable TX Register
madcowswe 0:0bbf2f16da9c 109 #define RFM_CONFIG_EF 0x8040 // Enable RX FIFO buffer
madcowswe 0:0bbf2f16da9c 110 #define RFM_CONFIG_BAND_315 0x8000 // Frequency band
madcowswe 0:0bbf2f16da9c 111 #define RFM_CONFIG_BAND_433 0x8010
madcowswe 0:0bbf2f16da9c 112 #define RFM_CONFIG_BAND_868 0x8020
madcowswe 0:0bbf2f16da9c 113 #define RFM_CONFIG_BAND_915 0x8030
madcowswe 0:0bbf2f16da9c 114 #define RFM_CONFIG_X_8_5pf 0x8000 // Crystal Load Capacitor
madcowswe 0:0bbf2f16da9c 115 #define RFM_CONFIG_X_9_0pf 0x8001
madcowswe 0:0bbf2f16da9c 116 #define RFM_CONFIG_X_9_5pf 0x8002
madcowswe 0:0bbf2f16da9c 117 #define RFM_CONFIG_X_10_0pf 0x8003
madcowswe 0:0bbf2f16da9c 118 #define RFM_CONFIG_X_10_5pf 0x8004
madcowswe 0:0bbf2f16da9c 119 #define RFM_CONFIG_X_11_0pf 0x8005
madcowswe 0:0bbf2f16da9c 120 #define RFM_CONFIG_X_11_5pf 0x8006
madcowswe 0:0bbf2f16da9c 121 #define RFM_CONFIG_X_12_0pf 0x8007
madcowswe 0:0bbf2f16da9c 122 #define RFM_CONFIG_X_12_5pf 0x8008
madcowswe 0:0bbf2f16da9c 123 #define RFM_CONFIG_X_13_0pf 0x8009
madcowswe 0:0bbf2f16da9c 124 #define RFM_CONFIG_X_13_5pf 0x800A
madcowswe 0:0bbf2f16da9c 125 #define RFM_CONFIG_X_14_0pf 0x800B
madcowswe 0:0bbf2f16da9c 126 #define RFM_CONFIG_X_14_5pf 0x800C
madcowswe 0:0bbf2f16da9c 127 #define RFM_CONFIG_X_15_0pf 0x800D
madcowswe 0:0bbf2f16da9c 128 #define RFM_CONFIG_X_15_5pf 0x800E
madcowswe 0:0bbf2f16da9c 129 #define RFM_CONFIG_X_16_0pf 0x800F
madcowswe 0:0bbf2f16da9c 130
madcowswe 0:0bbf2f16da9c 131 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 132 //
madcowswe 0:0bbf2f16da9c 133 // 2. Power Management Command
madcowswe 0:0bbf2f16da9c 134 //
madcowswe 0:0bbf2f16da9c 135 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 136
madcowswe 0:0bbf2f16da9c 137 #define RFM_POWER_MANAGEMENT 0x8200
madcowswe 0:0bbf2f16da9c 138
madcowswe 0:0bbf2f16da9c 139 #define RFM_POWER_MANAGEMENT_ER 0x8280 // Enable receiver
madcowswe 0:0bbf2f16da9c 140 #define RFM_POWER_MANAGEMENT_EBB 0x8240 // Enable base band block
madcowswe 0:0bbf2f16da9c 141 #define RFM_POWER_MANAGEMENT_ET 0x8220 // Enable transmitter
madcowswe 0:0bbf2f16da9c 142 #define RFM_POWER_MANAGEMENT_ES 0x8210 // Enable synthesizer
madcowswe 0:0bbf2f16da9c 143 #define RFM_POWER_MANAGEMENT_EX 0x8208 // Enable crystal oscillator
madcowswe 0:0bbf2f16da9c 144 #define RFM_POWER_MANAGEMENT_EB 0x8204 // Enable low battery detector
madcowswe 0:0bbf2f16da9c 145 #define RFM_POWER_MANAGEMENT_EW 0x8202 // Enable wake-up timer
madcowswe 0:0bbf2f16da9c 146 #define RFM_POWER_MANAGEMENT_DC 0x8201 // Disable clock output of CLK pin
madcowswe 0:0bbf2f16da9c 147
madcowswe 0:0bbf2f16da9c 148 #ifndef RFM_CLK_OUTPUT
madcowswe 0:0bbf2f16da9c 149 #error RFM_CLK_OUTPUT must be defined to 0 or 1
madcowswe 0:0bbf2f16da9c 150 #endif
madcowswe 0:0bbf2f16da9c 151 #if RFM_CLK_OUTPUT
madcowswe 0:0bbf2f16da9c 152 #define RFM_TX_ON_PRE() RFM_SPI_16( \
madcowswe 0:0bbf2f16da9c 153 RFM_POWER_MANAGEMENT_ES | \
madcowswe 0:0bbf2f16da9c 154 RFM_POWER_MANAGEMENT_EX )
madcowswe 0:0bbf2f16da9c 155 #define RFM_TX_ON() RFM_SPI_16( \
madcowswe 0:0bbf2f16da9c 156 RFM_POWER_MANAGEMENT_ET | \
madcowswe 0:0bbf2f16da9c 157 RFM_POWER_MANAGEMENT_ES | \
madcowswe 0:0bbf2f16da9c 158 RFM_POWER_MANAGEMENT_EX )
madcowswe 0:0bbf2f16da9c 159 #define RFM_RX_ON() RFM_SPI_16( \
madcowswe 0:0bbf2f16da9c 160 RFM_POWER_MANAGEMENT_ER | \
madcowswe 0:0bbf2f16da9c 161 RFM_POWER_MANAGEMENT_EBB | \
madcowswe 0:0bbf2f16da9c 162 RFM_POWER_MANAGEMENT_ES | \
madcowswe 0:0bbf2f16da9c 163 RFM_POWER_MANAGEMENT_EX )
madcowswe 0:0bbf2f16da9c 164 #define RFM_OFF() RFM_SPI_16( \
madcowswe 0:0bbf2f16da9c 165 RFM_POWER_MANAGEMENT_EX )
madcowswe 0:0bbf2f16da9c 166 #else
madcowswe 0:0bbf2f16da9c 167 #define RFM_TX_ON_PRE() RFM_SPI_16( \
madcowswe 0:0bbf2f16da9c 168 RFM_POWER_MANAGEMENT_DC | \
madcowswe 0:0bbf2f16da9c 169 RFM_POWER_MANAGEMENT_ES | \
madcowswe 0:0bbf2f16da9c 170 RFM_POWER_MANAGEMENT_EX )
madcowswe 0:0bbf2f16da9c 171 #define RFM_TX_ON() RFM_SPI_16( \
madcowswe 0:0bbf2f16da9c 172 RFM_POWER_MANAGEMENT_DC | \
madcowswe 0:0bbf2f16da9c 173 RFM_POWER_MANAGEMENT_ET | \
madcowswe 0:0bbf2f16da9c 174 RFM_POWER_MANAGEMENT_ES | \
madcowswe 0:0bbf2f16da9c 175 RFM_POWER_MANAGEMENT_EX )
madcowswe 0:0bbf2f16da9c 176 #define RFM_RX_ON() RFM_SPI_16( \
madcowswe 0:0bbf2f16da9c 177 RFM_POWER_MANAGEMENT_DC | \
madcowswe 0:0bbf2f16da9c 178 RFM_POWER_MANAGEMENT_ER | \
madcowswe 0:0bbf2f16da9c 179 RFM_POWER_MANAGEMENT_EBB | \
madcowswe 0:0bbf2f16da9c 180 RFM_POWER_MANAGEMENT_ES | \
madcowswe 0:0bbf2f16da9c 181 RFM_POWER_MANAGEMENT_EX )
madcowswe 0:0bbf2f16da9c 182 #define RFM_OFF() RFM_SPI_16(RFM_POWER_MANAGEMENT_DC)
madcowswe 0:0bbf2f16da9c 183 #endif
madcowswe 0:0bbf2f16da9c 184 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 185 //
madcowswe 0:0bbf2f16da9c 186 // 3. Frequency Setting Command
madcowswe 0:0bbf2f16da9c 187 //
madcowswe 0:0bbf2f16da9c 188 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 189
madcowswe 0:0bbf2f16da9c 190 #define RFM_FREQUENCY 0xA000
madcowswe 0:0bbf2f16da9c 191
madcowswe 0:0bbf2f16da9c 192 #define RFM_FREQ_315Band(v) (uint16_t)((v/10.0-31)*4000)
madcowswe 0:0bbf2f16da9c 193 #define RFM_FREQ_433Band(v) (uint16_t)((v/10.0-43)*4000)
madcowswe 0:0bbf2f16da9c 194 #define RFM_FREQ_868Band(v) (uint16_t)((v/20.0-43)*4000)
madcowswe 0:0bbf2f16da9c 195 #define RFM_FREQ_915Band(v) (uint16_t)((v/30.0-30)*4000)
madcowswe 0:0bbf2f16da9c 196
madcowswe 0:0bbf2f16da9c 197 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 198 //
madcowswe 0:0bbf2f16da9c 199 // 4. Data Rate Command
madcowswe 0:0bbf2f16da9c 200 //
madcowswe 0:0bbf2f16da9c 201 /////////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 202
madcowswe 0:0bbf2f16da9c 203 #define RFM_BAUD_RATE 9600
madcowswe 0:0bbf2f16da9c 204
madcowswe 0:0bbf2f16da9c 205 #define RFM_DATA_RATE 0xC600
madcowswe 0:0bbf2f16da9c 206
madcowswe 0:0bbf2f16da9c 207 #define RFM_DATA_RATE_CS 0xC680
madcowswe 0:0bbf2f16da9c 208 #define RFM_DATA_RATE_4800 0xC647
madcowswe 0:0bbf2f16da9c 209 #define RFM_DATA_RATE_9600 0xC623
madcowswe 0:0bbf2f16da9c 210 #define RFM_DATA_RATE_19200 0xC611
madcowswe 0:0bbf2f16da9c 211 #define RFM_DATA_RATE_38400 0xC608
madcowswe 0:0bbf2f16da9c 212 #define RFM_DATA_RATE_57600 0xC605
madcowswe 0:0bbf2f16da9c 213
madcowswe 0:0bbf2f16da9c 214 #define RFM_SET_DATARATE(baud) ( ((baud)<5400) ? (RFM_DATA_RATE_CS|((43104/(baud))-1)) : (RFM_DATA_RATE|((344828UL/(baud))-1)) )
madcowswe 0:0bbf2f16da9c 215
madcowswe 0:0bbf2f16da9c 216 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 217 //
madcowswe 0:0bbf2f16da9c 218 // 5. Receiver Control Command
madcowswe 0:0bbf2f16da9c 219 //
madcowswe 0:0bbf2f16da9c 220 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 221
madcowswe 0:0bbf2f16da9c 222 #define RFM_RX_CONTROL 0x9000
madcowswe 0:0bbf2f16da9c 223
madcowswe 0:0bbf2f16da9c 224 #define RFM_RX_CONTROL_P20_INT 0x9000 // Pin20 = ExternalInt
madcowswe 0:0bbf2f16da9c 225 #define RFM_RX_CONTROL_P20_VDI 0x9400 // Pin20 = VDI out
madcowswe 0:0bbf2f16da9c 226
madcowswe 0:0bbf2f16da9c 227 #define RFM_RX_CONTROL_VDI_FAST 0x9000 // fast VDI Response time
madcowswe 0:0bbf2f16da9c 228 #define RFM_RX_CONTROL_VDI_MED 0x9100 // medium
madcowswe 0:0bbf2f16da9c 229 #define RFM_RX_CONTROL_VDI_SLOW 0x9200 // slow
madcowswe 0:0bbf2f16da9c 230 #define RFM_RX_CONTROL_VDI_ON 0x9300 // Always on
madcowswe 0:0bbf2f16da9c 231
madcowswe 0:0bbf2f16da9c 232 #define RFM_RX_CONTROL_BW_400 0x9020 // bandwidth 400kHz
madcowswe 0:0bbf2f16da9c 233 #define RFM_RX_CONTROL_BW_340 0x9040 // bandwidth 340kHz
madcowswe 0:0bbf2f16da9c 234 #define RFM_RX_CONTROL_BW_270 0x9060 // bandwidth 270kHz
madcowswe 0:0bbf2f16da9c 235 #define RFM_RX_CONTROL_BW_200 0x9080 // bandwidth 200kHz
madcowswe 0:0bbf2f16da9c 236 #define RFM_RX_CONTROL_BW_134 0x90A0 // bandwidth 134kHz
madcowswe 0:0bbf2f16da9c 237 #define RFM_RX_CONTROL_BW_67 0x90C0 // bandwidth 67kHz
madcowswe 0:0bbf2f16da9c 238
madcowswe 0:0bbf2f16da9c 239 #define RFM_RX_CONTROL_GAIN_0 0x9000 // LNA gain 0db
madcowswe 0:0bbf2f16da9c 240 #define RFM_RX_CONTROL_GAIN_6 0x9008 // LNA gain -6db
madcowswe 0:0bbf2f16da9c 241 #define RFM_RX_CONTROL_GAIN_14 0x9010 // LNA gain -14db
madcowswe 0:0bbf2f16da9c 242 #define RFM_RX_CONTROL_GAIN_20 0x9018 // LNA gain -20db
madcowswe 0:0bbf2f16da9c 243
madcowswe 0:0bbf2f16da9c 244 #define RFM_RX_CONTROL_RSSI_103 0x9000 // DRSSI threshold -103dbm
madcowswe 0:0bbf2f16da9c 245 #define RFM_RX_CONTROL_RSSI_97 0x9001 // DRSSI threshold -97dbm
madcowswe 0:0bbf2f16da9c 246 #define RFM_RX_CONTROL_RSSI_91 0x9002 // DRSSI threshold -91dbm
madcowswe 0:0bbf2f16da9c 247 #define RFM_RX_CONTROL_RSSI_85 0x9003 // DRSSI threshold -85dbm
madcowswe 0:0bbf2f16da9c 248 #define RFM_RX_CONTROL_RSSI_79 0x9004 // DRSSI threshold -79dbm
madcowswe 0:0bbf2f16da9c 249 #define RFM_RX_CONTROL_RSSI_73 0x9005 // DRSSI threshold -73dbm
madcowswe 0:0bbf2f16da9c 250 //#define RFM_RX_CONTROL_RSSI_67 0x9006 // DRSSI threshold -67dbm // RF12B reserved
madcowswe 0:0bbf2f16da9c 251 //#define RFM_RX_CONTROL_RSSI_61 0x9007 // DRSSI threshold -61dbm // RF12B reserved
madcowswe 0:0bbf2f16da9c 252
madcowswe 0:0bbf2f16da9c 253 #define RFM_RX_CONTROL_BW(baud) (((baud)<8000) ? \
madcowswe 0:0bbf2f16da9c 254 RFM_RX_CONTROL_BW_67 : \
madcowswe 0:0bbf2f16da9c 255 ( \
madcowswe 0:0bbf2f16da9c 256 ((baud)<30000) ? \
madcowswe 0:0bbf2f16da9c 257 RFM_RX_CONTROL_BW_134 : \
madcowswe 0:0bbf2f16da9c 258 RFM_RX_CONTROL_BW_200 \
madcowswe 0:0bbf2f16da9c 259 ))
madcowswe 0:0bbf2f16da9c 260
madcowswe 0:0bbf2f16da9c 261 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 262 //
madcowswe 0:0bbf2f16da9c 263 // 6. Data Filter Command
madcowswe 0:0bbf2f16da9c 264 //
madcowswe 0:0bbf2f16da9c 265 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 266
madcowswe 0:0bbf2f16da9c 267 #define RFM_DATA_FILTER 0xC228
madcowswe 0:0bbf2f16da9c 268
madcowswe 0:0bbf2f16da9c 269 #define RFM_DATA_FILTER_AL 0xC2A8 // clock recovery auto-lock
madcowswe 0:0bbf2f16da9c 270 #define RFM_DATA_FILTER_ML 0xC268 // clock recovery fast mode
madcowswe 0:0bbf2f16da9c 271 #define RFM_DATA_FILTER_DIG 0xC228 // data filter type digital
madcowswe 0:0bbf2f16da9c 272 #define RFM_DATA_FILTER_ANALOG 0xC238 // data filter type analog
madcowswe 0:0bbf2f16da9c 273 #define RFM_DATA_FILTER_DQD(level) (RFM_DATA_FILTER | (level & 0x7))
madcowswe 0:0bbf2f16da9c 274
madcowswe 0:0bbf2f16da9c 275 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 276 //
madcowswe 0:0bbf2f16da9c 277 // 7. FIFO and Reset Mode Command
madcowswe 0:0bbf2f16da9c 278 //
madcowswe 0:0bbf2f16da9c 279 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 280
madcowswe 0:0bbf2f16da9c 281 #define RFM_FIFO 0xCA00
madcowswe 0:0bbf2f16da9c 282
madcowswe 0:0bbf2f16da9c 283 #define RFM_FIFO_AL 0xCA04 // FIFO Start condition sync-word/always
madcowswe 0:0bbf2f16da9c 284 #define RFM_FIFO_FF 0xCA02 // Enable FIFO fill
madcowswe 0:0bbf2f16da9c 285 #define RFM_FIFO_DR 0xCA01 // Disable hi sens reset mode
madcowswe 0:0bbf2f16da9c 286 #define RFM_FIFO_IT(level) (RFM_FIFO | (( (level) & 0xF)<<4))
madcowswe 0:0bbf2f16da9c 287
madcowswe 0:0bbf2f16da9c 288 #define RFM_FIFO_OFF() RFM_SPI_16(RFM_FIFO_IT(8) | RFM_FIFO_DR)
madcowswe 0:0bbf2f16da9c 289 #define RFM_FIFO_ON() RFM_SPI_16(RFM_FIFO_IT(8) | RFM_FIFO_FF | RFM_FIFO_DR)
madcowswe 0:0bbf2f16da9c 290
madcowswe 0:0bbf2f16da9c 291 /////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 292 //
madcowswe 0:0bbf2f16da9c 293 // 8. Receiver FIFO Read
madcowswe 0:0bbf2f16da9c 294 //
madcowswe 0:0bbf2f16da9c 295 /////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 296
madcowswe 0:0bbf2f16da9c 297 #define RFM_READ_FIFO() (RFM_SPI_16(0xB000) & 0xFF)
madcowswe 0:0bbf2f16da9c 298
madcowswe 0:0bbf2f16da9c 299 /////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 300 //
madcowswe 0:0bbf2f16da9c 301 // 9. AFC Command
madcowswe 0:0bbf2f16da9c 302 //
madcowswe 0:0bbf2f16da9c 303 /////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 304
madcowswe 0:0bbf2f16da9c 305 #define RFM_AFC 0xC400
madcowswe 0:0bbf2f16da9c 306
madcowswe 0:0bbf2f16da9c 307 #define RFM_AFC_EN 0xC401
madcowswe 0:0bbf2f16da9c 308 #define RFM_AFC_OE 0xC402
madcowswe 0:0bbf2f16da9c 309 #define RFM_AFC_FI 0xC404
madcowswe 0:0bbf2f16da9c 310 #define RFM_AFC_ST 0xC408
madcowswe 0:0bbf2f16da9c 311
madcowswe 0:0bbf2f16da9c 312 // Limits the value of the frequency offset register to the next values:
madcowswe 0:0bbf2f16da9c 313
madcowswe 0:0bbf2f16da9c 314 #define RFM_AFC_RANGE_LIMIT_NO 0xC400 // 0: No restriction
madcowswe 0:0bbf2f16da9c 315 #define RFM_AFC_RANGE_LIMIT_15_16 0xC410 // 1: +15 fres to -16 fres
madcowswe 0:0bbf2f16da9c 316 #define RFM_AFC_RANGE_LIMIT_7_8 0xC420 // 2: +7 fres to -8 fres
madcowswe 0:0bbf2f16da9c 317 #define RFM_AFC_RANGE_LIMIT_3_4 0xC430 // 3: +3 fres to -4 fres
madcowswe 0:0bbf2f16da9c 318
madcowswe 0:0bbf2f16da9c 319 // fres=2.5 kHz in 315MHz and 433MHz Bands
madcowswe 0:0bbf2f16da9c 320 // fres=5.0 kHz in 868MHz Band
madcowswe 0:0bbf2f16da9c 321 // fres=7.5 kHz in 915MHz Band
madcowswe 0:0bbf2f16da9c 322
madcowswe 0:0bbf2f16da9c 323 #define RFM_AFC_AUTO_OFF 0xC400 // 0: Auto mode off (Strobe is controlled by microcontroller)
madcowswe 0:0bbf2f16da9c 324 #define RFM_AFC_AUTO_ONCE 0xC440 // 1: Runs only once after each power-up
madcowswe 0:0bbf2f16da9c 325 #define RFM_AFC_AUTO_VDI 0xC480 // 2: Keep the foffset only during receiving(VDI=high)
madcowswe 0:0bbf2f16da9c 326 #define RFM_AFC_AUTO_INDEPENDENT 0xC4C0 // 3: Keep the foffset value independently trom the state of the VDI signal
madcowswe 0:0bbf2f16da9c 327
madcowswe 0:0bbf2f16da9c 328 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 329 //
madcowswe 0:0bbf2f16da9c 330 // 10. TX Configuration Control Command
madcowswe 0:0bbf2f16da9c 331 //
madcowswe 0:0bbf2f16da9c 332 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 333
madcowswe 0:0bbf2f16da9c 334 #define RFM_TX_CONTROL 0x9800
madcowswe 0:0bbf2f16da9c 335
madcowswe 0:0bbf2f16da9c 336 #define RFM_TX_CONTROL_POW_0 0x9800
madcowswe 0:0bbf2f16da9c 337 #define RFM_TX_CONTROL_POW_3 0x9801
madcowswe 0:0bbf2f16da9c 338 #define RFM_TX_CONTROL_POW_6 0x9802
madcowswe 0:0bbf2f16da9c 339 #define RFM_TX_CONTROL_POW_9 0x9803
madcowswe 0:0bbf2f16da9c 340 #define RFM_TX_CONTROL_POW_12 0x9804
madcowswe 0:0bbf2f16da9c 341 #define RFM_TX_CONTROL_POW_15 0x9805
madcowswe 0:0bbf2f16da9c 342 #define RFM_TX_CONTROL_POW_18 0x9806
madcowswe 0:0bbf2f16da9c 343 #define RFM_TX_CONTROL_POW_21 0x9807
madcowswe 0:0bbf2f16da9c 344 #define RFM_TX_CONTROL_MOD_15 0x9800
madcowswe 0:0bbf2f16da9c 345 #define RFM_TX_CONTROL_MOD_30 0x9810
madcowswe 0:0bbf2f16da9c 346 #define RFM_TX_CONTROL_MOD_45 0x9820
madcowswe 0:0bbf2f16da9c 347 #define RFM_TX_CONTROL_MOD_60 0x9830
madcowswe 0:0bbf2f16da9c 348 #define RFM_TX_CONTROL_MOD_75 0x9840
madcowswe 0:0bbf2f16da9c 349 #define RFM_TX_CONTROL_MOD_90 0x9850
madcowswe 0:0bbf2f16da9c 350 #define RFM_TX_CONTROL_MOD_105 0x9860
madcowswe 0:0bbf2f16da9c 351 #define RFM_TX_CONTROL_MOD_120 0x9870
madcowswe 0:0bbf2f16da9c 352 #define RFM_TX_CONTROL_MOD_135 0x9880
madcowswe 0:0bbf2f16da9c 353 #define RFM_TX_CONTROL_MOD_150 0x9890
madcowswe 0:0bbf2f16da9c 354 #define RFM_TX_CONTROL_MOD_165 0x98A0
madcowswe 0:0bbf2f16da9c 355 #define RFM_TX_CONTROL_MOD_180 0x98B0
madcowswe 0:0bbf2f16da9c 356 #define RFM_TX_CONTROL_MOD_195 0x98C0
madcowswe 0:0bbf2f16da9c 357 #define RFM_TX_CONTROL_MOD_210 0x98D0
madcowswe 0:0bbf2f16da9c 358 #define RFM_TX_CONTROL_MOD_225 0x98E0
madcowswe 0:0bbf2f16da9c 359 #define RFM_TX_CONTROL_MOD_240 0x98F0
madcowswe 0:0bbf2f16da9c 360 #define RFM_TX_CONTROL_MP 0x9900
madcowswe 0:0bbf2f16da9c 361
madcowswe 0:0bbf2f16da9c 362 #define RFM_TX_CONTROL_MOD(baud) (((baud)<8000) ? \
madcowswe 0:0bbf2f16da9c 363 RFM_TX_CONTROL_MOD_45 : \
madcowswe 0:0bbf2f16da9c 364 ( \
madcowswe 0:0bbf2f16da9c 365 ((baud)<20000) ? \
madcowswe 0:0bbf2f16da9c 366 RFM_TX_CONTROL_MOD_60 : \
madcowswe 0:0bbf2f16da9c 367 ( \
madcowswe 0:0bbf2f16da9c 368 ((baud)<30000) ? \
madcowswe 0:0bbf2f16da9c 369 RFM_TX_CONTROL_MOD_75 : \
madcowswe 0:0bbf2f16da9c 370 ( \
madcowswe 0:0bbf2f16da9c 371 ((baud)<40000) ? \
madcowswe 0:0bbf2f16da9c 372 RFM_TX_CONTROL_MOD_90 : \
madcowswe 0:0bbf2f16da9c 373 RFM_TX_CONTROL_MOD_120 \
madcowswe 0:0bbf2f16da9c 374 ) \
madcowswe 0:0bbf2f16da9c 375 ) \
madcowswe 0:0bbf2f16da9c 376 ))
madcowswe 0:0bbf2f16da9c 377
madcowswe 0:0bbf2f16da9c 378 /////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 379 //
madcowswe 0:0bbf2f16da9c 380 // 11. Transmitter Register Write Command
madcowswe 0:0bbf2f16da9c 381 //
madcowswe 0:0bbf2f16da9c 382 /////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 383
madcowswe 0:0bbf2f16da9c 384 //#define RFM_WRITE(byte) RFM_SPI_16(0xB800 | ((byte) & 0xFF))
madcowswe 0:0bbf2f16da9c 385 #define RFM_WRITE(byte) RFM_SPI_16(0xB800 | (byte) )
madcowswe 0:0bbf2f16da9c 386
madcowswe 0:0bbf2f16da9c 387 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 388 //
madcowswe 0:0bbf2f16da9c 389 // 12. Wake-up Timer Command
madcowswe 0:0bbf2f16da9c 390 //
madcowswe 0:0bbf2f16da9c 391 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 392
madcowswe 0:0bbf2f16da9c 393 #define RFM_WAKEUP_TIMER 0xE000
madcowswe 0:0bbf2f16da9c 394 #define RFM_WAKEUP_SET(time) RFM_SPI_16(RFM_WAKEUP_TIMER | (time))
madcowswe 0:0bbf2f16da9c 395
madcowswe 0:0bbf2f16da9c 396 #define RFM_WAKEUP_480s (RFM_WAKEUP_TIMER |(11 << 8)| 234)
madcowswe 0:0bbf2f16da9c 397 #define RFM_WAKEUP_240s (RFM_WAKEUP_TIMER |(10 << 8)| 234)
madcowswe 0:0bbf2f16da9c 398 #define RFM_WAKEUP_120s (RFM_WAKEUP_TIMER |(9 << 8)| 234)
madcowswe 0:0bbf2f16da9c 399 #define RFM_WAKEUP_119s (RFM_WAKEUP_TIMER |(9 << 8)| 232)
madcowswe 0:0bbf2f16da9c 400
madcowswe 0:0bbf2f16da9c 401 #define RFM_WAKEUP_60s (RFM_WAKEUP_TIMER |(8 << 8) | 235)
madcowswe 0:0bbf2f16da9c 402 #define RFM_WAKEUP_59s (RFM_WAKEUP_TIMER |(8 << 8) | 230)
madcowswe 0:0bbf2f16da9c 403
madcowswe 0:0bbf2f16da9c 404 #define RFM_WAKEUP_30s (RFM_WAKEUP_TIMER |(7 << 8) | 235)
madcowswe 0:0bbf2f16da9c 405 #define RFM_WAKEUP_29s (RFM_WAKEUP_TIMER |(7 << 8) | 227)
madcowswe 0:0bbf2f16da9c 406
madcowswe 0:0bbf2f16da9c 407 #define RFM_WAKEUP_8s (RFM_WAKEUP_TIMER |(5 << 8) | 250)
madcowswe 0:0bbf2f16da9c 408 #define RFM_WAKEUP_7s (RFM_WAKEUP_TIMER |(5 << 8) | 219)
madcowswe 0:0bbf2f16da9c 409 #define RFM_WAKEUP_6s (RFM_WAKEUP_TIMER |(6 << 8) | 94)
madcowswe 0:0bbf2f16da9c 410 #define RFM_WAKEUP_5s (RFM_WAKEUP_TIMER |(5 << 8) | 156)
madcowswe 0:0bbf2f16da9c 411 #define RFM_WAKEUP_4s (RFM_WAKEUP_TIMER |(5 << 8) | 125)
madcowswe 0:0bbf2f16da9c 412 #define RFM_WAKEUP_1s (RFM_WAKEUP_TIMER |(2 << 8) | 250)
madcowswe 0:0bbf2f16da9c 413 #define RFM_WAKEUP_900ms (RFM_WAKEUP_TIMER |(2 << 8) | 225)
madcowswe 0:0bbf2f16da9c 414 #define RFM_WAKEUP_800ms (RFM_WAKEUP_TIMER |(2 << 8) | 200)
madcowswe 0:0bbf2f16da9c 415 #define RFM_WAKEUP_700ms (RFM_WAKEUP_TIMER |(2 << 8) | 175)
madcowswe 0:0bbf2f16da9c 416 #define RFM_WAKEUP_600ms (RFM_WAKEUP_TIMER |(2 << 8) | 150)
madcowswe 0:0bbf2f16da9c 417 #define RFM_WAKEUP_500ms (RFM_WAKEUP_TIMER |(2 << 8) | 125)
madcowswe 0:0bbf2f16da9c 418 #define RFM_WAKEUP_400ms (RFM_WAKEUP_TIMER |(2 << 8) | 100)
madcowswe 0:0bbf2f16da9c 419 #define RFM_WAKEUP_300ms (RFM_WAKEUP_TIMER |(2 << 8) | 75)
madcowswe 0:0bbf2f16da9c 420 #define RFM_WAKEUP_200ms (RFM_WAKEUP_TIMER |(2 << 8) | 50)
madcowswe 0:0bbf2f16da9c 421 #define RFM_WAKEUP_100ms (RFM_WAKEUP_TIMER |(2 << 8) | 25)
madcowswe 0:0bbf2f16da9c 422
madcowswe 0:0bbf2f16da9c 423 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 424 //
madcowswe 0:0bbf2f16da9c 425 // 13. Low Duty-Cycle Command
madcowswe 0:0bbf2f16da9c 426 //
madcowswe 0:0bbf2f16da9c 427 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 428
madcowswe 0:0bbf2f16da9c 429 #define RFM_LOW_DUTY_CYCLE 0xC800
madcowswe 0:0bbf2f16da9c 430
madcowswe 0:0bbf2f16da9c 431 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 432 //
madcowswe 0:0bbf2f16da9c 433 // 14. Low Battery Detector Command
madcowswe 0:0bbf2f16da9c 434 //
madcowswe 0:0bbf2f16da9c 435 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 436
madcowswe 0:0bbf2f16da9c 437 #define RFM_LOW_BATT_DETECT 0xC000
madcowswe 0:0bbf2f16da9c 438 #define RFM_LOW_BATT_DETECT_D_1MHZ 0xC000
madcowswe 0:0bbf2f16da9c 439 #define RFM_LOW_BATT_DETECT_D_1_25MHZ 0xC020
madcowswe 0:0bbf2f16da9c 440 #define RFM_LOW_BATT_DETECT_D_1_66MHZ 0xC040
madcowswe 0:0bbf2f16da9c 441 #define RFM_LOW_BATT_DETECT_D_2MHZ 0xC060
madcowswe 0:0bbf2f16da9c 442 #define RFM_LOW_BATT_DETECT_D_2_5MHZ 0xC080
madcowswe 0:0bbf2f16da9c 443 #define RFM_LOW_BATT_DETECT_D_3_33MHZ 0xC0A0
madcowswe 0:0bbf2f16da9c 444 #define RFM_LOW_BATT_DETECT_D_5MHZ 0xC0C0
madcowswe 0:0bbf2f16da9c 445 #define RFM_LOW_BATT_DETECT_D_10MHZ 0xC0E0
madcowswe 0:0bbf2f16da9c 446
madcowswe 0:0bbf2f16da9c 447 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 448 //
madcowswe 0:0bbf2f16da9c 449 // 15. Status Read Command
madcowswe 0:0bbf2f16da9c 450 //
madcowswe 0:0bbf2f16da9c 451 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 452
madcowswe 0:0bbf2f16da9c 453 #define RFM_READ_STATUS() RFM_SPI_16(0x0000)
madcowswe 0:0bbf2f16da9c 454 #define RFM_READ_STATUS_FFIT() SPI_1 (0x00)
madcowswe 0:0bbf2f16da9c 455 #define RFM_READ_STATUS_RGIT RFM_READ_STATUS_FFIT
madcowswe 0:0bbf2f16da9c 456
madcowswe 0:0bbf2f16da9c 457 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 458
madcowswe 0:0bbf2f16da9c 459 // RFM air protocol flags:
madcowswe 0:0bbf2f16da9c 460
madcowswe 0:0bbf2f16da9c 461 #define RFMPROTO_FLAGS_BITASK_PACKETTYPE 0b11000000 //!< the uppermost 2 bits of the flags field encode the packettype
madcowswe 0:0bbf2f16da9c 462 #define RFMPROTO_FLAGS_PACKETTYPE_BROADCAST 0b00000000 //!< broadcast packettype (message from hr20, protocol; step 1)
madcowswe 0:0bbf2f16da9c 463 #define RFMPROTO_FLAGS_PACKETTYPE_COMMAND 0b01000000 //!< command packettype (message to hr20, protocol; step 2)
madcowswe 0:0bbf2f16da9c 464 #define RFMPROTO_FLAGS_PACKETTYPE_REPLY 0b10000000 //!< reply packettype (message from hr20, protocol; step 3)
madcowswe 0:0bbf2f16da9c 465 #define RFMPROTO_FLAGS_PACKETTYPE_SPECIAL 0b11000000 //!< currently unused packettype
madcowswe 0:0bbf2f16da9c 466
madcowswe 0:0bbf2f16da9c 467 #define RFMPROTO_FLAGS_BITASK_DEVICETYPE 0b00011111 //!< the lowermost 5 bytes denote the device type. this way other sensors and actors may coexist
madcowswe 0:0bbf2f16da9c 468 #define RFMPROTO_FLAGS_DEVICETYPE_OPENHR20 0b00010100 //!< topen HR20 device type. 10100 is for decimal 20
madcowswe 0:0bbf2f16da9c 469
madcowswe 0:0bbf2f16da9c 470 #define RFMPROTO_IS_PACKETTYPE_BROADCAST(FLAGS) ( RFMPROTO_FLAGS_PACKETTYPE_BROADCAST == ((FLAGS) & RFMPROTO_FLAGS_BITASK_PACKETTYPE) )
madcowswe 0:0bbf2f16da9c 471 #define RFMPROTO_IS_PACKETTYPE_COMMAND(FLAGS) ( RFMPROTO_FLAGS_PACKETTYPE_COMMAND == ((FLAGS) & RFMPROTO_FLAGS_BITASK_PACKETTYPE) )
madcowswe 0:0bbf2f16da9c 472 #define RFMPROTO_IS_PACKETTYPE_REPLY(FLAGS) ( RFMPROTO_FLAGS_PACKETTYPE_REPLY == ((FLAGS) & RFMPROTO_FLAGS_BITASK_PACKETTYPE) )
madcowswe 0:0bbf2f16da9c 473 #define RFMPROTO_IS_PACKETTYPE_SPECIAL(FLAGS) ( RFMPROTO_FLAGS_PACKETTYPE_SPECIAL == ((FLAGS) & RFMPROTO_FLAGS_BITASK_PACKETTYPE) )
madcowswe 0:0bbf2f16da9c 474 #define RFMPROTO_IS_DEVICETYPE_OPENHR20(FLAGS) ( RFMPROTO_FLAGS_DEVICETYPE_OPENHR20 == ((FLAGS) & RFMPROTO_FLAGS_BITASK_DEVICETYPE) )
madcowswe 0:0bbf2f16da9c 475
madcowswe 0:0bbf2f16da9c 476 ///////////////////////////////////////////////////////////////////////////////
madcowswe 0:0bbf2f16da9c 477
madcowswe 0:0bbf2f16da9c 478 #endif