V148
Fork of RadioHead-148 by
RH_RF22.h@0:ab4e012489ef, 2015-10-15 (annotated)
- Committer:
- davidr99
- Date:
- Thu Oct 15 01:27:00 2015 +0000
- Revision:
- 0:ab4e012489ef
Messy start, but a port for RadioHead.; Currently the SPI modulus are the only ones that work.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davidr99 | 0:ab4e012489ef | 1 | // RH_RF22.h |
davidr99 | 0:ab4e012489ef | 2 | // Author: Mike McCauley (mikem@airspayce.com) |
davidr99 | 0:ab4e012489ef | 3 | // Copyright (C) 2011 Mike McCauley |
davidr99 | 0:ab4e012489ef | 4 | // $Id: RH_RF22.h,v 1.27 2015/05/17 00:11:26 mikem Exp $ |
davidr99 | 0:ab4e012489ef | 5 | // |
davidr99 | 0:ab4e012489ef | 6 | |
davidr99 | 0:ab4e012489ef | 7 | #ifndef RH_RF22_h |
davidr99 | 0:ab4e012489ef | 8 | #define RH_RF22_h |
davidr99 | 0:ab4e012489ef | 9 | |
davidr99 | 0:ab4e012489ef | 10 | #include <RHGenericSPI.h> |
davidr99 | 0:ab4e012489ef | 11 | #include <RHSPIDriver.h> |
davidr99 | 0:ab4e012489ef | 12 | |
davidr99 | 0:ab4e012489ef | 13 | // This is the maximum number of interrupts the library can support |
davidr99 | 0:ab4e012489ef | 14 | // Most Arduinos can handle 2, Megas can handle more |
davidr99 | 0:ab4e012489ef | 15 | #define RH_RF22_NUM_INTERRUPTS 3 |
davidr99 | 0:ab4e012489ef | 16 | |
davidr99 | 0:ab4e012489ef | 17 | // This is the bit in the SPI address that marks it as a write |
davidr99 | 0:ab4e012489ef | 18 | #define RH_RF22_SPI_WRITE_MASK 0x80 |
davidr99 | 0:ab4e012489ef | 19 | |
davidr99 | 0:ab4e012489ef | 20 | // This is the maximum message length that can be supported by this library. Limited by |
davidr99 | 0:ab4e012489ef | 21 | // the single message length octet in the header. |
davidr99 | 0:ab4e012489ef | 22 | // Yes, 255 is correct even though the FIFO size in the RF22 is only |
davidr99 | 0:ab4e012489ef | 23 | // 64 octets. We use interrupts to refill the Tx FIFO during transmission and to empty the |
davidr99 | 0:ab4e012489ef | 24 | // Rx FIFO during reception |
davidr99 | 0:ab4e012489ef | 25 | // Can be pre-defined to a smaller size (to save SRAM) prior to including this header |
davidr99 | 0:ab4e012489ef | 26 | #ifndef RH_RF22_MAX_MESSAGE_LEN |
davidr99 | 0:ab4e012489ef | 27 | //#define RH_RF22_MAX_MESSAGE_LEN 255 |
davidr99 | 0:ab4e012489ef | 28 | #define RH_RF22_MAX_MESSAGE_LEN 50 |
davidr99 | 0:ab4e012489ef | 29 | #endif |
davidr99 | 0:ab4e012489ef | 30 | |
davidr99 | 0:ab4e012489ef | 31 | // Max number of octets the RF22 Rx and Tx FIFOs can hold |
davidr99 | 0:ab4e012489ef | 32 | #define RH_RF22_FIFO_SIZE 64 |
davidr99 | 0:ab4e012489ef | 33 | |
davidr99 | 0:ab4e012489ef | 34 | // These values we set for FIFO thresholds (4, 55) are actually the same as the POR values |
davidr99 | 0:ab4e012489ef | 35 | #define RH_RF22_TXFFAEM_THRESHOLD 4 |
davidr99 | 0:ab4e012489ef | 36 | #define RH_RF22_RXFFAFULL_THRESHOLD 55 |
davidr99 | 0:ab4e012489ef | 37 | |
davidr99 | 0:ab4e012489ef | 38 | // Number of registers to be passed to setModemConfig(). Obsolete. |
davidr99 | 0:ab4e012489ef | 39 | #define RH_RF22_NUM_MODEM_CONFIG_REGS 18 |
davidr99 | 0:ab4e012489ef | 40 | |
davidr99 | 0:ab4e012489ef | 41 | // Register names |
davidr99 | 0:ab4e012489ef | 42 | #define RH_RF22_REG_00_DEVICE_TYPE 0x00 |
davidr99 | 0:ab4e012489ef | 43 | #define RH_RF22_REG_01_VERSION_CODE 0x01 |
davidr99 | 0:ab4e012489ef | 44 | #define RH_RF22_REG_02_DEVICE_STATUS 0x02 |
davidr99 | 0:ab4e012489ef | 45 | #define RH_RF22_REG_03_INTERRUPT_STATUS1 0x03 |
davidr99 | 0:ab4e012489ef | 46 | #define RH_RF22_REG_04_INTERRUPT_STATUS2 0x04 |
davidr99 | 0:ab4e012489ef | 47 | #define RH_RF22_REG_05_INTERRUPT_ENABLE1 0x05 |
davidr99 | 0:ab4e012489ef | 48 | #define RH_RF22_REG_06_INTERRUPT_ENABLE2 0x06 |
davidr99 | 0:ab4e012489ef | 49 | #define RH_RF22_REG_07_OPERATING_MODE1 0x07 |
davidr99 | 0:ab4e012489ef | 50 | #define RH_RF22_REG_08_OPERATING_MODE2 0x08 |
davidr99 | 0:ab4e012489ef | 51 | #define RH_RF22_REG_09_OSCILLATOR_LOAD_CAPACITANCE 0x09 |
davidr99 | 0:ab4e012489ef | 52 | #define RH_RF22_REG_0A_UC_OUTPUT_CLOCK 0x0a |
davidr99 | 0:ab4e012489ef | 53 | #define RH_RF22_REG_0B_GPIO_CONFIGURATION0 0x0b |
davidr99 | 0:ab4e012489ef | 54 | #define RH_RF22_REG_0C_GPIO_CONFIGURATION1 0x0c |
davidr99 | 0:ab4e012489ef | 55 | #define RH_RF22_REG_0D_GPIO_CONFIGURATION2 0x0d |
davidr99 | 0:ab4e012489ef | 56 | #define RH_RF22_REG_0E_IO_PORT_CONFIGURATION 0x0e |
davidr99 | 0:ab4e012489ef | 57 | #define RH_RF22_REG_0F_ADC_CONFIGURATION 0x0f |
davidr99 | 0:ab4e012489ef | 58 | #define RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10 |
davidr99 | 0:ab4e012489ef | 59 | #define RH_RF22_REG_11_ADC_VALUE 0x11 |
davidr99 | 0:ab4e012489ef | 60 | #define RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12 |
davidr99 | 0:ab4e012489ef | 61 | #define RH_RF22_REG_13_TEMPERATURE_VALUE_OFFSET 0x13 |
davidr99 | 0:ab4e012489ef | 62 | #define RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14 |
davidr99 | 0:ab4e012489ef | 63 | #define RH_RF22_REG_15_WAKEUP_TIMER_PERIOD2 0x15 |
davidr99 | 0:ab4e012489ef | 64 | #define RH_RF22_REG_16_WAKEUP_TIMER_PERIOD3 0x16 |
davidr99 | 0:ab4e012489ef | 65 | #define RH_RF22_REG_17_WAKEUP_TIMER_VALUE1 0x17 |
davidr99 | 0:ab4e012489ef | 66 | #define RH_RF22_REG_18_WAKEUP_TIMER_VALUE2 0x18 |
davidr99 | 0:ab4e012489ef | 67 | #define RH_RF22_REG_19_LDC_MODE_DURATION 0x19 |
davidr99 | 0:ab4e012489ef | 68 | #define RH_RF22_REG_1A_LOW_BATTERY_DETECTOR_THRESHOLD 0x1a |
davidr99 | 0:ab4e012489ef | 69 | #define RH_RF22_REG_1B_BATTERY_VOLTAGE_LEVEL 0x1b |
davidr99 | 0:ab4e012489ef | 70 | #define RH_RF22_REG_1C_IF_FILTER_BANDWIDTH 0x1c |
davidr99 | 0:ab4e012489ef | 71 | #define RH_RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d |
davidr99 | 0:ab4e012489ef | 72 | #define RH_RF22_REG_1E_AFC_TIMING_CONTROL 0x1e |
davidr99 | 0:ab4e012489ef | 73 | #define RH_RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE 0x1f |
davidr99 | 0:ab4e012489ef | 74 | #define RH_RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE 0x20 |
davidr99 | 0:ab4e012489ef | 75 | #define RH_RF22_REG_21_CLOCK_RECOVERY_OFFSET2 0x21 |
davidr99 | 0:ab4e012489ef | 76 | #define RH_RF22_REG_22_CLOCK_RECOVERY_OFFSET1 0x22 |
davidr99 | 0:ab4e012489ef | 77 | #define RH_RF22_REG_23_CLOCK_RECOVERY_OFFSET0 0x23 |
davidr99 | 0:ab4e012489ef | 78 | #define RH_RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1 0x24 |
davidr99 | 0:ab4e012489ef | 79 | #define RH_RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0 0x25 |
davidr99 | 0:ab4e012489ef | 80 | #define RH_RF22_REG_26_RSSI 0x26 |
davidr99 | 0:ab4e012489ef | 81 | #define RH_RF22_REG_27_RSSI_THRESHOLD 0x27 |
davidr99 | 0:ab4e012489ef | 82 | #define RH_RF22_REG_28_ANTENNA_DIVERSITY1 0x28 |
davidr99 | 0:ab4e012489ef | 83 | #define RH_RF22_REG_29_ANTENNA_DIVERSITY2 0x29 |
davidr99 | 0:ab4e012489ef | 84 | #define RH_RF22_REG_2A_AFC_LIMITER 0x2a |
davidr99 | 0:ab4e012489ef | 85 | #define RH_RF22_REG_2B_AFC_CORRECTION_READ 0x2b |
davidr99 | 0:ab4e012489ef | 86 | #define RH_RF22_REG_2C_OOK_COUNTER_VALUE_1 0x2c |
davidr99 | 0:ab4e012489ef | 87 | #define RH_RF22_REG_2D_OOK_COUNTER_VALUE_2 0x2d |
davidr99 | 0:ab4e012489ef | 88 | #define RH_RF22_REG_2E_SLICER_PEAK_HOLD 0x2e |
davidr99 | 0:ab4e012489ef | 89 | #define RH_RF22_REG_30_DATA_ACCESS_CONTROL 0x30 |
davidr99 | 0:ab4e012489ef | 90 | #define RH_RF22_REG_31_EZMAC_STATUS 0x31 |
davidr99 | 0:ab4e012489ef | 91 | #define RH_RF22_REG_32_HEADER_CONTROL1 0x32 |
davidr99 | 0:ab4e012489ef | 92 | #define RH_RF22_REG_33_HEADER_CONTROL2 0x33 |
davidr99 | 0:ab4e012489ef | 93 | #define RH_RF22_REG_34_PREAMBLE_LENGTH 0x34 |
davidr99 | 0:ab4e012489ef | 94 | #define RH_RF22_REG_35_PREAMBLE_DETECTION_CONTROL1 0x35 |
davidr99 | 0:ab4e012489ef | 95 | #define RH_RF22_REG_36_SYNC_WORD3 0x36 |
davidr99 | 0:ab4e012489ef | 96 | #define RH_RF22_REG_37_SYNC_WORD2 0x37 |
davidr99 | 0:ab4e012489ef | 97 | #define RH_RF22_REG_38_SYNC_WORD1 0x38 |
davidr99 | 0:ab4e012489ef | 98 | #define RH_RF22_REG_39_SYNC_WORD0 0x39 |
davidr99 | 0:ab4e012489ef | 99 | #define RH_RF22_REG_3A_TRANSMIT_HEADER3 0x3a |
davidr99 | 0:ab4e012489ef | 100 | #define RH_RF22_REG_3B_TRANSMIT_HEADER2 0x3b |
davidr99 | 0:ab4e012489ef | 101 | #define RH_RF22_REG_3C_TRANSMIT_HEADER1 0x3c |
davidr99 | 0:ab4e012489ef | 102 | #define RH_RF22_REG_3D_TRANSMIT_HEADER0 0x3d |
davidr99 | 0:ab4e012489ef | 103 | #define RH_RF22_REG_3E_PACKET_LENGTH 0x3e |
davidr99 | 0:ab4e012489ef | 104 | #define RH_RF22_REG_3F_CHECK_HEADER3 0x3f |
davidr99 | 0:ab4e012489ef | 105 | #define RH_RF22_REG_40_CHECK_HEADER2 0x40 |
davidr99 | 0:ab4e012489ef | 106 | #define RH_RF22_REG_41_CHECK_HEADER1 0x41 |
davidr99 | 0:ab4e012489ef | 107 | #define RH_RF22_REG_42_CHECK_HEADER0 0x42 |
davidr99 | 0:ab4e012489ef | 108 | #define RH_RF22_REG_43_HEADER_ENABLE3 0x43 |
davidr99 | 0:ab4e012489ef | 109 | #define RH_RF22_REG_44_HEADER_ENABLE2 0x44 |
davidr99 | 0:ab4e012489ef | 110 | #define RH_RF22_REG_45_HEADER_ENABLE1 0x45 |
davidr99 | 0:ab4e012489ef | 111 | #define RH_RF22_REG_46_HEADER_ENABLE0 0x46 |
davidr99 | 0:ab4e012489ef | 112 | #define RH_RF22_REG_47_RECEIVED_HEADER3 0x47 |
davidr99 | 0:ab4e012489ef | 113 | #define RH_RF22_REG_48_RECEIVED_HEADER2 0x48 |
davidr99 | 0:ab4e012489ef | 114 | #define RH_RF22_REG_49_RECEIVED_HEADER1 0x49 |
davidr99 | 0:ab4e012489ef | 115 | #define RH_RF22_REG_4A_RECEIVED_HEADER0 0x4a |
davidr99 | 0:ab4e012489ef | 116 | #define RH_RF22_REG_4B_RECEIVED_PACKET_LENGTH 0x4b |
davidr99 | 0:ab4e012489ef | 117 | #define RH_RF22_REG_50_ANALOG_TEST_BUS_SELECT 0x50 |
davidr99 | 0:ab4e012489ef | 118 | #define RH_RF22_REG_51_DIGITAL_TEST_BUS_SELECT 0x51 |
davidr99 | 0:ab4e012489ef | 119 | #define RH_RF22_REG_52_TX_RAMP_CONTROL 0x52 |
davidr99 | 0:ab4e012489ef | 120 | #define RH_RF22_REG_53_PLL_TUNE_TIME 0x53 |
davidr99 | 0:ab4e012489ef | 121 | #define RH_RF22_REG_55_CALIBRATION_CONTROL 0x55 |
davidr99 | 0:ab4e012489ef | 122 | #define RH_RF22_REG_56_MODEM_TEST 0x56 |
davidr99 | 0:ab4e012489ef | 123 | #define RH_RF22_REG_57_CHARGE_PUMP_TEST 0x57 |
davidr99 | 0:ab4e012489ef | 124 | #define RH_RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING 0x58 |
davidr99 | 0:ab4e012489ef | 125 | #define RH_RF22_REG_59_DIVIDER_CURRENT_TRIMMING 0x59 |
davidr99 | 0:ab4e012489ef | 126 | #define RH_RF22_REG_5A_VCO_CURRENT_TRIMMING 0x5a |
davidr99 | 0:ab4e012489ef | 127 | #define RH_RF22_REG_5B_VCO_CALIBRATION 0x5b |
davidr99 | 0:ab4e012489ef | 128 | #define RH_RF22_REG_5C_SYNTHESIZER_TEST 0x5c |
davidr99 | 0:ab4e012489ef | 129 | #define RH_RF22_REG_5D_BLOCK_ENABLE_OVERRIDE1 0x5d |
davidr99 | 0:ab4e012489ef | 130 | #define RH_RF22_REG_5E_BLOCK_ENABLE_OVERRIDE2 0x5e |
davidr99 | 0:ab4e012489ef | 131 | #define RH_RF22_REG_5F_BLOCK_ENABLE_OVERRIDE3 0x5f |
davidr99 | 0:ab4e012489ef | 132 | #define RH_RF22_REG_60_CHANNEL_FILTER_COEFFICIENT_ADDRESS 0x60 |
davidr99 | 0:ab4e012489ef | 133 | #define RH_RF22_REG_61_CHANNEL_FILTER_COEFFICIENT_VALUE 0x61 |
davidr99 | 0:ab4e012489ef | 134 | #define RH_RF22_REG_62_CRYSTAL_OSCILLATOR_POR_CONTROL 0x62 |
davidr99 | 0:ab4e012489ef | 135 | #define RH_RF22_REG_63_RC_OSCILLATOR_COARSE_CALIBRATION 0x63 |
davidr99 | 0:ab4e012489ef | 136 | #define RH_RF22_REG_64_RC_OSCILLATOR_FINE_CALIBRATION 0x64 |
davidr99 | 0:ab4e012489ef | 137 | #define RH_RF22_REG_65_LDO_CONTROL_OVERRIDE 0x65 |
davidr99 | 0:ab4e012489ef | 138 | #define RH_RF22_REG_66_LDO_LEVEL_SETTINGS 0x66 |
davidr99 | 0:ab4e012489ef | 139 | #define RH_RF22_REG_67_DELTA_SIGMA_ADC_TUNING1 0x67 |
davidr99 | 0:ab4e012489ef | 140 | #define RH_RF22_REG_68_DELTA_SIGMA_ADC_TUNING2 0x68 |
davidr99 | 0:ab4e012489ef | 141 | #define RH_RF22_REG_69_AGC_OVERRIDE1 0x69 |
davidr99 | 0:ab4e012489ef | 142 | #define RH_RF22_REG_6A_AGC_OVERRIDE2 0x6a |
davidr99 | 0:ab4e012489ef | 143 | #define RH_RF22_REG_6B_GFSK_FIR_FILTER_COEFFICIENT_ADDRESS 0x6b |
davidr99 | 0:ab4e012489ef | 144 | #define RH_RF22_REG_6C_GFSK_FIR_FILTER_COEFFICIENT_VALUE 0x6c |
davidr99 | 0:ab4e012489ef | 145 | #define RH_RF22_REG_6D_TX_POWER 0x6d |
davidr99 | 0:ab4e012489ef | 146 | #define RH_RF22_REG_6E_TX_DATA_RATE1 0x6e |
davidr99 | 0:ab4e012489ef | 147 | #define RH_RF22_REG_6F_TX_DATA_RATE0 0x6f |
davidr99 | 0:ab4e012489ef | 148 | #define RH_RF22_REG_70_MODULATION_CONTROL1 0x70 |
davidr99 | 0:ab4e012489ef | 149 | #define RH_RF22_REG_71_MODULATION_CONTROL2 0x71 |
davidr99 | 0:ab4e012489ef | 150 | #define RH_RF22_REG_72_FREQUENCY_DEVIATION 0x72 |
davidr99 | 0:ab4e012489ef | 151 | #define RH_RF22_REG_73_FREQUENCY_OFFSET1 0x73 |
davidr99 | 0:ab4e012489ef | 152 | #define RH_RF22_REG_74_FREQUENCY_OFFSET2 0x74 |
davidr99 | 0:ab4e012489ef | 153 | #define RH_RF22_REG_75_FREQUENCY_BAND_SELECT 0x75 |
davidr99 | 0:ab4e012489ef | 154 | #define RH_RF22_REG_76_NOMINAL_CARRIER_FREQUENCY1 0x76 |
davidr99 | 0:ab4e012489ef | 155 | #define RH_RF22_REG_77_NOMINAL_CARRIER_FREQUENCY0 0x77 |
davidr99 | 0:ab4e012489ef | 156 | #define RH_RF22_REG_79_FREQUENCY_HOPPING_CHANNEL_SELECT 0x79 |
davidr99 | 0:ab4e012489ef | 157 | #define RH_RF22_REG_7A_FREQUENCY_HOPPING_STEP_SIZE 0x7a |
davidr99 | 0:ab4e012489ef | 158 | #define RH_RF22_REG_7C_TX_FIFO_CONTROL1 0x7c |
davidr99 | 0:ab4e012489ef | 159 | #define RH_RF22_REG_7D_TX_FIFO_CONTROL2 0x7d |
davidr99 | 0:ab4e012489ef | 160 | #define RH_RF22_REG_7E_RX_FIFO_CONTROL 0x7e |
davidr99 | 0:ab4e012489ef | 161 | #define RH_RF22_REG_7F_FIFO_ACCESS 0x7f |
davidr99 | 0:ab4e012489ef | 162 | |
davidr99 | 0:ab4e012489ef | 163 | // These register masks etc are named wherever possible |
davidr99 | 0:ab4e012489ef | 164 | // corresponding to the bit and field names in the RF-22 Manual |
davidr99 | 0:ab4e012489ef | 165 | // RH_RF22_REG_00_DEVICE_TYPE 0x00 |
davidr99 | 0:ab4e012489ef | 166 | #define RH_RF22_DEVICE_TYPE_RX_TRX 0x08 |
davidr99 | 0:ab4e012489ef | 167 | #define RH_RF22_DEVICE_TYPE_TX 0x07 |
davidr99 | 0:ab4e012489ef | 168 | |
davidr99 | 0:ab4e012489ef | 169 | // RH_RF22_REG_02_DEVICE_STATUS 0x02 |
davidr99 | 0:ab4e012489ef | 170 | #define RH_RF22_FFOVL 0x80 |
davidr99 | 0:ab4e012489ef | 171 | #define RH_RF22_FFUNFL 0x40 |
davidr99 | 0:ab4e012489ef | 172 | #define RH_RF22_RXFFEM 0x20 |
davidr99 | 0:ab4e012489ef | 173 | #define RH_RF22_HEADERR 0x10 |
davidr99 | 0:ab4e012489ef | 174 | #define RH_RF22_FREQERR 0x08 |
davidr99 | 0:ab4e012489ef | 175 | #define RH_RF22_LOCKDET 0x04 |
davidr99 | 0:ab4e012489ef | 176 | #define RH_RF22_CPS 0x03 |
davidr99 | 0:ab4e012489ef | 177 | #define RH_RF22_CPS_IDLE 0x00 |
davidr99 | 0:ab4e012489ef | 178 | #define RH_RF22_CPS_RX 0x01 |
davidr99 | 0:ab4e012489ef | 179 | #define RH_RF22_CPS_TX 0x10 |
davidr99 | 0:ab4e012489ef | 180 | |
davidr99 | 0:ab4e012489ef | 181 | // RH_RF22_REG_03_INTERRUPT_STATUS1 0x03 |
davidr99 | 0:ab4e012489ef | 182 | #define RH_RF22_IFFERROR 0x80 |
davidr99 | 0:ab4e012489ef | 183 | #define RH_RF22_ITXFFAFULL 0x40 |
davidr99 | 0:ab4e012489ef | 184 | #define RH_RF22_ITXFFAEM 0x20 |
davidr99 | 0:ab4e012489ef | 185 | #define RH_RF22_IRXFFAFULL 0x10 |
davidr99 | 0:ab4e012489ef | 186 | #define RH_RF22_IEXT 0x08 |
davidr99 | 0:ab4e012489ef | 187 | #define RH_RF22_IPKSENT 0x04 |
davidr99 | 0:ab4e012489ef | 188 | #define RH_RF22_IPKVALID 0x02 |
davidr99 | 0:ab4e012489ef | 189 | #define RH_RF22_ICRCERROR 0x01 |
davidr99 | 0:ab4e012489ef | 190 | |
davidr99 | 0:ab4e012489ef | 191 | // RH_RF22_REG_04_INTERRUPT_STATUS2 0x04 |
davidr99 | 0:ab4e012489ef | 192 | #define RH_RF22_ISWDET 0x80 |
davidr99 | 0:ab4e012489ef | 193 | #define RH_RF22_IPREAVAL 0x40 |
davidr99 | 0:ab4e012489ef | 194 | #define RH_RF22_IPREAINVAL 0x20 |
davidr99 | 0:ab4e012489ef | 195 | #define RH_RF22_IRSSI 0x10 |
davidr99 | 0:ab4e012489ef | 196 | #define RH_RF22_IWUT 0x08 |
davidr99 | 0:ab4e012489ef | 197 | #define RH_RF22_ILBD 0x04 |
davidr99 | 0:ab4e012489ef | 198 | #define RH_RF22_ICHIPRDY 0x02 |
davidr99 | 0:ab4e012489ef | 199 | #define RH_RF22_IPOR 0x01 |
davidr99 | 0:ab4e012489ef | 200 | |
davidr99 | 0:ab4e012489ef | 201 | // RH_RF22_REG_05_INTERRUPT_ENABLE1 0x05 |
davidr99 | 0:ab4e012489ef | 202 | #define RH_RF22_ENFFERR 0x80 |
davidr99 | 0:ab4e012489ef | 203 | #define RH_RF22_ENTXFFAFULL 0x40 |
davidr99 | 0:ab4e012489ef | 204 | #define RH_RF22_ENTXFFAEM 0x20 |
davidr99 | 0:ab4e012489ef | 205 | #define RH_RF22_ENRXFFAFULL 0x10 |
davidr99 | 0:ab4e012489ef | 206 | #define RH_RF22_ENEXT 0x08 |
davidr99 | 0:ab4e012489ef | 207 | #define RH_RF22_ENPKSENT 0x04 |
davidr99 | 0:ab4e012489ef | 208 | #define RH_RF22_ENPKVALID 0x02 |
davidr99 | 0:ab4e012489ef | 209 | #define RH_RF22_ENCRCERROR 0x01 |
davidr99 | 0:ab4e012489ef | 210 | |
davidr99 | 0:ab4e012489ef | 211 | // RH_RF22_REG_06_INTERRUPT_ENABLE2 0x06 |
davidr99 | 0:ab4e012489ef | 212 | #define RH_RF22_ENSWDET 0x80 |
davidr99 | 0:ab4e012489ef | 213 | #define RH_RF22_ENPREAVAL 0x40 |
davidr99 | 0:ab4e012489ef | 214 | #define RH_RF22_ENPREAINVAL 0x20 |
davidr99 | 0:ab4e012489ef | 215 | #define RH_RF22_ENRSSI 0x10 |
davidr99 | 0:ab4e012489ef | 216 | #define RH_RF22_ENWUT 0x08 |
davidr99 | 0:ab4e012489ef | 217 | #define RH_RF22_ENLBDI 0x04 |
davidr99 | 0:ab4e012489ef | 218 | #define RH_RF22_ENCHIPRDY 0x02 |
davidr99 | 0:ab4e012489ef | 219 | #define RH_RF22_ENPOR 0x01 |
davidr99 | 0:ab4e012489ef | 220 | |
davidr99 | 0:ab4e012489ef | 221 | // RH_RF22_REG_07_OPERATING_MODE 0x07 |
davidr99 | 0:ab4e012489ef | 222 | #define RH_RF22_SWRES 0x80 |
davidr99 | 0:ab4e012489ef | 223 | #define RH_RF22_ENLBD 0x40 |
davidr99 | 0:ab4e012489ef | 224 | #define RH_RF22_ENWT 0x20 |
davidr99 | 0:ab4e012489ef | 225 | #define RH_RF22_X32KSEL 0x10 |
davidr99 | 0:ab4e012489ef | 226 | #define RH_RF22_TXON 0x08 |
davidr99 | 0:ab4e012489ef | 227 | #define RH_RF22_RXON 0x04 |
davidr99 | 0:ab4e012489ef | 228 | #define RH_RF22_PLLON 0x02 |
davidr99 | 0:ab4e012489ef | 229 | #define RH_RF22_XTON 0x01 |
davidr99 | 0:ab4e012489ef | 230 | |
davidr99 | 0:ab4e012489ef | 231 | // RH_RF22_REG_08_OPERATING_MODE2 0x08 |
davidr99 | 0:ab4e012489ef | 232 | #define RH_RF22_ANTDIV 0xc0 |
davidr99 | 0:ab4e012489ef | 233 | #define RH_RF22_RXMPK 0x10 |
davidr99 | 0:ab4e012489ef | 234 | #define RH_RF22_AUTOTX 0x08 |
davidr99 | 0:ab4e012489ef | 235 | #define RH_RF22_ENLDM 0x04 |
davidr99 | 0:ab4e012489ef | 236 | #define RH_RF22_FFCLRRX 0x02 |
davidr99 | 0:ab4e012489ef | 237 | #define RH_RF22_FFCLRTX 0x01 |
davidr99 | 0:ab4e012489ef | 238 | |
davidr99 | 0:ab4e012489ef | 239 | // RH_RF22_REG_0F_ADC_CONFIGURATION 0x0f |
davidr99 | 0:ab4e012489ef | 240 | #define RH_RF22_ADCSTART 0x80 |
davidr99 | 0:ab4e012489ef | 241 | #define RH_RF22_ADCDONE 0x80 |
davidr99 | 0:ab4e012489ef | 242 | #define RH_RF22_ADCSEL 0x70 |
davidr99 | 0:ab4e012489ef | 243 | #define RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR 0x00 |
davidr99 | 0:ab4e012489ef | 244 | #define RH_RF22_ADCSEL_GPIO0_SINGLE_ENDED 0x10 |
davidr99 | 0:ab4e012489ef | 245 | #define RH_RF22_ADCSEL_GPIO1_SINGLE_ENDED 0x20 |
davidr99 | 0:ab4e012489ef | 246 | #define RH_RF22_ADCSEL_GPIO2_SINGLE_ENDED 0x30 |
davidr99 | 0:ab4e012489ef | 247 | #define RH_RF22_ADCSEL_GPIO0_GPIO1_DIFFERENTIAL 0x40 |
davidr99 | 0:ab4e012489ef | 248 | #define RH_RF22_ADCSEL_GPIO1_GPIO2_DIFFERENTIAL 0x50 |
davidr99 | 0:ab4e012489ef | 249 | #define RH_RF22_ADCSEL_GPIO0_GPIO2_DIFFERENTIAL 0x60 |
davidr99 | 0:ab4e012489ef | 250 | #define RH_RF22_ADCSEL_GND 0x70 |
davidr99 | 0:ab4e012489ef | 251 | #define RH_RF22_ADCREF 0x0c |
davidr99 | 0:ab4e012489ef | 252 | #define RH_RF22_ADCREF_BANDGAP_VOLTAGE 0x00 |
davidr99 | 0:ab4e012489ef | 253 | #define RH_RF22_ADCREF_VDD_ON_3 0x08 |
davidr99 | 0:ab4e012489ef | 254 | #define RH_RF22_ADCREF_VDD_ON_2 0x0c |
davidr99 | 0:ab4e012489ef | 255 | #define RH_RF22_ADCGAIN 0x03 |
davidr99 | 0:ab4e012489ef | 256 | |
davidr99 | 0:ab4e012489ef | 257 | // RH_RF22_REG_10_ADC_SENSOR_AMP_OFFSET 0x10 |
davidr99 | 0:ab4e012489ef | 258 | #define RH_RF22_ADCOFFS 0x0f |
davidr99 | 0:ab4e012489ef | 259 | |
davidr99 | 0:ab4e012489ef | 260 | // RH_RF22_REG_12_TEMPERATURE_SENSOR_CALIBRATION 0x12 |
davidr99 | 0:ab4e012489ef | 261 | #define RH_RF22_TSRANGE 0xc0 |
davidr99 | 0:ab4e012489ef | 262 | #define RH_RF22_TSRANGE_M64_64C 0x00 |
davidr99 | 0:ab4e012489ef | 263 | #define RH_RF22_TSRANGE_M64_192C 0x40 |
davidr99 | 0:ab4e012489ef | 264 | #define RH_RF22_TSRANGE_0_128C 0x80 |
davidr99 | 0:ab4e012489ef | 265 | #define RH_RF22_TSRANGE_M40_216F 0xc0 |
davidr99 | 0:ab4e012489ef | 266 | #define RH_RF22_ENTSOFFS 0x20 |
davidr99 | 0:ab4e012489ef | 267 | #define RH_RF22_ENTSTRIM 0x10 |
davidr99 | 0:ab4e012489ef | 268 | #define RH_RF22_TSTRIM 0x0f |
davidr99 | 0:ab4e012489ef | 269 | |
davidr99 | 0:ab4e012489ef | 270 | // RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1 0x14 |
davidr99 | 0:ab4e012489ef | 271 | #define RH_RF22_WTR 0x3c |
davidr99 | 0:ab4e012489ef | 272 | #define RH_RF22_WTD 0x03 |
davidr99 | 0:ab4e012489ef | 273 | |
davidr99 | 0:ab4e012489ef | 274 | // RH_RF22_REG_1D_AFC_LOOP_GEARSHIFT_OVERRIDE 0x1d |
davidr99 | 0:ab4e012489ef | 275 | #define RH_RF22_AFBCD 0x80 |
davidr99 | 0:ab4e012489ef | 276 | #define RH_RF22_ENAFC 0x40 |
davidr99 | 0:ab4e012489ef | 277 | #define RH_RF22_AFCGEARH 0x38 |
davidr99 | 0:ab4e012489ef | 278 | #define RH_RF22_AFCGEARL 0x07 |
davidr99 | 0:ab4e012489ef | 279 | |
davidr99 | 0:ab4e012489ef | 280 | // RH_RF22_REG_1E_AFC_TIMING_CONTROL 0x1e |
davidr99 | 0:ab4e012489ef | 281 | #define RH_RF22_SWAIT_TIMER 0xc0 |
davidr99 | 0:ab4e012489ef | 282 | #define RH_RF22_SHWAIT 0x38 |
davidr99 | 0:ab4e012489ef | 283 | #define RH_RF22_ANWAIT 0x07 |
davidr99 | 0:ab4e012489ef | 284 | |
davidr99 | 0:ab4e012489ef | 285 | // RH_RF22_REG_30_DATA_ACCESS_CONTROL 0x30 |
davidr99 | 0:ab4e012489ef | 286 | #define RH_RF22_ENPACRX 0x80 |
davidr99 | 0:ab4e012489ef | 287 | #define RH_RF22_MSBFRST 0x00 |
davidr99 | 0:ab4e012489ef | 288 | #define RH_RF22_LSBFRST 0x40 |
davidr99 | 0:ab4e012489ef | 289 | #define RH_RF22_CRCHDRS 0x00 |
davidr99 | 0:ab4e012489ef | 290 | #define RH_RF22_CRCDONLY 0x20 |
davidr99 | 0:ab4e012489ef | 291 | #define RH_RF22_SKIP2PH 0x10 |
davidr99 | 0:ab4e012489ef | 292 | #define RH_RF22_ENPACTX 0x08 |
davidr99 | 0:ab4e012489ef | 293 | #define RH_RF22_ENCRC 0x04 |
davidr99 | 0:ab4e012489ef | 294 | #define RH_RF22_CRC 0x03 |
davidr99 | 0:ab4e012489ef | 295 | #define RH_RF22_CRC_CCITT 0x00 |
davidr99 | 0:ab4e012489ef | 296 | #define RH_RF22_CRC_CRC_16_IBM 0x01 |
davidr99 | 0:ab4e012489ef | 297 | #define RH_RF22_CRC_IEC_16 0x02 |
davidr99 | 0:ab4e012489ef | 298 | #define RH_RF22_CRC_BIACHEVA 0x03 |
davidr99 | 0:ab4e012489ef | 299 | |
davidr99 | 0:ab4e012489ef | 300 | // RH_RF22_REG_32_HEADER_CONTROL1 0x32 |
davidr99 | 0:ab4e012489ef | 301 | #define RH_RF22_BCEN 0xf0 |
davidr99 | 0:ab4e012489ef | 302 | #define RH_RF22_BCEN_NONE 0x00 |
davidr99 | 0:ab4e012489ef | 303 | #define RH_RF22_BCEN_HEADER0 0x10 |
davidr99 | 0:ab4e012489ef | 304 | #define RH_RF22_BCEN_HEADER1 0x20 |
davidr99 | 0:ab4e012489ef | 305 | #define RH_RF22_BCEN_HEADER2 0x40 |
davidr99 | 0:ab4e012489ef | 306 | #define RH_RF22_BCEN_HEADER3 0x80 |
davidr99 | 0:ab4e012489ef | 307 | #define RH_RF22_HDCH 0x0f |
davidr99 | 0:ab4e012489ef | 308 | #define RH_RF22_HDCH_NONE 0x00 |
davidr99 | 0:ab4e012489ef | 309 | #define RH_RF22_HDCH_HEADER0 0x01 |
davidr99 | 0:ab4e012489ef | 310 | #define RH_RF22_HDCH_HEADER1 0x02 |
davidr99 | 0:ab4e012489ef | 311 | #define RH_RF22_HDCH_HEADER2 0x04 |
davidr99 | 0:ab4e012489ef | 312 | #define RH_RF22_HDCH_HEADER3 0x08 |
davidr99 | 0:ab4e012489ef | 313 | |
davidr99 | 0:ab4e012489ef | 314 | // RH_RF22_REG_33_HEADER_CONTROL2 0x33 |
davidr99 | 0:ab4e012489ef | 315 | #define RH_RF22_HDLEN 0x70 |
davidr99 | 0:ab4e012489ef | 316 | #define RH_RF22_HDLEN_0 0x00 |
davidr99 | 0:ab4e012489ef | 317 | #define RH_RF22_HDLEN_1 0x10 |
davidr99 | 0:ab4e012489ef | 318 | #define RH_RF22_HDLEN_2 0x20 |
davidr99 | 0:ab4e012489ef | 319 | #define RH_RF22_HDLEN_3 0x30 |
davidr99 | 0:ab4e012489ef | 320 | #define RH_RF22_HDLEN_4 0x40 |
davidr99 | 0:ab4e012489ef | 321 | #define RH_RF22_VARPKLEN 0x00 |
davidr99 | 0:ab4e012489ef | 322 | #define RH_RF22_FIXPKLEN 0x08 |
davidr99 | 0:ab4e012489ef | 323 | #define RH_RF22_SYNCLEN 0x06 |
davidr99 | 0:ab4e012489ef | 324 | #define RH_RF22_SYNCLEN_1 0x00 |
davidr99 | 0:ab4e012489ef | 325 | #define RH_RF22_SYNCLEN_2 0x02 |
davidr99 | 0:ab4e012489ef | 326 | #define RH_RF22_SYNCLEN_3 0x04 |
davidr99 | 0:ab4e012489ef | 327 | #define RH_RF22_SYNCLEN_4 0x06 |
davidr99 | 0:ab4e012489ef | 328 | #define RH_RF22_PREALEN8 0x01 |
davidr99 | 0:ab4e012489ef | 329 | |
davidr99 | 0:ab4e012489ef | 330 | // RH_RF22_REG_6D_TX_POWER 0x6d |
davidr99 | 0:ab4e012489ef | 331 | // https://www.sparkfun.com/datasheets/Wireless/General/RFM22B.pdf |
davidr99 | 0:ab4e012489ef | 332 | #define RH_RF22_PAPEAKVAL 0x80 |
davidr99 | 0:ab4e012489ef | 333 | #define RH_RF22_PAPEAKEN 0x40 |
davidr99 | 0:ab4e012489ef | 334 | #define RH_RF22_PAPEAKLVL 0x30 |
davidr99 | 0:ab4e012489ef | 335 | #define RH_RF22_PAPEAKLVL6_5 0x00 |
davidr99 | 0:ab4e012489ef | 336 | #define RH_RF22_PAPEAKLVL7 0x10 |
davidr99 | 0:ab4e012489ef | 337 | #define RH_RF22_PAPEAKLVL7_5 0x20 |
davidr99 | 0:ab4e012489ef | 338 | #define RH_RF22_PAPEAKLVL8 0x30 |
davidr99 | 0:ab4e012489ef | 339 | #define RH_RF22_LNA_SW 0x08 |
davidr99 | 0:ab4e012489ef | 340 | #define RH_RF22_TXPOW 0x07 |
davidr99 | 0:ab4e012489ef | 341 | #define RH_RF22_TXPOW_4X31 0x08 // Not used in RFM22B |
davidr99 | 0:ab4e012489ef | 342 | // For RFM22B: |
davidr99 | 0:ab4e012489ef | 343 | #define RH_RF22_TXPOW_1DBM 0x00 |
davidr99 | 0:ab4e012489ef | 344 | #define RH_RF22_TXPOW_2DBM 0x01 |
davidr99 | 0:ab4e012489ef | 345 | #define RH_RF22_TXPOW_5DBM 0x02 |
davidr99 | 0:ab4e012489ef | 346 | #define RH_RF22_TXPOW_8DBM 0x03 |
davidr99 | 0:ab4e012489ef | 347 | #define RH_RF22_TXPOW_11DBM 0x04 |
davidr99 | 0:ab4e012489ef | 348 | #define RH_RF22_TXPOW_14DBM 0x05 |
davidr99 | 0:ab4e012489ef | 349 | #define RH_RF22_TXPOW_17DBM 0x06 |
davidr99 | 0:ab4e012489ef | 350 | #define RH_RF22_TXPOW_20DBM 0x07 |
davidr99 | 0:ab4e012489ef | 351 | // RFM23B only: |
davidr99 | 0:ab4e012489ef | 352 | #define RH_RF22_RF23B_TXPOW_M8DBM 0x00 // -8dBm |
davidr99 | 0:ab4e012489ef | 353 | #define RH_RF22_RF23B_TXPOW_M5DBM 0x01 // -5dBm |
davidr99 | 0:ab4e012489ef | 354 | #define RH_RF22_RF23B_TXPOW_M2DBM 0x02 // -2dBm |
davidr99 | 0:ab4e012489ef | 355 | #define RH_RF22_RF23B_TXPOW_1DBM 0x03 // 1dBm |
davidr99 | 0:ab4e012489ef | 356 | #define RH_RF22_RF23B_TXPOW_4DBM 0x04 // 4dBm |
davidr99 | 0:ab4e012489ef | 357 | #define RH_RF22_RF23B_TXPOW_7DBM 0x05 // 7dBm |
davidr99 | 0:ab4e012489ef | 358 | #define RH_RF22_RF23B_TXPOW_10DBM 0x06 // 10dBm |
davidr99 | 0:ab4e012489ef | 359 | #define RH_RF22_RF23B_TXPOW_13DBM 0x07 // 13dBm |
davidr99 | 0:ab4e012489ef | 360 | // RFM23BP only: |
davidr99 | 0:ab4e012489ef | 361 | #define RH_RF22_RF23BP_TXPOW_28DBM 0x05 // 28dBm |
davidr99 | 0:ab4e012489ef | 362 | #define RH_RF22_RF23BP_TXPOW_29DBM 0x06 // 29dBm |
davidr99 | 0:ab4e012489ef | 363 | #define RH_RF22_RF23BP_TXPOW_30DBM 0x07 // 30dBm |
davidr99 | 0:ab4e012489ef | 364 | |
davidr99 | 0:ab4e012489ef | 365 | // RH_RF22_REG_71_MODULATION_CONTROL2 0x71 |
davidr99 | 0:ab4e012489ef | 366 | #define RH_RF22_TRCLK 0xc0 |
davidr99 | 0:ab4e012489ef | 367 | #define RH_RF22_TRCLK_NONE 0x00 |
davidr99 | 0:ab4e012489ef | 368 | #define RH_RF22_TRCLK_GPIO 0x40 |
davidr99 | 0:ab4e012489ef | 369 | #define RH_RF22_TRCLK_SDO 0x80 |
davidr99 | 0:ab4e012489ef | 370 | #define RH_RF22_TRCLK_NIRQ 0xc0 |
davidr99 | 0:ab4e012489ef | 371 | #define RH_RF22_DTMOD 0x30 |
davidr99 | 0:ab4e012489ef | 372 | #define RH_RF22_DTMOD_DIRECT_GPIO 0x00 |
davidr99 | 0:ab4e012489ef | 373 | #define RH_RF22_DTMOD_DIRECT_SDI 0x10 |
davidr99 | 0:ab4e012489ef | 374 | #define RH_RF22_DTMOD_FIFO 0x20 |
davidr99 | 0:ab4e012489ef | 375 | #define RH_RF22_DTMOD_PN9 0x30 |
davidr99 | 0:ab4e012489ef | 376 | #define RH_RF22_ENINV 0x08 |
davidr99 | 0:ab4e012489ef | 377 | #define RH_RF22_FD8 0x04 |
davidr99 | 0:ab4e012489ef | 378 | #define RH_RF22_MODTYP 0x30 |
davidr99 | 0:ab4e012489ef | 379 | #define RH_RF22_MODTYP_UNMODULATED 0x00 |
davidr99 | 0:ab4e012489ef | 380 | #define RH_RF22_MODTYP_OOK 0x01 |
davidr99 | 0:ab4e012489ef | 381 | #define RH_RF22_MODTYP_FSK 0x02 |
davidr99 | 0:ab4e012489ef | 382 | #define RH_RF22_MODTYP_GFSK 0x03 |
davidr99 | 0:ab4e012489ef | 383 | |
davidr99 | 0:ab4e012489ef | 384 | |
davidr99 | 0:ab4e012489ef | 385 | // RH_RF22_REG_75_FREQUENCY_BAND_SELECT 0x75 |
davidr99 | 0:ab4e012489ef | 386 | #define RH_RF22_SBSEL 0x40 |
davidr99 | 0:ab4e012489ef | 387 | #define RH_RF22_HBSEL 0x20 |
davidr99 | 0:ab4e012489ef | 388 | #define RH_RF22_FB 0x1f |
davidr99 | 0:ab4e012489ef | 389 | |
davidr99 | 0:ab4e012489ef | 390 | // Define this to include Serial printing in diagnostic routines |
davidr99 | 0:ab4e012489ef | 391 | #define RH_RF22_HAVE_SERIAL |
davidr99 | 0:ab4e012489ef | 392 | |
davidr99 | 0:ab4e012489ef | 393 | ///////////////////////////////////////////////////////////////////// |
davidr99 | 0:ab4e012489ef | 394 | /// \class RH_RF22 RH_RF22.h <RH_RF22.h> |
davidr99 | 0:ab4e012489ef | 395 | /// \brief Driver to send and receive unaddressed, unreliable datagrams via an RF22 and compatible radio transceiver. |
davidr99 | 0:ab4e012489ef | 396 | /// |
davidr99 | 0:ab4e012489ef | 397 | /// Works with RF22, RF23 based radio modules, and compatible chips and modules, including: |
davidr99 | 0:ab4e012489ef | 398 | /// - RF22 bare module: http://www.sparkfun.com/products/10153 |
davidr99 | 0:ab4e012489ef | 399 | /// (Caution, that is a 3.3V part, and requires a 3.3V CPU such as Teensy etc or level shifters) |
davidr99 | 0:ab4e012489ef | 400 | /// - RF22 shield: http://www.sparkfun.com/products/11018 |
davidr99 | 0:ab4e012489ef | 401 | /// - RF22 integrated board http://www.anarduino.com/miniwireless |
davidr99 | 0:ab4e012489ef | 402 | /// - RFM23BP bare module: http://www.anarduino.com/details.jsp?pid=130 |
davidr99 | 0:ab4e012489ef | 403 | /// - Silicon Labs Si4430/31/32 based modules. S4432 is equivalent to RF22. Si4431/30 is equivalent to RF23. |
davidr99 | 0:ab4e012489ef | 404 | /// |
davidr99 | 0:ab4e012489ef | 405 | /// Data based on https://www.sparkfun.com/datasheets/Wireless/General/RFM22B.pdf |
davidr99 | 0:ab4e012489ef | 406 | /// |
davidr99 | 0:ab4e012489ef | 407 | /// \par Overview |
davidr99 | 0:ab4e012489ef | 408 | /// |
davidr99 | 0:ab4e012489ef | 409 | /// This base class provides basic functions for sending and receiving unaddressed, |
davidr99 | 0:ab4e012489ef | 410 | /// unreliable datagrams of arbitrary length to 255 octets per packet. |
davidr99 | 0:ab4e012489ef | 411 | /// |
davidr99 | 0:ab4e012489ef | 412 | /// Manager classes may use this class to implement reliable, addressed datagrams and streams, |
davidr99 | 0:ab4e012489ef | 413 | /// mesh routers, repeaters, translators etc. |
davidr99 | 0:ab4e012489ef | 414 | /// |
davidr99 | 0:ab4e012489ef | 415 | /// On transmission, the TO and FROM addresses default to 0x00, unless changed by a subclass. |
davidr99 | 0:ab4e012489ef | 416 | /// On reception the TO addressed is checked against the node address (defaults to 0x00) or the |
davidr99 | 0:ab4e012489ef | 417 | /// broadcast address (which is 0xff). The ID and FLAGS are set to 0, and not checked by this class. |
davidr99 | 0:ab4e012489ef | 418 | /// This permits use of the this base RH_RF22 class as an |
davidr99 | 0:ab4e012489ef | 419 | /// unaddressed, unreliable datagram service without the use of one the RadioHead Manager classes. |
davidr99 | 0:ab4e012489ef | 420 | /// |
davidr99 | 0:ab4e012489ef | 421 | /// Naturally, for any 2 radios to communicate that must be configured to use the same frequency and |
davidr99 | 0:ab4e012489ef | 422 | /// modulation scheme. |
davidr99 | 0:ab4e012489ef | 423 | /// |
davidr99 | 0:ab4e012489ef | 424 | /// \par Details |
davidr99 | 0:ab4e012489ef | 425 | /// |
davidr99 | 0:ab4e012489ef | 426 | /// This Driver provides an object-oriented interface for sending and receiving data messages with Hope-RF |
davidr99 | 0:ab4e012489ef | 427 | /// RF22 and RF23 based radio modules, and compatible chips and modules, |
davidr99 | 0:ab4e012489ef | 428 | /// including the RFM22B transceiver module such as |
davidr99 | 0:ab4e012489ef | 429 | /// this bare module: http://www.sparkfun.com/products/10153 |
davidr99 | 0:ab4e012489ef | 430 | /// and this shield: http://www.sparkfun.com/products/11018 |
davidr99 | 0:ab4e012489ef | 431 | /// and this module: http://www.hoperfusa.com/details.jsp?pid=131 |
davidr99 | 0:ab4e012489ef | 432 | /// and this integrated board: http://www.anarduino.com/miniwireless |
davidr99 | 0:ab4e012489ef | 433 | /// and RF23BP modules such as this http://www.anarduino.com/details.jsp?pid=130 |
davidr99 | 0:ab4e012489ef | 434 | /// |
davidr99 | 0:ab4e012489ef | 435 | /// The Hope-RF (http://www.hoperf.com) RFM22B (http://www.hoperf.com/rf_fsk/fsk/RFM22B.htm) |
davidr99 | 0:ab4e012489ef | 436 | /// is a low-cost ISM transceiver module. It supports FSK, GFSK, OOK over a wide |
davidr99 | 0:ab4e012489ef | 437 | /// range of frequencies and programmable data rates. |
davidr99 | 0:ab4e012489ef | 438 | /// Manual can be found at https://www.sparkfun.com/datasheets/Wireless/General/RFM22.PDF |
davidr99 | 0:ab4e012489ef | 439 | /// |
davidr99 | 0:ab4e012489ef | 440 | /// This library provides functions for sending and receiving messages of up to 255 octets on any |
davidr99 | 0:ab4e012489ef | 441 | /// frequency supported by the RF22B, in a range of predefined data rates and frequency deviations. |
davidr99 | 0:ab4e012489ef | 442 | /// Frequency can be set with 312Hz precision to any frequency from 240.0MHz to 960.0MHz. |
davidr99 | 0:ab4e012489ef | 443 | /// |
davidr99 | 0:ab4e012489ef | 444 | /// Up to 3 RF22B modules can be connected to an Arduino, permitting the construction of translators |
davidr99 | 0:ab4e012489ef | 445 | /// and frequency changers, etc. |
davidr99 | 0:ab4e012489ef | 446 | /// |
davidr99 | 0:ab4e012489ef | 447 | /// The following modulation types are suppported with a range of modem configurations for |
davidr99 | 0:ab4e012489ef | 448 | /// common data rates and frequency deviations: |
davidr99 | 0:ab4e012489ef | 449 | /// - GFSK Gaussian Frequency Shift Keying |
davidr99 | 0:ab4e012489ef | 450 | /// - FSK Frequency Shift Keying |
davidr99 | 0:ab4e012489ef | 451 | /// - OOK On-Off Keying |
davidr99 | 0:ab4e012489ef | 452 | /// |
davidr99 | 0:ab4e012489ef | 453 | /// Support for other RF22B features such as on-chip temperature measurement, analog-digital |
davidr99 | 0:ab4e012489ef | 454 | /// converter, transmitter power control etc is also provided. |
davidr99 | 0:ab4e012489ef | 455 | /// |
davidr99 | 0:ab4e012489ef | 456 | /// Tested on Arduino Diecimila, Uno and Mega with arduino-0021, 1.0.5 |
davidr99 | 0:ab4e012489ef | 457 | /// on OpenSuSE 13.1 and avr-libc-1.6.1-1.15, |
davidr99 | 0:ab4e012489ef | 458 | /// cross-avr-binutils-2.19-9.1, cross-avr-gcc-4.1.3_20080612-26.5. |
davidr99 | 0:ab4e012489ef | 459 | /// With HopeRF RFM22 modules that appear to have RF22B chips on board: |
davidr99 | 0:ab4e012489ef | 460 | /// - Device Type Code = 0x08 (RX/TRX) |
davidr99 | 0:ab4e012489ef | 461 | /// - Version Code = 0x06 |
davidr99 | 0:ab4e012489ef | 462 | /// Works on Duo. Works with Sparkfun RFM22 Wireless shields. Works with RFM22 modules from http://www.hoperfusa.com/ |
davidr99 | 0:ab4e012489ef | 463 | /// Works with Arduino 1.0 to at least 1.0.5. Works on Maple, Flymaple, Uno32. |
davidr99 | 0:ab4e012489ef | 464 | /// |
davidr99 | 0:ab4e012489ef | 465 | /// \par Packet Format |
davidr99 | 0:ab4e012489ef | 466 | /// |
davidr99 | 0:ab4e012489ef | 467 | /// All messages sent and received by this Driver must conform to this packet format: |
davidr99 | 0:ab4e012489ef | 468 | /// |
davidr99 | 0:ab4e012489ef | 469 | /// - 8 nibbles (4 octets) PREAMBLE |
davidr99 | 0:ab4e012489ef | 470 | /// - 2 octets SYNC 0x2d, 0xd4 |
davidr99 | 0:ab4e012489ef | 471 | /// - 4 octets HEADER: (TO, FROM, ID, FLAGS) |
davidr99 | 0:ab4e012489ef | 472 | /// - 1 octet LENGTH (0 to 255), number of octets in DATA |
davidr99 | 0:ab4e012489ef | 473 | /// - 0 to 255 octets DATA |
davidr99 | 0:ab4e012489ef | 474 | /// - 2 octets CRC computed with CRC16(IBM), computed on HEADER, LENGTH and DATA |
davidr99 | 0:ab4e012489ef | 475 | /// |
davidr99 | 0:ab4e012489ef | 476 | /// For technical reasons, the message format is not protocol compatible with the |
davidr99 | 0:ab4e012489ef | 477 | /// 'HopeRF Radio Transceiver Message Library for Arduino' http://www.airspayce.com/mikem/arduino/HopeRF from the same author. Nor is it compatible with |
davidr99 | 0:ab4e012489ef | 478 | /// 'Virtual Wire' http://www.airspayce.com/mikem/arduino/VirtualWire.pdf also from the same author. |
davidr99 | 0:ab4e012489ef | 479 | /// |
davidr99 | 0:ab4e012489ef | 480 | /// \par Connecting RFM-22 to Arduino |
davidr99 | 0:ab4e012489ef | 481 | /// |
davidr99 | 0:ab4e012489ef | 482 | /// If you have the Sparkfun RFM22 Shield (https://www.sparkfun.com/products/11018) |
davidr99 | 0:ab4e012489ef | 483 | /// the connections described below are done for you on the shield, no changes required, |
davidr99 | 0:ab4e012489ef | 484 | /// just add headers and plug it in to an Arduino (but not and Arduino Mega, see below) |
davidr99 | 0:ab4e012489ef | 485 | /// |
davidr99 | 0:ab4e012489ef | 486 | /// The physical connection between the RF22B and the Arduino requires 3.3V, |
davidr99 | 0:ab4e012489ef | 487 | /// the 3 x SPI pins (SCK, SDI, SDO), a Slave Select pin and an interrupt pin. |
davidr99 | 0:ab4e012489ef | 488 | /// |
davidr99 | 0:ab4e012489ef | 489 | /// Note also that on the RFM22B (but not the RFM23B), it is required to control the TX_ANT and |
davidr99 | 0:ab4e012489ef | 490 | /// RX_ANT pins of the RFM22 in order to control the antenna connection properly. The RH_RF22 |
davidr99 | 0:ab4e012489ef | 491 | /// driver is configured by default so that GPIO0 and GPIO1 outputs can |
davidr99 | 0:ab4e012489ef | 492 | /// control TX_ANT and RX_ANT input pins respectively automatically. On RFM22, |
davidr99 | 0:ab4e012489ef | 493 | /// you must connect GPIO0 |
davidr99 | 0:ab4e012489ef | 494 | /// to TX_ANT and GPIO1 to RX_ANT for this automatic antenna switching to |
davidr99 | 0:ab4e012489ef | 495 | /// occur. See setGpioReversed() for more details. These connections are not required on RFM23B. |
davidr99 | 0:ab4e012489ef | 496 | /// |
davidr99 | 0:ab4e012489ef | 497 | /// If you are using the Sparkfun RF22 shield, it will work with any 5V arduino without modification. |
davidr99 | 0:ab4e012489ef | 498 | /// Connect the RFM-22 module to most Arduino's like this (Caution, Arduino Mega has different pins for SPI, |
davidr99 | 0:ab4e012489ef | 499 | /// see below). |
davidr99 | 0:ab4e012489ef | 500 | /// \code |
davidr99 | 0:ab4e012489ef | 501 | /// Arduino RFM-22B |
davidr99 | 0:ab4e012489ef | 502 | /// GND----------GND-\ (ground in) |
davidr99 | 0:ab4e012489ef | 503 | /// SDN-/ (shutdown in) |
davidr99 | 0:ab4e012489ef | 504 | /// 3V3----------VCC (3.3V in) |
davidr99 | 0:ab4e012489ef | 505 | /// interrupt 0 pin D2-----------NIRQ (interrupt request out) |
davidr99 | 0:ab4e012489ef | 506 | /// SS pin D10----------NSEL (chip select in) |
davidr99 | 0:ab4e012489ef | 507 | /// SCK pin D13----------SCK (SPI clock in) |
davidr99 | 0:ab4e012489ef | 508 | /// MOSI pin D11----------SDI (SPI Data in) |
davidr99 | 0:ab4e012489ef | 509 | /// MISO pin D12----------SDO (SPI data out) |
davidr99 | 0:ab4e012489ef | 510 | /// /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT) |
davidr99 | 0:ab4e012489ef | 511 | /// \--TX_ANT (TX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 512 | /// /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT) |
davidr99 | 0:ab4e012489ef | 513 | /// \--RX_ANT (RX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 514 | /// \endcode |
davidr99 | 0:ab4e012489ef | 515 | /// For an Arduino Mega: |
davidr99 | 0:ab4e012489ef | 516 | /// \code |
davidr99 | 0:ab4e012489ef | 517 | /// Mega RFM-22B |
davidr99 | 0:ab4e012489ef | 518 | /// GND----------GND-\ (ground in) |
davidr99 | 0:ab4e012489ef | 519 | /// SDN-/ (shutdown in) |
davidr99 | 0:ab4e012489ef | 520 | /// 3V3----------VCC (3.3V in) |
davidr99 | 0:ab4e012489ef | 521 | /// interrupt 0 pin D2-----------NIRQ (interrupt request out) |
davidr99 | 0:ab4e012489ef | 522 | /// SS pin D53----------NSEL (chip select in) |
davidr99 | 0:ab4e012489ef | 523 | /// SCK pin D52----------SCK (SPI clock in) |
davidr99 | 0:ab4e012489ef | 524 | /// MOSI pin D51----------SDI (SPI Data in) |
davidr99 | 0:ab4e012489ef | 525 | /// MISO pin D50----------SDO (SPI data out) |
davidr99 | 0:ab4e012489ef | 526 | /// /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT) |
davidr99 | 0:ab4e012489ef | 527 | /// \--TX_ANT (TX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 528 | /// /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT) |
davidr99 | 0:ab4e012489ef | 529 | /// \--RX_ANT (RX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 530 | /// \endcode |
davidr99 | 0:ab4e012489ef | 531 | /// For Chipkit Uno32. Caution: you must also ensure jumper JP4 on the Uno32 is set to RD4 |
davidr99 | 0:ab4e012489ef | 532 | /// \code |
davidr99 | 0:ab4e012489ef | 533 | /// Arduino RFM-22B |
davidr99 | 0:ab4e012489ef | 534 | /// GND----------GND-\ (ground in) |
davidr99 | 0:ab4e012489ef | 535 | /// SDN-/ (shutdown in) |
davidr99 | 0:ab4e012489ef | 536 | /// 3V3----------VCC (3.3V in) |
davidr99 | 0:ab4e012489ef | 537 | /// interrupt 0 pin D38----------NIRQ (interrupt request out) |
davidr99 | 0:ab4e012489ef | 538 | /// SS pin D10----------NSEL (chip select in) |
davidr99 | 0:ab4e012489ef | 539 | /// SCK pin D13----------SCK (SPI clock in) |
davidr99 | 0:ab4e012489ef | 540 | /// MOSI pin D11----------SDI (SPI Data in) |
davidr99 | 0:ab4e012489ef | 541 | /// MISO pin D12----------SDO (SPI data out) |
davidr99 | 0:ab4e012489ef | 542 | /// /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT) |
davidr99 | 0:ab4e012489ef | 543 | /// \--TX_ANT (TX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 544 | /// /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT) |
davidr99 | 0:ab4e012489ef | 545 | /// \--RX_ANT (RX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 546 | /// \endcode |
davidr99 | 0:ab4e012489ef | 547 | /// For Teensy 3.1 |
davidr99 | 0:ab4e012489ef | 548 | /// \code |
davidr99 | 0:ab4e012489ef | 549 | /// Teensy RFM-22B |
davidr99 | 0:ab4e012489ef | 550 | /// GND----------GND-\ (ground in) |
davidr99 | 0:ab4e012489ef | 551 | /// SDN-/ (shutdown in) |
davidr99 | 0:ab4e012489ef | 552 | /// 3V3----------VCC (3.3V in) |
davidr99 | 0:ab4e012489ef | 553 | /// interrupt 2 pin D2-----------NIRQ (interrupt request out) |
davidr99 | 0:ab4e012489ef | 554 | /// SS pin D10----------NSEL (chip select in) |
davidr99 | 0:ab4e012489ef | 555 | /// SCK pin D13----------SCK (SPI clock in) |
davidr99 | 0:ab4e012489ef | 556 | /// MOSI pin D11----------SDI (SPI Data in) |
davidr99 | 0:ab4e012489ef | 557 | /// MISO pin D12----------SDO (SPI data out) |
davidr99 | 0:ab4e012489ef | 558 | /// /--GPIO0 (GPIO0 out to control transmitter antenna TX_ANT) |
davidr99 | 0:ab4e012489ef | 559 | /// \--TX_ANT (TX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 560 | /// /--GPIO1 (GPIO1 out to control receiver antenna RX_ANT) |
davidr99 | 0:ab4e012489ef | 561 | /// \--RX_ANT (RX antenna control in) RFM22B only |
davidr99 | 0:ab4e012489ef | 562 | /// \endcode |
davidr99 | 0:ab4e012489ef | 563 | /// For connecting an Arduino to an RFM23BP module. Note that the antenna control pins are reversed |
davidr99 | 0:ab4e012489ef | 564 | /// compared to the RF22. |
davidr99 | 0:ab4e012489ef | 565 | /// \code |
davidr99 | 0:ab4e012489ef | 566 | /// Arduino RFM-23BP |
davidr99 | 0:ab4e012489ef | 567 | /// GND----------GND-\ (ground in) |
davidr99 | 0:ab4e012489ef | 568 | /// SDN-/ (shutdown in) |
davidr99 | 0:ab4e012489ef | 569 | /// 5V-----------VCC (5V in) |
davidr99 | 0:ab4e012489ef | 570 | /// interrupt 0 pin D2-----------NIRQ (interrupt request out) |
davidr99 | 0:ab4e012489ef | 571 | /// SS pin D10----------NSEL (chip select in) |
davidr99 | 0:ab4e012489ef | 572 | /// SCK pin D13----------SCK (SPI clock in) |
davidr99 | 0:ab4e012489ef | 573 | /// MOSI pin D11----------SDI (SPI Data in) |
davidr99 | 0:ab4e012489ef | 574 | /// MISO pin D12----------SDO (SPI data out) |
davidr99 | 0:ab4e012489ef | 575 | /// /--GPIO0 (GPIO0 out to control receiver antenna RXON) |
davidr99 | 0:ab4e012489ef | 576 | /// \--RXON (RX antenna control in) |
davidr99 | 0:ab4e012489ef | 577 | /// /--GPIO1 (GPIO1 out to control transmitter antenna TXON) |
davidr99 | 0:ab4e012489ef | 578 | /// \--TXON (TX antenna control in) |
davidr99 | 0:ab4e012489ef | 579 | /// \endcode |
davidr99 | 0:ab4e012489ef | 580 | /// |
davidr99 | 0:ab4e012489ef | 581 | /// and you can then use the default constructor RH_RF22(). |
davidr99 | 0:ab4e012489ef | 582 | /// You can override the default settings for the SS pin and the interrupt |
davidr99 | 0:ab4e012489ef | 583 | /// in the RH_RF22 constructor if you wish to connect the slave select SS to other than the normal one for your |
davidr99 | 0:ab4e012489ef | 584 | /// Arduino (D10 for Diecimila, Uno etc and D53 for Mega) |
davidr99 | 0:ab4e012489ef | 585 | /// or the interrupt request to other than pin D2 (Caution, different processors have different constraints as to the |
davidr99 | 0:ab4e012489ef | 586 | /// pins available for interrupts). |
davidr99 | 0:ab4e012489ef | 587 | /// |
davidr99 | 0:ab4e012489ef | 588 | /// It is possible to have 2 radios connected to one Arduino, provided each radio has its own |
davidr99 | 0:ab4e012489ef | 589 | /// SS and interrupt line (SCK, SDI and SDO are common to both radios) |
davidr99 | 0:ab4e012489ef | 590 | /// |
davidr99 | 0:ab4e012489ef | 591 | /// Caution: on some Arduinos such as the Mega 2560, if you set the slave select pin to be other than the usual SS |
davidr99 | 0:ab4e012489ef | 592 | /// pin (D53 on Mega 2560), you may need to set the usual SS pin to be an output to force the Arduino into SPI |
davidr99 | 0:ab4e012489ef | 593 | /// master mode. |
davidr99 | 0:ab4e012489ef | 594 | /// |
davidr99 | 0:ab4e012489ef | 595 | /// Caution: Power supply requirements of the RF22 module may be relevant in some circumstances: |
davidr99 | 0:ab4e012489ef | 596 | /// RF22 modules are capable of pulling 80mA+ at full power, where Arduino's 3.3V line can |
davidr99 | 0:ab4e012489ef | 597 | /// give 50mA. You may need to make provision for alternate power supply for |
davidr99 | 0:ab4e012489ef | 598 | /// the RF22, especially if you wish to use full transmit power, and/or you have |
davidr99 | 0:ab4e012489ef | 599 | /// other shields demanding power. Inadequate power for the RF22 is reported to cause symptoms such as: |
davidr99 | 0:ab4e012489ef | 600 | /// - reset's/bootups terminate with "init failed" messages |
davidr99 | 0:ab4e012489ef | 601 | /// -random termination of communication after 5-30 packets sent/received |
davidr99 | 0:ab4e012489ef | 602 | /// -"fake ok" state, where initialization passes fluently, but communication doesn't happen |
davidr99 | 0:ab4e012489ef | 603 | /// -shields hang Arduino boards, especially during the flashing |
davidr99 | 0:ab4e012489ef | 604 | /// |
davidr99 | 0:ab4e012489ef | 605 | /// Caution: some RF22 breakout boards (such as the HAB-RFM22B-BOA HAB-RFM22B-BO) reportedly |
davidr99 | 0:ab4e012489ef | 606 | /// have the TX_ANT and RX_ANT pre-connected to GPIO0 and GPIO1 round the wrong way. You can work with this |
davidr99 | 0:ab4e012489ef | 607 | /// if you use setGpioReversed(). |
davidr99 | 0:ab4e012489ef | 608 | /// |
davidr99 | 0:ab4e012489ef | 609 | /// Caution: If you are using a bare RF22 module without IO level shifters, you may have difficulty connecting |
davidr99 | 0:ab4e012489ef | 610 | /// to a 5V arduino. The RF22 module is 3.3V and its IO pins are 3.3V not 5V. Some Arduinos (Diecimila and |
davidr99 | 0:ab4e012489ef | 611 | /// Uno) seem to work OK with this, and some (Mega) do not always work reliably. Your Mileage May Vary. |
davidr99 | 0:ab4e012489ef | 612 | /// For best result, use level shifters, or use a RF22 shield or board with level shifters built in, |
davidr99 | 0:ab4e012489ef | 613 | /// such as the Sparkfun RFM22 shield http://www.sparkfun.com/products/11018. |
davidr99 | 0:ab4e012489ef | 614 | /// You could also use a 3.3V IO Arduino such as a Pro. |
davidr99 | 0:ab4e012489ef | 615 | /// It is recognised that it is difficult to connect |
davidr99 | 0:ab4e012489ef | 616 | /// the Sparkfun RFM22 shield to a Mega, since the SPI pins on the Mega are different to other Arduinos, |
davidr99 | 0:ab4e012489ef | 617 | /// But it is possible, by bending the SPI pins (D10, D11, D12, D13) on the |
davidr99 | 0:ab4e012489ef | 618 | /// shield out of the way before plugging it in to the Mega and jumpering the shield pins to the Mega like this: |
davidr99 | 0:ab4e012489ef | 619 | /// \code |
davidr99 | 0:ab4e012489ef | 620 | /// RF22 Shield Mega |
davidr99 | 0:ab4e012489ef | 621 | /// D10 D53 |
davidr99 | 0:ab4e012489ef | 622 | /// D13 D52 |
davidr99 | 0:ab4e012489ef | 623 | /// D11 D51 |
davidr99 | 0:ab4e012489ef | 624 | /// D12 D50 |
davidr99 | 0:ab4e012489ef | 625 | /// \endcode |
davidr99 | 0:ab4e012489ef | 626 | /// |
davidr99 | 0:ab4e012489ef | 627 | /// \par Interrupts |
davidr99 | 0:ab4e012489ef | 628 | /// |
davidr99 | 0:ab4e012489ef | 629 | /// The Driver uses interrupts to react to events in the RF22 module, |
davidr99 | 0:ab4e012489ef | 630 | /// such as the reception of a new packet, or the completion of transmission of a packet. |
davidr99 | 0:ab4e012489ef | 631 | /// The RH_RF22 interrupt service routine reads status from and writes data |
davidr99 | 0:ab4e012489ef | 632 | /// to the the RF22 module via the SPI interface. It is very important therefore, |
davidr99 | 0:ab4e012489ef | 633 | /// that if you are using the RF22 library with another SPI based deviced, that you |
davidr99 | 0:ab4e012489ef | 634 | /// disable interrupts while you transfer data to and from that other device. |
davidr99 | 0:ab4e012489ef | 635 | /// Use cli() to disable interrupts and sei() to reenable them. |
davidr99 | 0:ab4e012489ef | 636 | /// |
davidr99 | 0:ab4e012489ef | 637 | /// \par SPI Interface |
davidr99 | 0:ab4e012489ef | 638 | /// |
davidr99 | 0:ab4e012489ef | 639 | /// The RF22 module uses the SPI bus to communicate with the Arduino. Arduino |
davidr99 | 0:ab4e012489ef | 640 | /// IDE includes a hardware SPI class to communicate with SPI devices using |
davidr99 | 0:ab4e012489ef | 641 | /// the SPI facilities built into the Atmel chips, over the standard designated |
davidr99 | 0:ab4e012489ef | 642 | /// SPI pins MOSI, MISO, SCK, which are usually on Arduino pins 11, 12 and 13 |
davidr99 | 0:ab4e012489ef | 643 | /// respectively (or 51, 50, 52 on a Mega). |
davidr99 | 0:ab4e012489ef | 644 | /// |
davidr99 | 0:ab4e012489ef | 645 | /// By default, the RH_RF22 Driver uses the Hardware SPI interface to |
davidr99 | 0:ab4e012489ef | 646 | /// communicate with the RF22 module. However, if your RF22 SPI is connected to |
davidr99 | 0:ab4e012489ef | 647 | /// the Arduino through non-standard pins, or the standard Hardware SPI |
davidr99 | 0:ab4e012489ef | 648 | /// interface will not work for you, you can instead use a bit-banged Software |
davidr99 | 0:ab4e012489ef | 649 | /// SPI class RHSoftwareSPI, which can be configured to work on any Arduino digital IO pins. |
davidr99 | 0:ab4e012489ef | 650 | /// See the documentation of RHSoftwareSPI for details. |
davidr99 | 0:ab4e012489ef | 651 | /// |
davidr99 | 0:ab4e012489ef | 652 | /// The advantages of the Software SPI interface are that it can be used on |
davidr99 | 0:ab4e012489ef | 653 | /// any Arduino pins, not just the usual dedicated hardware pins. The |
davidr99 | 0:ab4e012489ef | 654 | /// disadvantage is that it is significantly slower then hardware. |
davidr99 | 0:ab4e012489ef | 655 | /// If you observe reliable behaviour with the default hardware SPI RHHardwareSPI, but unreliable behaviour |
davidr99 | 0:ab4e012489ef | 656 | /// with Software SPI RHSoftwareSPI, it may be due to slow CPU performance. |
davidr99 | 0:ab4e012489ef | 657 | /// |
davidr99 | 0:ab4e012489ef | 658 | /// Initialisation example with hardware SPI |
davidr99 | 0:ab4e012489ef | 659 | /// \code |
davidr99 | 0:ab4e012489ef | 660 | /// #include <RH_RF22.h> |
davidr99 | 0:ab4e012489ef | 661 | /// RH_RF22 driver; |
davidr99 | 0:ab4e012489ef | 662 | /// RHReliableDatagram manager(driver, CLIENT_ADDRESS); |
davidr99 | 0:ab4e012489ef | 663 | /// \endcode |
davidr99 | 0:ab4e012489ef | 664 | /// |
davidr99 | 0:ab4e012489ef | 665 | /// Initialisation example with software SPI |
davidr99 | 0:ab4e012489ef | 666 | /// \code |
davidr99 | 0:ab4e012489ef | 667 | /// #include <RH_RF22.h> |
davidr99 | 0:ab4e012489ef | 668 | /// #include <RHSoftwareSPI.h> |
davidr99 | 0:ab4e012489ef | 669 | /// RHSoftwareSPI spi; |
davidr99 | 0:ab4e012489ef | 670 | /// RH_RF22 driver(10, 2, spi); |
davidr99 | 0:ab4e012489ef | 671 | /// RHReliableDatagram manager(driver, CLIENT_ADDRESS); |
davidr99 | 0:ab4e012489ef | 672 | /// \endcode |
davidr99 | 0:ab4e012489ef | 673 | /// |
davidr99 | 0:ab4e012489ef | 674 | /// \par Memory |
davidr99 | 0:ab4e012489ef | 675 | /// |
davidr99 | 0:ab4e012489ef | 676 | /// The RH_RF22 Driver requires non-trivial amounts of memory. The sample programs all compile to |
davidr99 | 0:ab4e012489ef | 677 | /// about 9 to 14kbytes each on Arduino, which will fit in the flash proram memory of most Arduinos. However, |
davidr99 | 0:ab4e012489ef | 678 | /// the RAM requirements are more critical. Most sample programs above will run on Duemilanova, |
davidr99 | 0:ab4e012489ef | 679 | /// but not on Diecimila. Even on Duemilanova, the RAM requirements are very close to the |
davidr99 | 0:ab4e012489ef | 680 | /// available memory of 2kbytes. Therefore, you should be vary sparing with RAM use in programs that use |
davidr99 | 0:ab4e012489ef | 681 | /// the RH_RF22 Driver on Duemilanova. |
davidr99 | 0:ab4e012489ef | 682 | /// |
davidr99 | 0:ab4e012489ef | 683 | /// The sample RHRouter and RHMesh programs compile to about 14kbytes, |
davidr99 | 0:ab4e012489ef | 684 | /// and require more RAM than the others. |
davidr99 | 0:ab4e012489ef | 685 | /// They will not run on Duemilanova or Diecimila, but will run on Arduino Mega. |
davidr99 | 0:ab4e012489ef | 686 | /// |
davidr99 | 0:ab4e012489ef | 687 | /// It is often hard to accurately identify when you are hitting RAM limits on Arduino. |
davidr99 | 0:ab4e012489ef | 688 | /// The symptoms can include: |
davidr99 | 0:ab4e012489ef | 689 | /// - Mysterious crashes and restarts |
davidr99 | 0:ab4e012489ef | 690 | /// - Changes in behaviour when seemingly unrelated changes are made (such as adding print() statements) |
davidr99 | 0:ab4e012489ef | 691 | /// - Hanging |
davidr99 | 0:ab4e012489ef | 692 | /// - Output from Serial.print() not appearing |
davidr99 | 0:ab4e012489ef | 693 | /// |
davidr99 | 0:ab4e012489ef | 694 | /// With an Arduino Mega, with 8 kbytes of SRAM, there is much more RAM headroom for |
davidr99 | 0:ab4e012489ef | 695 | /// your own elaborate programs. |
davidr99 | 0:ab4e012489ef | 696 | /// This library is reported to work with Arduino Pro Mini, but that has not been tested by me. |
davidr99 | 0:ab4e012489ef | 697 | /// |
davidr99 | 0:ab4e012489ef | 698 | /// The RF22M modules use an inexpensive crystal to control the frequency synthesizer, and therfore you can expect |
davidr99 | 0:ab4e012489ef | 699 | /// the transmitter and receiver frequencies to be subject to the usual inaccuracies of such crystals. The RF22 |
davidr99 | 0:ab4e012489ef | 700 | /// contains an AFC circuit to compensate for differences in transmitter and receiver frequencies. |
davidr99 | 0:ab4e012489ef | 701 | /// It does this by altering the receiver frequency during reception by up to the pull-in frequency range. |
davidr99 | 0:ab4e012489ef | 702 | /// This RF22 library enables the AFC and by default sets the pull-in frequency range to |
davidr99 | 0:ab4e012489ef | 703 | /// 0.05MHz, which should be sufficient to handle most situations. However, if you observe unexplained packet losses |
davidr99 | 0:ab4e012489ef | 704 | /// or failure to operate correctly all the time it may be because your modules have a wider frequency difference, and |
davidr99 | 0:ab4e012489ef | 705 | /// you may need to set the afcPullInRange to a different value, using setFrequency(); |
davidr99 | 0:ab4e012489ef | 706 | /// |
davidr99 | 0:ab4e012489ef | 707 | /// \par Transmitter Power |
davidr99 | 0:ab4e012489ef | 708 | /// |
davidr99 | 0:ab4e012489ef | 709 | /// You can control the transmitter power on the RF22 and RF23 transceivers |
davidr99 | 0:ab4e012489ef | 710 | /// with the RH_RF22::setTxPower() function. The argument can be any of the |
davidr99 | 0:ab4e012489ef | 711 | /// RH_RF22_TXPOW_* (for RFM22) or RH_RF22_RF23B_TXPOW_* (for RFM23) values. |
davidr99 | 0:ab4e012489ef | 712 | /// The default is RH_RF22_TXPOW_8DBM/RH_RF22_RF23B_TXPOW_1DBM . Eg: |
davidr99 | 0:ab4e012489ef | 713 | /// \code |
davidr99 | 0:ab4e012489ef | 714 | /// driver.setTxPower(RH_RF22_TXPOW_2DBM); |
davidr99 | 0:ab4e012489ef | 715 | /// \endcode |
davidr99 | 0:ab4e012489ef | 716 | /// |
davidr99 | 0:ab4e012489ef | 717 | /// The RF23BP has higher power capability, there are |
davidr99 | 0:ab4e012489ef | 718 | /// several power settings that are specific to the RF23BP only: |
davidr99 | 0:ab4e012489ef | 719 | /// |
davidr99 | 0:ab4e012489ef | 720 | /// - RH_RF22_RF23BP_TXPOW_28DBM |
davidr99 | 0:ab4e012489ef | 721 | /// - RH_RF22_RF23BP_TXPOW_29DBM |
davidr99 | 0:ab4e012489ef | 722 | /// - RH_RF22_RF23BP_TXPOW_38DBM |
davidr99 | 0:ab4e012489ef | 723 | /// |
davidr99 | 0:ab4e012489ef | 724 | /// CAUTION: the high power settings available on the RFM23BP require |
davidr99 | 0:ab4e012489ef | 725 | /// significant power supply current. For example at +30dBm, the typical chip |
davidr99 | 0:ab4e012489ef | 726 | /// supply current is 550mA. This will overwhelm some small CPU board power |
davidr99 | 0:ab4e012489ef | 727 | /// regulators and USB supplies. If you use this chip at high power make sure |
davidr99 | 0:ab4e012489ef | 728 | /// you have an adequate supply current providing full 5V to the RFM23BP (and |
davidr99 | 0:ab4e012489ef | 729 | /// the CPU if required), otherwise you can expect strange behaviour like |
davidr99 | 0:ab4e012489ef | 730 | /// hanging, stopping, incorrect power levels, RF power amp overheating etc. |
davidr99 | 0:ab4e012489ef | 731 | /// You must also ensure that the RFM23BP GPIO pins are connected to the |
davidr99 | 0:ab4e012489ef | 732 | /// antenna switch control pins like so: |
davidr99 | 0:ab4e012489ef | 733 | //// |
davidr99 | 0:ab4e012489ef | 734 | /// \code |
davidr99 | 0:ab4e012489ef | 735 | /// GPIO0 <-> RXON |
davidr99 | 0:ab4e012489ef | 736 | /// GPIO1 <-> TXON |
davidr99 | 0:ab4e012489ef | 737 | /// \endcode |
davidr99 | 0:ab4e012489ef | 738 | /// |
davidr99 | 0:ab4e012489ef | 739 | /// The RF output impedance of the RFM22BP module is 50 ohms. In our |
davidr99 | 0:ab4e012489ef | 740 | /// experiments we found that the most critical issue (besides a suitable |
davidr99 | 0:ab4e012489ef | 741 | /// power supply) is to ensure that the antenna impedance is also near 50 |
davidr99 | 0:ab4e012489ef | 742 | /// ohms. Connecting a simple 1/4 wavelength (ie a 17.3cm single wire) |
davidr99 | 0:ab4e012489ef | 743 | /// directly to the antenna output <b>will not work at full 30dBm power</b>, |
davidr99 | 0:ab4e012489ef | 744 | /// and will result in the transmitter hanging and/or the power amp |
davidr99 | 0:ab4e012489ef | 745 | /// overheating. Connect a proper 50 ohm impedance transmission line or |
davidr99 | 0:ab4e012489ef | 746 | /// antenna, and prevent RF radiation into the radio and arduino modules, |
davidr99 | 0:ab4e012489ef | 747 | /// in order to get full, reliable power. Our tests show that a 433MHz |
davidr99 | 0:ab4e012489ef | 748 | /// RFM23BP feeding a 50 ohm transmission line with a VHF discone antenna at |
davidr99 | 0:ab4e012489ef | 749 | /// the end results in full power output and the power amp transistor on the |
davidr99 | 0:ab4e012489ef | 750 | /// RFM22BP module runnning slightly warm but not hot. We recommend you use |
davidr99 | 0:ab4e012489ef | 751 | /// the services of a competent RF engineer when trying to use this high power |
davidr99 | 0:ab4e012489ef | 752 | /// module. |
davidr99 | 0:ab4e012489ef | 753 | /// |
davidr99 | 0:ab4e012489ef | 754 | /// Note: with RFM23BP, the reported maximum possible power when operating on 3.3V is 27dBm. |
davidr99 | 0:ab4e012489ef | 755 | /// |
davidr99 | 0:ab4e012489ef | 756 | /// We have made some actual power measurements against |
davidr99 | 0:ab4e012489ef | 757 | /// programmed power for Sparkfun RFM22 wireless module under the following conditions: |
davidr99 | 0:ab4e012489ef | 758 | /// - Sparkfun RFM22 wireless module, Duemilanove, USB power |
davidr99 | 0:ab4e012489ef | 759 | /// - 10cm RG58C/U soldered direct to RFM22 module ANT and GND |
davidr99 | 0:ab4e012489ef | 760 | /// - bnc connecteor |
davidr99 | 0:ab4e012489ef | 761 | /// - 12dB attenuator |
davidr99 | 0:ab4e012489ef | 762 | /// - BNC-SMA adapter |
davidr99 | 0:ab4e012489ef | 763 | /// - MiniKits AD8307 HF/VHF Power Head (calibrated against Rohde&Schwartz 806.2020 test set) |
davidr99 | 0:ab4e012489ef | 764 | /// - Tektronix TDS220 scope to measure the Vout from power head |
davidr99 | 0:ab4e012489ef | 765 | /// \code |
davidr99 | 0:ab4e012489ef | 766 | /// Program power Measured Power |
davidr99 | 0:ab4e012489ef | 767 | /// dBm dBm |
davidr99 | 0:ab4e012489ef | 768 | /// 1 -5.6 |
davidr99 | 0:ab4e012489ef | 769 | /// 2 -3.8 |
davidr99 | 0:ab4e012489ef | 770 | /// 5 -2.2 |
davidr99 | 0:ab4e012489ef | 771 | /// 8 -0.6 |
davidr99 | 0:ab4e012489ef | 772 | /// 11 1.2 |
davidr99 | 0:ab4e012489ef | 773 | /// 14 11.6 |
davidr99 | 0:ab4e012489ef | 774 | /// 17 14.4 |
davidr99 | 0:ab4e012489ef | 775 | /// 20 18.0 |
davidr99 | 0:ab4e012489ef | 776 | /// \endcode |
davidr99 | 0:ab4e012489ef | 777 | /// (Caution: we dont claim laboratory accuracy for these measurements) |
davidr99 | 0:ab4e012489ef | 778 | /// You would not expect to get anywhere near these powers to air with a simple 1/4 wavelength wire antenna. |
davidr99 | 0:ab4e012489ef | 779 | /// |
davidr99 | 0:ab4e012489ef | 780 | /// \par Performance |
davidr99 | 0:ab4e012489ef | 781 | /// |
davidr99 | 0:ab4e012489ef | 782 | /// Some simple speed performance tests have been conducted. |
davidr99 | 0:ab4e012489ef | 783 | /// In general packet transmission rate will be limited by the modulation scheme. |
davidr99 | 0:ab4e012489ef | 784 | /// Also, if your code does any slow operations like Serial printing it will also limit performance. |
davidr99 | 0:ab4e012489ef | 785 | /// We disabled any printing in the tests below. |
davidr99 | 0:ab4e012489ef | 786 | /// We tested with RH_RF22::GFSK_Rb125Fd125, which is probably the fastest scheme available. |
davidr99 | 0:ab4e012489ef | 787 | /// We tested with a 13 octet message length, over a very short distance of 10cm. |
davidr99 | 0:ab4e012489ef | 788 | /// |
davidr99 | 0:ab4e012489ef | 789 | /// Transmission (no reply) tests with modulation RH_RF22::GFSK_Rb125Fd125 and a |
davidr99 | 0:ab4e012489ef | 790 | /// 13 octet message show about 330 messages per second transmitted. |
davidr99 | 0:ab4e012489ef | 791 | /// |
davidr99 | 0:ab4e012489ef | 792 | /// Transmit-and-wait-for-a-reply tests with modulation RH_RF22::GFSK_Rb125Fd125 and a |
davidr99 | 0:ab4e012489ef | 793 | /// 13 octet message (send and receive) show about 160 round trips per second. |
davidr99 | 0:ab4e012489ef | 794 | /// |
davidr99 | 0:ab4e012489ef | 795 | /// \par Compatibility with RF22 library |
davidr99 | 0:ab4e012489ef | 796 | /// The RH_RF22 driver is based on our earlier RF22 library http://www.airspayce.com/mikem/arduino/RF22 |
davidr99 | 0:ab4e012489ef | 797 | /// We have tried hard to be as compatible as possible with the earlier RF22 library, but there are some differences: |
davidr99 | 0:ab4e012489ef | 798 | /// - Different constructor. |
davidr99 | 0:ab4e012489ef | 799 | /// - Indexes for some modem configurations have changed (we recommend you use the symbolic names, not integer indexes). |
davidr99 | 0:ab4e012489ef | 800 | /// |
davidr99 | 0:ab4e012489ef | 801 | /// The major difference is that under RadioHead, you are |
davidr99 | 0:ab4e012489ef | 802 | /// required to create 2 objects (ie RH_RF22 and a manager) instead of just one object under RF22 |
davidr99 | 0:ab4e012489ef | 803 | /// (ie RHMesh, RHRouter, RHReliableDatagram or RHDatagram). |
davidr99 | 0:ab4e012489ef | 804 | /// It may be sufficient or you to change for example: |
davidr99 | 0:ab4e012489ef | 805 | /// \code |
davidr99 | 0:ab4e012489ef | 806 | /// RF22ReliableDatagram rf22(CLIENT_ADDRESS); |
davidr99 | 0:ab4e012489ef | 807 | /// \endcode |
davidr99 | 0:ab4e012489ef | 808 | /// to: |
davidr99 | 0:ab4e012489ef | 809 | /// \code |
davidr99 | 0:ab4e012489ef | 810 | /// RH_RF22 driver; |
davidr99 | 0:ab4e012489ef | 811 | /// RHReliableDatagram rf22(driver, CLIENT_ADDRESS); |
davidr99 | 0:ab4e012489ef | 812 | /// \endcode |
davidr99 | 0:ab4e012489ef | 813 | /// and any instance of RF22_MAX_MESSAGE_LEN to RH_RF22_MAX_MESSAGE_LEN |
davidr99 | 0:ab4e012489ef | 814 | /// |
davidr99 | 0:ab4e012489ef | 815 | /// RadioHead version 1.6 changed the way the interrupt pin number is |
davidr99 | 0:ab4e012489ef | 816 | /// specified on Arduino and Uno32 platforms. If your code previously |
davidr99 | 0:ab4e012489ef | 817 | /// specifed a non-default interrupt pin number in the RH_RF22 constructor, |
davidr99 | 0:ab4e012489ef | 818 | /// you may need to review your code to specify the correct interrrupt pin |
davidr99 | 0:ab4e012489ef | 819 | /// (and not the interrupt number as before). |
davidr99 | 0:ab4e012489ef | 820 | class RH_RF22 : public RHSPIDriver |
davidr99 | 0:ab4e012489ef | 821 | { |
davidr99 | 0:ab4e012489ef | 822 | public: |
davidr99 | 0:ab4e012489ef | 823 | |
davidr99 | 0:ab4e012489ef | 824 | /// \brief Defines register values for a set of modem configuration registers |
davidr99 | 0:ab4e012489ef | 825 | /// |
davidr99 | 0:ab4e012489ef | 826 | /// Defines register values for a set of modem configuration registers |
davidr99 | 0:ab4e012489ef | 827 | /// that can be passed to setModemConfig() |
davidr99 | 0:ab4e012489ef | 828 | /// if none of the choices in ModemConfigChoice suit your need |
davidr99 | 0:ab4e012489ef | 829 | /// setModemConfig() writes the register values to the appropriate RH_RF22 registers |
davidr99 | 0:ab4e012489ef | 830 | /// to set the desired modulation type, data rate and deviation/bandwidth. |
davidr99 | 0:ab4e012489ef | 831 | /// Suitable values for these registers can be computed using the register calculator at |
davidr99 | 0:ab4e012489ef | 832 | /// http://www.hoperf.com/upload/rf/RF22B%2023B%2031B%2042B%2043B%20Register%20Settings_RevB1-v5.xls |
davidr99 | 0:ab4e012489ef | 833 | typedef struct |
davidr99 | 0:ab4e012489ef | 834 | { |
davidr99 | 0:ab4e012489ef | 835 | uint8_t reg_1c; ///< Value for register RH_RF22_REG_1C_IF_FILTER_BANDWIDTH |
davidr99 | 0:ab4e012489ef | 836 | uint8_t reg_1f; ///< Value for register RH_RF22_REG_1F_CLOCK_RECOVERY_GEARSHIFT_OVERRIDE |
davidr99 | 0:ab4e012489ef | 837 | uint8_t reg_20; ///< Value for register RH_RF22_REG_20_CLOCK_RECOVERY_OVERSAMPLING_RATE |
davidr99 | 0:ab4e012489ef | 838 | uint8_t reg_21; ///< Value for register RH_RF22_REG_21_CLOCK_RECOVERY_OFFSET2 |
davidr99 | 0:ab4e012489ef | 839 | uint8_t reg_22; ///< Value for register RH_RF22_REG_22_CLOCK_RECOVERY_OFFSET1 |
davidr99 | 0:ab4e012489ef | 840 | uint8_t reg_23; ///< Value for register RH_RF22_REG_23_CLOCK_RECOVERY_OFFSET0 |
davidr99 | 0:ab4e012489ef | 841 | uint8_t reg_24; ///< Value for register RH_RF22_REG_24_CLOCK_RECOVERY_TIMING_LOOP_GAIN1 |
davidr99 | 0:ab4e012489ef | 842 | uint8_t reg_25; ///< Value for register RH_RF22_REG_25_CLOCK_RECOVERY_TIMING_LOOP_GAIN0 |
davidr99 | 0:ab4e012489ef | 843 | uint8_t reg_2c; ///< Value for register RH_RF22_REG_2C_OOK_COUNTER_VALUE_1 |
davidr99 | 0:ab4e012489ef | 844 | uint8_t reg_2d; ///< Value for register RH_RF22_REG_2D_OOK_COUNTER_VALUE_2 |
davidr99 | 0:ab4e012489ef | 845 | uint8_t reg_2e; ///< Value for register RH_RF22_REG_2E_SLICER_PEAK_HOLD |
davidr99 | 0:ab4e012489ef | 846 | uint8_t reg_58; ///< Value for register RH_RF22_REG_58_CHARGE_PUMP_CURRENT_TRIMMING |
davidr99 | 0:ab4e012489ef | 847 | uint8_t reg_69; ///< Value for register RH_RF22_REG_69_AGC_OVERRIDE1 |
davidr99 | 0:ab4e012489ef | 848 | uint8_t reg_6e; ///< Value for register RH_RF22_REG_6E_TX_DATA_RATE1 |
davidr99 | 0:ab4e012489ef | 849 | uint8_t reg_6f; ///< Value for register RH_RF22_REG_6F_TX_DATA_RATE0 |
davidr99 | 0:ab4e012489ef | 850 | uint8_t reg_70; ///< Value for register RH_RF22_REG_70_MODULATION_CONTROL1 |
davidr99 | 0:ab4e012489ef | 851 | uint8_t reg_71; ///< Value for register RH_RF22_REG_71_MODULATION_CONTROL2 |
davidr99 | 0:ab4e012489ef | 852 | uint8_t reg_72; ///< Value for register RH_RF22_REG_72_FREQUENCY_DEVIATION |
davidr99 | 0:ab4e012489ef | 853 | } ModemConfig; |
davidr99 | 0:ab4e012489ef | 854 | |
davidr99 | 0:ab4e012489ef | 855 | /// Choices for setModemConfig() for a selected subset of common modulation types, |
davidr99 | 0:ab4e012489ef | 856 | /// and data rates. If you need another configuration, use the register calculator. |
davidr99 | 0:ab4e012489ef | 857 | /// and call setModemRegisters() with your desired settings. |
davidr99 | 0:ab4e012489ef | 858 | /// These are indexes into MODEM_CONFIG_TABLE. We strongly recommend you use these symbolic |
davidr99 | 0:ab4e012489ef | 859 | /// definitions and not their integer equivalents: its possible that new values will be |
davidr99 | 0:ab4e012489ef | 860 | /// introduced in later versions (though we will try to avoid it). |
davidr99 | 0:ab4e012489ef | 861 | typedef enum |
davidr99 | 0:ab4e012489ef | 862 | { |
davidr99 | 0:ab4e012489ef | 863 | UnmodulatedCarrier = 0, ///< Unmodulated carrier for testing |
davidr99 | 0:ab4e012489ef | 864 | FSK_PN9_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz, PN9 random modulation for testing |
davidr99 | 0:ab4e012489ef | 865 | |
davidr99 | 0:ab4e012489ef | 866 | FSK_Rb2Fd5, ///< FSK, No Manchester, Rb = 2kbs, Fd = 5kHz |
davidr99 | 0:ab4e012489ef | 867 | FSK_Rb2_4Fd36, ///< FSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz |
davidr99 | 0:ab4e012489ef | 868 | FSK_Rb4_8Fd45, ///< FSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz |
davidr99 | 0:ab4e012489ef | 869 | FSK_Rb9_6Fd45, ///< FSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz |
davidr99 | 0:ab4e012489ef | 870 | FSK_Rb19_2Fd9_6, ///< FSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz |
davidr99 | 0:ab4e012489ef | 871 | FSK_Rb38_4Fd19_6, ///< FSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz |
davidr99 | 0:ab4e012489ef | 872 | FSK_Rb57_6Fd28_8, ///< FSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz |
davidr99 | 0:ab4e012489ef | 873 | FSK_Rb125Fd125, ///< FSK, No Manchester, Rb = 125kbs, Fd = 125kHz |
davidr99 | 0:ab4e012489ef | 874 | FSK_Rb_512Fd2_5, ///< FSK, No Manchester, Rb = 512bs, Fd = 2.5kHz, for POCSAG compatibility |
davidr99 | 0:ab4e012489ef | 875 | FSK_Rb_512Fd4_5, ///< FSK, No Manchester, Rb = 512bs, Fd = 4.5kHz, for POCSAG compatibility |
davidr99 | 0:ab4e012489ef | 876 | |
davidr99 | 0:ab4e012489ef | 877 | GFSK_Rb2Fd5, ///< GFSK, No Manchester, Rb = 2kbs, Fd = 5kHz |
davidr99 | 0:ab4e012489ef | 878 | GFSK_Rb2_4Fd36, ///< GFSK, No Manchester, Rb = 2.4kbs, Fd = 36kHz |
davidr99 | 0:ab4e012489ef | 879 | GFSK_Rb4_8Fd45, ///< GFSK, No Manchester, Rb = 4.8kbs, Fd = 45kHz |
davidr99 | 0:ab4e012489ef | 880 | GFSK_Rb9_6Fd45, ///< GFSK, No Manchester, Rb = 9.6kbs, Fd = 45kHz |
davidr99 | 0:ab4e012489ef | 881 | GFSK_Rb19_2Fd9_6, ///< GFSK, No Manchester, Rb = 19.2kbs, Fd = 9.6kHz |
davidr99 | 0:ab4e012489ef | 882 | GFSK_Rb38_4Fd19_6, ///< GFSK, No Manchester, Rb = 38.4kbs, Fd = 19.6kHz |
davidr99 | 0:ab4e012489ef | 883 | GFSK_Rb57_6Fd28_8, ///< GFSK, No Manchester, Rb = 57.6kbs, Fd = 28.8kHz |
davidr99 | 0:ab4e012489ef | 884 | GFSK_Rb125Fd125, ///< GFSK, No Manchester, Rb = 125kbs, Fd = 125kHz |
davidr99 | 0:ab4e012489ef | 885 | |
davidr99 | 0:ab4e012489ef | 886 | OOK_Rb1_2Bw75, ///< OOK, No Manchester, Rb = 1.2kbs, Rx Bandwidth = 75kHz |
davidr99 | 0:ab4e012489ef | 887 | OOK_Rb2_4Bw335, ///< OOK, No Manchester, Rb = 2.4kbs, Rx Bandwidth = 335kHz |
davidr99 | 0:ab4e012489ef | 888 | OOK_Rb4_8Bw335, ///< OOK, No Manchester, Rb = 4.8kbs, Rx Bandwidth = 335kHz |
davidr99 | 0:ab4e012489ef | 889 | OOK_Rb9_6Bw335, ///< OOK, No Manchester, Rb = 9.6kbs, Rx Bandwidth = 335kHz |
davidr99 | 0:ab4e012489ef | 890 | OOK_Rb19_2Bw335, ///< OOK, No Manchester, Rb = 19.2kbs, Rx Bandwidth = 335kHz |
davidr99 | 0:ab4e012489ef | 891 | OOK_Rb38_4Bw335, ///< OOK, No Manchester, Rb = 38.4kbs, Rx Bandwidth = 335kHz |
davidr99 | 0:ab4e012489ef | 892 | OOK_Rb40Bw335 ///< OOK, No Manchester, Rb = 40kbs, Rx Bandwidth = 335kHz |
davidr99 | 0:ab4e012489ef | 893 | |
davidr99 | 0:ab4e012489ef | 894 | } ModemConfigChoice; |
davidr99 | 0:ab4e012489ef | 895 | |
davidr99 | 0:ab4e012489ef | 896 | /// \brief Defines the available choices for CRC |
davidr99 | 0:ab4e012489ef | 897 | /// Types of permitted CRC polynomials, to be passed to setCRCPolynomial() |
davidr99 | 0:ab4e012489ef | 898 | /// They deliberately have the same numeric values as the crc[1:0] field of Register |
davidr99 | 0:ab4e012489ef | 899 | /// RH_RF22_REG_30_DATA_ACCESS_CONTROL |
davidr99 | 0:ab4e012489ef | 900 | typedef enum |
davidr99 | 0:ab4e012489ef | 901 | { |
davidr99 | 0:ab4e012489ef | 902 | CRC_CCITT = 0, ///< CCITT |
davidr99 | 0:ab4e012489ef | 903 | CRC_16_IBM = 1, ///< CRC-16 (IBM) The default used by RH_RF22 driver |
davidr99 | 0:ab4e012489ef | 904 | CRC_IEC_16 = 2, ///< IEC-16 |
davidr99 | 0:ab4e012489ef | 905 | CRC_Biacheva = 3 ///< Biacheva |
davidr99 | 0:ab4e012489ef | 906 | } CRCPolynomial; |
davidr99 | 0:ab4e012489ef | 907 | |
davidr99 | 0:ab4e012489ef | 908 | /// Constructor. You can have multiple instances, but each instance must have its own |
davidr99 | 0:ab4e012489ef | 909 | /// interrupt and slave select pin. After constructing, you must call init() to initialise the interface |
davidr99 | 0:ab4e012489ef | 910 | /// and the radio module. A maximum of 3 instances can co-exist on one processor, provided there are sufficient |
davidr99 | 0:ab4e012489ef | 911 | /// distinct interrupt lines, one for each instance. |
davidr99 | 0:ab4e012489ef | 912 | /// \param[in] slaveSelectPin the Arduino pin number of the output to use to select the RH_RF22 before |
davidr99 | 0:ab4e012489ef | 913 | /// accessing it. Defaults to the normal SS pin for your Arduino (D10 for Diecimila, Uno etc, D53 for Mega, D10 for Maple) |
davidr99 | 0:ab4e012489ef | 914 | /// \param[in] interruptPin The interrupt Pin number that is connected to the RF22 NIRQ interrupt line. |
davidr99 | 0:ab4e012489ef | 915 | /// Defaults to pin 2, as required by sparkfun RFM22 module shields. |
davidr99 | 0:ab4e012489ef | 916 | /// Caution: You must specify an interrupt capable pin. |
davidr99 | 0:ab4e012489ef | 917 | /// On many Arduino boards, there are limitations as to which pins may be used as interrupts. |
davidr99 | 0:ab4e012489ef | 918 | /// On Leonardo pins 0, 1, 2 or 3. On Mega2560 pins 2, 3, 18, 19, 20, 21. On Due and Teensy, any digital pin. |
davidr99 | 0:ab4e012489ef | 919 | /// On other Arduinos pins 2 or 3. |
davidr99 | 0:ab4e012489ef | 920 | /// See http://arduino.cc/en/Reference/attachInterrupt for more details. |
davidr99 | 0:ab4e012489ef | 921 | /// On Chipkit Uno32, pins 38, 2, 7, 8, 35. |
davidr99 | 0:ab4e012489ef | 922 | /// On other boards, any digital pin may be used. |
davidr99 | 0:ab4e012489ef | 923 | /// \param[in] spi Pointer to the SPI interface object to use. |
davidr99 | 0:ab4e012489ef | 924 | /// Defaults to the standard Arduino hardware SPI interface |
davidr99 | 0:ab4e012489ef | 925 | RH_RF22(PINS slaveSelectPin, PINS interruptPin, RHGenericSPI& spi = hardware_spi); |
davidr99 | 0:ab4e012489ef | 926 | |
davidr99 | 0:ab4e012489ef | 927 | /// Initialises this instance and the radio module connected to it. |
davidr99 | 0:ab4e012489ef | 928 | /// The following steps are taken: |
davidr99 | 0:ab4e012489ef | 929 | /// - Initialise the slave select pin and the SPI interface library |
davidr99 | 0:ab4e012489ef | 930 | /// - Software reset the RH_RF22 module |
davidr99 | 0:ab4e012489ef | 931 | /// - Checks the connected RH_RF22 module is either a RH_RF22_DEVICE_TYPE_RX_TRX or a RH_RF22_DEVICE_TYPE_TX |
davidr99 | 0:ab4e012489ef | 932 | /// - Attaches an interrupt handler |
davidr99 | 0:ab4e012489ef | 933 | /// - Configures the RH_RF22 module |
davidr99 | 0:ab4e012489ef | 934 | /// - Sets the frequency to 434.0 MHz |
davidr99 | 0:ab4e012489ef | 935 | /// - Sets the modem data rate to FSK_Rb2_4Fd36 |
davidr99 | 0:ab4e012489ef | 936 | /// \return true if everything was successful |
davidr99 | 0:ab4e012489ef | 937 | bool init(); |
davidr99 | 0:ab4e012489ef | 938 | |
davidr99 | 0:ab4e012489ef | 939 | /// Issues a software reset to the |
davidr99 | 0:ab4e012489ef | 940 | /// RH_RF22 module. Blocks for 1ms to ensure the reset is complete. |
davidr99 | 0:ab4e012489ef | 941 | void reset(); |
davidr99 | 0:ab4e012489ef | 942 | |
davidr99 | 0:ab4e012489ef | 943 | /// Reads and returns the device status register RH_RF22_REG_02_DEVICE_STATUS |
davidr99 | 0:ab4e012489ef | 944 | /// \return The value of the device status register |
davidr99 | 0:ab4e012489ef | 945 | uint8_t statusRead(); |
davidr99 | 0:ab4e012489ef | 946 | |
davidr99 | 0:ab4e012489ef | 947 | /// Reads a value from the on-chip analog-digital converter |
davidr99 | 0:ab4e012489ef | 948 | /// \param[in] adcsel Selects the ADC input to measure. One of RH_RF22_ADCSEL_*. Defaults to the |
davidr99 | 0:ab4e012489ef | 949 | /// internal temperature sensor |
davidr99 | 0:ab4e012489ef | 950 | /// \param[in] adcref Specifies the refernce voltage to use. One of RH_RF22_ADCREF_*. |
davidr99 | 0:ab4e012489ef | 951 | /// Defaults to the internal bandgap voltage. |
davidr99 | 0:ab4e012489ef | 952 | /// \param[in] adcgain Amplifier gain selection. |
davidr99 | 0:ab4e012489ef | 953 | /// \param[in] adcoffs Amplifier offseet (0 to 15). |
davidr99 | 0:ab4e012489ef | 954 | /// \return The analog value. 0 to 255. |
davidr99 | 0:ab4e012489ef | 955 | uint8_t adcRead(uint8_t adcsel = RH_RF22_ADCSEL_INTERNAL_TEMPERATURE_SENSOR, |
davidr99 | 0:ab4e012489ef | 956 | uint8_t adcref = RH_RF22_ADCREF_BANDGAP_VOLTAGE, |
davidr99 | 0:ab4e012489ef | 957 | uint8_t adcgain = 0, |
davidr99 | 0:ab4e012489ef | 958 | uint8_t adcoffs = 0); |
davidr99 | 0:ab4e012489ef | 959 | |
davidr99 | 0:ab4e012489ef | 960 | /// Reads the on-chip temperature sensor |
davidr99 | 0:ab4e012489ef | 961 | /// \param[in] tsrange Specifies the temperature range to use. One of RH_RF22_TSRANGE_* |
davidr99 | 0:ab4e012489ef | 962 | /// \param[in] tvoffs Specifies the temperature value offset. This is actually signed value |
davidr99 | 0:ab4e012489ef | 963 | /// added to the measured temperature value |
davidr99 | 0:ab4e012489ef | 964 | /// \return The measured temperature. |
davidr99 | 0:ab4e012489ef | 965 | uint8_t temperatureRead(uint8_t tsrange = RH_RF22_TSRANGE_M64_64C, uint8_t tvoffs = 0); |
davidr99 | 0:ab4e012489ef | 966 | |
davidr99 | 0:ab4e012489ef | 967 | /// Reads the wakeup timer value in registers RH_RF22_REG_17_WAKEUP_TIMER_VALUE1 |
davidr99 | 0:ab4e012489ef | 968 | /// and RH_RF22_REG_18_WAKEUP_TIMER_VALUE2 |
davidr99 | 0:ab4e012489ef | 969 | /// \return The wakeup timer value |
davidr99 | 0:ab4e012489ef | 970 | uint16_t wutRead(); |
davidr99 | 0:ab4e012489ef | 971 | |
davidr99 | 0:ab4e012489ef | 972 | /// Sets the wakeup timer period registers RH_RF22_REG_14_WAKEUP_TIMER_PERIOD1, |
davidr99 | 0:ab4e012489ef | 973 | /// RH_RF22_REG_15_WAKEUP_TIMER_PERIOD2 and RH_RF22_R<EG_16_WAKEUP_TIMER_PERIOD3 |
davidr99 | 0:ab4e012489ef | 974 | /// \param[in] wtm Wakeup timer mantissa value |
davidr99 | 0:ab4e012489ef | 975 | /// \param[in] wtr Wakeup timer exponent R value |
davidr99 | 0:ab4e012489ef | 976 | /// \param[in] wtd Wakeup timer exponent D value |
davidr99 | 0:ab4e012489ef | 977 | void setWutPeriod(uint16_t wtm, uint8_t wtr = 0, uint8_t wtd = 0); |
davidr99 | 0:ab4e012489ef | 978 | |
davidr99 | 0:ab4e012489ef | 979 | /// Sets the transmitter and receiver centre frequency |
davidr99 | 0:ab4e012489ef | 980 | /// \param[in] centre Frequency in MHz. 240.0 to 960.0. Caution, some versions of RH_RF22 and derivatives |
davidr99 | 0:ab4e012489ef | 981 | /// implemented more restricted frequency ranges. |
davidr99 | 0:ab4e012489ef | 982 | /// \param[in] afcPullInRange Sets the AF Pull In Range in MHz. Defaults to 0.05MHz (50kHz). |
davidr99 | 0:ab4e012489ef | 983 | /// Range is 0.0 to 0.159375 |
davidr99 | 0:ab4e012489ef | 984 | /// for frequencies 240.0 to 480MHz, and 0.0 to 0.318750MHz for frequencies 480.0 to 960MHz, |
davidr99 | 0:ab4e012489ef | 985 | /// \return true if the selected frquency centre + (fhch * fhs) is within range and the afcPullInRange |
davidr99 | 0:ab4e012489ef | 986 | /// is within range |
davidr99 | 0:ab4e012489ef | 987 | bool setFrequency(float centre, float afcPullInRange = 0.05); |
davidr99 | 0:ab4e012489ef | 988 | |
davidr99 | 0:ab4e012489ef | 989 | /// Sets the frequency hopping step size. |
davidr99 | 0:ab4e012489ef | 990 | /// \param[in] fhs Frequency Hopping step size in 10kHz increments |
davidr99 | 0:ab4e012489ef | 991 | /// \return true if centre + (fhch * fhs) is within limits |
davidr99 | 0:ab4e012489ef | 992 | bool setFHStepSize(uint8_t fhs); |
davidr99 | 0:ab4e012489ef | 993 | |
davidr99 | 0:ab4e012489ef | 994 | /// Sets the frequncy hopping channel. Adds fhch * fhs to centre frequency |
davidr99 | 0:ab4e012489ef | 995 | /// \param[in] fhch The channel number |
davidr99 | 0:ab4e012489ef | 996 | /// \return true if the selected frquency centre + (fhch * fhs) is within range |
davidr99 | 0:ab4e012489ef | 997 | bool setFHChannel(uint8_t fhch); |
davidr99 | 0:ab4e012489ef | 998 | |
davidr99 | 0:ab4e012489ef | 999 | /// Reads and returns the current RSSI value from register RH_RF22_REG_26_RSSI. Caution: this is |
davidr99 | 0:ab4e012489ef | 1000 | /// in internal units (see figure 31 of RFM22B/23B documentation), not in dBm. If you want to find the RSSI in dBm |
davidr99 | 0:ab4e012489ef | 1001 | /// of the last received message, use lastRssi() instead. |
davidr99 | 0:ab4e012489ef | 1002 | /// \return The current RSSI value |
davidr99 | 0:ab4e012489ef | 1003 | uint8_t rssiRead(); |
davidr99 | 0:ab4e012489ef | 1004 | |
davidr99 | 0:ab4e012489ef | 1005 | /// Reads and returns the current EZMAC value from register RH_RF22_REG_31_EZMAC_STATUS |
davidr99 | 0:ab4e012489ef | 1006 | /// \return The current EZMAC value |
davidr99 | 0:ab4e012489ef | 1007 | uint8_t ezmacStatusRead(); |
davidr99 | 0:ab4e012489ef | 1008 | |
davidr99 | 0:ab4e012489ef | 1009 | /// Sets the parameters for the RH_RF22 Idle mode in register RH_RF22_REG_07_OPERATING_MODE. |
davidr99 | 0:ab4e012489ef | 1010 | /// Idle mode is the mode the RH_RF22 will be in when not transmitting or receiving. The default idle mode |
davidr99 | 0:ab4e012489ef | 1011 | /// is RH_RF22_XTON ie READY mode. |
davidr99 | 0:ab4e012489ef | 1012 | /// \param[in] mode Mask of mode bits, using RH_RF22_SWRES, RH_RF22_ENLBD, RH_RF22_ENWT, |
davidr99 | 0:ab4e012489ef | 1013 | /// RH_RF22_X32KSEL, RH_RF22_PLLON, RH_RF22_XTON. |
davidr99 | 0:ab4e012489ef | 1014 | void setOpMode(uint8_t mode); |
davidr99 | 0:ab4e012489ef | 1015 | |
davidr99 | 0:ab4e012489ef | 1016 | /// If current mode is Rx or Tx changes it to Idle. If the transmitter or receiver is running, |
davidr99 | 0:ab4e012489ef | 1017 | /// disables them. |
davidr99 | 0:ab4e012489ef | 1018 | void setModeIdle(); |
davidr99 | 0:ab4e012489ef | 1019 | |
davidr99 | 0:ab4e012489ef | 1020 | /// If current mode is Tx or Idle, changes it to Rx. |
davidr99 | 0:ab4e012489ef | 1021 | /// Starts the receiver in the RH_RF22. |
davidr99 | 0:ab4e012489ef | 1022 | void setModeRx(); |
davidr99 | 0:ab4e012489ef | 1023 | |
davidr99 | 0:ab4e012489ef | 1024 | /// If current mode is Rx or Idle, changes it to Rx. |
davidr99 | 0:ab4e012489ef | 1025 | /// Starts the transmitter in the RH_RF22. |
davidr99 | 0:ab4e012489ef | 1026 | void setModeTx(); |
davidr99 | 0:ab4e012489ef | 1027 | |
davidr99 | 0:ab4e012489ef | 1028 | /// Sets the transmitter power output level in register RH_RF22_REG_6D_TX_POWER. |
davidr99 | 0:ab4e012489ef | 1029 | /// Be a good neighbour and set the lowest power level you need. |
davidr99 | 0:ab4e012489ef | 1030 | /// After init(), the power will be set to RH_RF22::RH_RF22_TXPOW_8DBM on RF22B |
davidr99 | 0:ab4e012489ef | 1031 | /// or RH_RF22_RF23B_TXPOW_1DBM on an RF23B. |
davidr99 | 0:ab4e012489ef | 1032 | /// The highest power available on RF22B is RH_RF22::RH_RF22_TXPOW_20DBM (20dBm). |
davidr99 | 0:ab4e012489ef | 1033 | /// The highest power available on RF23B is RH_RF22::RH_RF22_RF23B_TXPOW_13DBM (13dBm). |
davidr99 | 0:ab4e012489ef | 1034 | /// Higher powers are available on RF23BP (using RH_RF22_RF23BP_TXPOW_*), |
davidr99 | 0:ab4e012489ef | 1035 | /// and then only with an adequate power supply. See comments above. |
davidr99 | 0:ab4e012489ef | 1036 | /// Caution: In some countries you may only select certain higher power levels if you |
davidr99 | 0:ab4e012489ef | 1037 | /// are also using frequency hopping. Make sure you are aware of the legal |
davidr99 | 0:ab4e012489ef | 1038 | /// limitations and regulations in your region. |
davidr99 | 0:ab4e012489ef | 1039 | /// \param[in] power Transmitter power level, one of RH_RF22_*TXPOW_* |
davidr99 | 0:ab4e012489ef | 1040 | void setTxPower(uint8_t power); |
davidr99 | 0:ab4e012489ef | 1041 | |
davidr99 | 0:ab4e012489ef | 1042 | /// Sets all the registered required to configure the data modem in the RH_RF22, including the data rate, |
davidr99 | 0:ab4e012489ef | 1043 | /// bandwidths etc. You cas use this to configure the modem with custom configuraitons if none of the |
davidr99 | 0:ab4e012489ef | 1044 | /// canned configurations in ModemConfigChoice suit you. |
davidr99 | 0:ab4e012489ef | 1045 | /// \param[in] config A ModemConfig structure containing values for the modem configuration registers. |
davidr99 | 0:ab4e012489ef | 1046 | void setModemRegisters(const ModemConfig* config); |
davidr99 | 0:ab4e012489ef | 1047 | |
davidr99 | 0:ab4e012489ef | 1048 | /// Select one of the predefined modem configurations. If you need a modem configuration not provided |
davidr99 | 0:ab4e012489ef | 1049 | /// here, use setModemRegisters() with your own ModemConfig. |
davidr99 | 0:ab4e012489ef | 1050 | /// \param[in] index The configuration choice. |
davidr99 | 0:ab4e012489ef | 1051 | /// \return true if index is a valid choice. |
davidr99 | 0:ab4e012489ef | 1052 | bool setModemConfig(ModemConfigChoice index); |
davidr99 | 0:ab4e012489ef | 1053 | |
davidr99 | 0:ab4e012489ef | 1054 | /// Starts the receiver and checks whether a received message is available. |
davidr99 | 0:ab4e012489ef | 1055 | /// This can be called multiple times in a timeout loop |
davidr99 | 0:ab4e012489ef | 1056 | /// \return true if a complete, valid message has been received and is able to be retrieved by |
davidr99 | 0:ab4e012489ef | 1057 | /// recv() |
davidr99 | 0:ab4e012489ef | 1058 | bool available(); |
davidr99 | 0:ab4e012489ef | 1059 | |
davidr99 | 0:ab4e012489ef | 1060 | /// Turns the receiver on if it not already on. |
davidr99 | 0:ab4e012489ef | 1061 | /// If there is a valid message available, copy it to buf and return true |
davidr99 | 0:ab4e012489ef | 1062 | /// else return false. |
davidr99 | 0:ab4e012489ef | 1063 | /// If a message is copied, *len is set to the length (Caution, 0 length messages are permitted). |
davidr99 | 0:ab4e012489ef | 1064 | /// You should be sure to call this function frequently enough to not miss any messages |
davidr99 | 0:ab4e012489ef | 1065 | /// It is recommended that you call it in your main loop. |
davidr99 | 0:ab4e012489ef | 1066 | /// \param[in] buf Location to copy the received message |
davidr99 | 0:ab4e012489ef | 1067 | /// \param[in,out] len Pointer to available space in buf. Set to the actual number of octets copied. |
davidr99 | 0:ab4e012489ef | 1068 | /// \return true if a valid message was copied to buf |
davidr99 | 0:ab4e012489ef | 1069 | bool recv(uint8_t* buf, uint8_t* len); |
davidr99 | 0:ab4e012489ef | 1070 | |
davidr99 | 0:ab4e012489ef | 1071 | /// Waits until any previous transmit packet is finished being transmitted with waitPacketSent(). |
davidr99 | 0:ab4e012489ef | 1072 | /// Then loads a message into the transmitter and starts the transmitter. Note that a message length |
davidr99 | 0:ab4e012489ef | 1073 | /// of 0 is NOT permitted. |
davidr99 | 0:ab4e012489ef | 1074 | /// \param[in] data Array of data to be sent |
davidr99 | 0:ab4e012489ef | 1075 | /// \param[in] len Number of bytes of data to send (> 0) |
davidr99 | 0:ab4e012489ef | 1076 | /// \return true if the message length was valid and it was correctly queued for transmit |
davidr99 | 0:ab4e012489ef | 1077 | bool send(const uint8_t* data, uint8_t len); |
davidr99 | 0:ab4e012489ef | 1078 | |
davidr99 | 0:ab4e012489ef | 1079 | /// Sets the length of the preamble |
davidr99 | 0:ab4e012489ef | 1080 | /// in 4-bit nibbles. |
davidr99 | 0:ab4e012489ef | 1081 | /// Caution: this should be set to the same |
davidr99 | 0:ab4e012489ef | 1082 | /// value on all nodes in your network. Default is 8. |
davidr99 | 0:ab4e012489ef | 1083 | /// Sets the message preamble length in RH_RF22_REG_34_PREAMBLE_LENGTH |
davidr99 | 0:ab4e012489ef | 1084 | /// \param[in] nibbles Preamble length in nibbles of 4 bits each. |
davidr99 | 0:ab4e012489ef | 1085 | void setPreambleLength(uint8_t nibbles); |
davidr99 | 0:ab4e012489ef | 1086 | |
davidr99 | 0:ab4e012489ef | 1087 | /// Sets the sync words for transmit and receive in registers RH_RF22_REG_36_SYNC_WORD3 |
davidr99 | 0:ab4e012489ef | 1088 | /// to RH_RF22_REG_39_SYNC_WORD0 |
davidr99 | 0:ab4e012489ef | 1089 | /// Caution: SyncWords should be set to the same |
davidr99 | 0:ab4e012489ef | 1090 | /// value on all nodes in your network. Nodes with different SyncWords set will never receive |
davidr99 | 0:ab4e012489ef | 1091 | /// each others messages, so different SyncWords can be used to isolate different |
davidr99 | 0:ab4e012489ef | 1092 | /// networks from each other. Default is { 0x2d, 0xd4 }. |
davidr99 | 0:ab4e012489ef | 1093 | /// \param[in] syncWords Array of sync words, 1 to 4 octets long |
davidr99 | 0:ab4e012489ef | 1094 | /// \param[in] len Number of sync words to set, 1 to 4. |
davidr99 | 0:ab4e012489ef | 1095 | void setSyncWords(const uint8_t* syncWords, uint8_t len); |
davidr99 | 0:ab4e012489ef | 1096 | |
davidr99 | 0:ab4e012489ef | 1097 | /// Tells the receiver to accept messages with any TO address, not just messages |
davidr99 | 0:ab4e012489ef | 1098 | /// addressed to thisAddress or the broadcast address |
davidr99 | 0:ab4e012489ef | 1099 | /// \param[in] promiscuous true if you wish to receive messages with any TO address |
davidr99 | 0:ab4e012489ef | 1100 | virtual void setPromiscuous(bool promiscuous); |
davidr99 | 0:ab4e012489ef | 1101 | |
davidr99 | 0:ab4e012489ef | 1102 | /// Sets the CRC polynomial to be used to generate the CRC for both receive and transmit |
davidr99 | 0:ab4e012489ef | 1103 | /// otherwise the default of CRC_16_IBM will be used. |
davidr99 | 0:ab4e012489ef | 1104 | /// \param[in] polynomial One of RH_RF22::CRCPolynomial choices CRC_* |
davidr99 | 0:ab4e012489ef | 1105 | /// \return true if polynomial is a valid option for this radio. |
davidr99 | 0:ab4e012489ef | 1106 | bool setCRCPolynomial(CRCPolynomial polynomial); |
davidr99 | 0:ab4e012489ef | 1107 | |
davidr99 | 0:ab4e012489ef | 1108 | /// Configures GPIO pins for reversed GPIO connections to the antenna switch. |
davidr99 | 0:ab4e012489ef | 1109 | /// Normally on RF22 modules, GPIO0(out) is connected to TX_ANT(in) to enable tx antenna during transmit |
davidr99 | 0:ab4e012489ef | 1110 | /// and GPIO1(out) is connected to RX_ANT(in) to enable rx antenna during receive. The RH_RF22 driver |
davidr99 | 0:ab4e012489ef | 1111 | /// configures the GPIO pins during init() so the antenna switch works as expected. |
davidr99 | 0:ab4e012489ef | 1112 | /// However, some RF22 modules, such as HAB-RFM22B-BOA HAB-RFM22B-BO, also Si4432 sold by Dorji.com via Tindie.com |
davidr99 | 0:ab4e012489ef | 1113 | /// have these GPIO pins reversed, so that GPIO0 is connected to RX_ANT. |
davidr99 | 0:ab4e012489ef | 1114 | /// Call this function with a true argument after init() and before transmitting |
davidr99 | 0:ab4e012489ef | 1115 | /// in order to configure the module for reversed GPIO pins. |
davidr99 | 0:ab4e012489ef | 1116 | /// \param[in] gpioReversed Set to true if your RF22 module has reversed GPIO antenna switch connections. |
davidr99 | 0:ab4e012489ef | 1117 | void setGpioReversed(bool gpioReversed = false); |
davidr99 | 0:ab4e012489ef | 1118 | |
davidr99 | 0:ab4e012489ef | 1119 | /// Returns the time in millis since the last preamble was received, and when the last |
davidr99 | 0:ab4e012489ef | 1120 | /// RSSI measurement was made. |
davidr99 | 0:ab4e012489ef | 1121 | uint32_t getLastPreambleTime(); |
davidr99 | 0:ab4e012489ef | 1122 | |
davidr99 | 0:ab4e012489ef | 1123 | /// The maximum message length supported by this driver |
davidr99 | 0:ab4e012489ef | 1124 | /// \return The maximum message length supported by this driver |
davidr99 | 0:ab4e012489ef | 1125 | uint8_t maxMessageLength(); |
davidr99 | 0:ab4e012489ef | 1126 | |
davidr99 | 0:ab4e012489ef | 1127 | /// Sets the radio into low-power sleep mode. |
davidr99 | 0:ab4e012489ef | 1128 | /// If successful, the transport will stay in sleep mode until woken by |
davidr99 | 0:ab4e012489ef | 1129 | /// changing mode it idle, transmit or receive (eg by calling send(), recv(), available() etc) |
davidr99 | 0:ab4e012489ef | 1130 | /// Caution: there is a time penalty as the radio takes a finite time to wake from sleep mode. |
davidr99 | 0:ab4e012489ef | 1131 | /// \return true if sleep mode was successfully entered. |
davidr99 | 0:ab4e012489ef | 1132 | virtual bool sleep(); |
davidr99 | 0:ab4e012489ef | 1133 | |
davidr99 | 0:ab4e012489ef | 1134 | protected: |
davidr99 | 0:ab4e012489ef | 1135 | /// This is a low level function to handle the interrupts for one instance of RH_RF22. |
davidr99 | 0:ab4e012489ef | 1136 | /// Called automatically by isr*() |
davidr99 | 0:ab4e012489ef | 1137 | /// Should not need to be called. |
davidr99 | 0:ab4e012489ef | 1138 | void handleInterrupt(); |
davidr99 | 0:ab4e012489ef | 1139 | |
davidr99 | 0:ab4e012489ef | 1140 | /// Clears the receiver buffer. |
davidr99 | 0:ab4e012489ef | 1141 | /// Internal use only |
davidr99 | 0:ab4e012489ef | 1142 | void clearRxBuf(); |
davidr99 | 0:ab4e012489ef | 1143 | |
davidr99 | 0:ab4e012489ef | 1144 | /// Clears the transmitter buffer |
davidr99 | 0:ab4e012489ef | 1145 | /// Internal use only |
davidr99 | 0:ab4e012489ef | 1146 | void clearTxBuf(); |
davidr99 | 0:ab4e012489ef | 1147 | |
davidr99 | 0:ab4e012489ef | 1148 | /// Fills the transmitter buffer with the data of a mesage to be sent |
davidr99 | 0:ab4e012489ef | 1149 | /// \param[in] data Array of data bytes to be sent (1 to 255) |
davidr99 | 0:ab4e012489ef | 1150 | /// \param[in] len Number of data bytes in data (> 0) |
davidr99 | 0:ab4e012489ef | 1151 | /// \return true if the message length is valid |
davidr99 | 0:ab4e012489ef | 1152 | bool fillTxBuf(const uint8_t* data, uint8_t len); |
davidr99 | 0:ab4e012489ef | 1153 | |
davidr99 | 0:ab4e012489ef | 1154 | /// Appends the transmitter buffer with the data of a mesage to be sent |
davidr99 | 0:ab4e012489ef | 1155 | /// \param[in] data Array of data bytes to be sent (0 to 255) |
davidr99 | 0:ab4e012489ef | 1156 | /// \param[in] len Number of data bytes in data |
davidr99 | 0:ab4e012489ef | 1157 | /// \return false if the resulting message would exceed RH_RF22_MAX_MESSAGE_LEN, else true |
davidr99 | 0:ab4e012489ef | 1158 | bool appendTxBuf(const uint8_t* data, uint8_t len); |
davidr99 | 0:ab4e012489ef | 1159 | |
davidr99 | 0:ab4e012489ef | 1160 | /// Internal function to load the next fragment of |
davidr99 | 0:ab4e012489ef | 1161 | /// the current message into the transmitter FIFO |
davidr99 | 0:ab4e012489ef | 1162 | /// Internal use only |
davidr99 | 0:ab4e012489ef | 1163 | void sendNextFragment(); |
davidr99 | 0:ab4e012489ef | 1164 | |
davidr99 | 0:ab4e012489ef | 1165 | /// function to copy the next fragment from |
davidr99 | 0:ab4e012489ef | 1166 | /// the receiver FIF) into the receiver buffer |
davidr99 | 0:ab4e012489ef | 1167 | void readNextFragment(); |
davidr99 | 0:ab4e012489ef | 1168 | |
davidr99 | 0:ab4e012489ef | 1169 | /// Clears the RF22 Rx and Tx FIFOs |
davidr99 | 0:ab4e012489ef | 1170 | /// Internal use only |
davidr99 | 0:ab4e012489ef | 1171 | void resetFifos(); |
davidr99 | 0:ab4e012489ef | 1172 | |
davidr99 | 0:ab4e012489ef | 1173 | /// Clears the RF22 Rx FIFO |
davidr99 | 0:ab4e012489ef | 1174 | /// Internal use only |
davidr99 | 0:ab4e012489ef | 1175 | void resetRxFifo(); |
davidr99 | 0:ab4e012489ef | 1176 | |
davidr99 | 0:ab4e012489ef | 1177 | /// Clears the RF22 Tx FIFO |
davidr99 | 0:ab4e012489ef | 1178 | /// Internal use only |
davidr99 | 0:ab4e012489ef | 1179 | void resetTxFifo(); |
davidr99 | 0:ab4e012489ef | 1180 | |
davidr99 | 0:ab4e012489ef | 1181 | /// This function will be called by handleInterrupt() if an RF22 external interrupt occurs. |
davidr99 | 0:ab4e012489ef | 1182 | /// This can only happen if external interrupts are enabled in the RF22 |
davidr99 | 0:ab4e012489ef | 1183 | /// (which they are not by default). |
davidr99 | 0:ab4e012489ef | 1184 | /// Subclasses may override this function to get control when an RF22 external interrupt occurs. |
davidr99 | 0:ab4e012489ef | 1185 | virtual void handleExternalInterrupt(); |
davidr99 | 0:ab4e012489ef | 1186 | |
davidr99 | 0:ab4e012489ef | 1187 | /// This function will be called by handleInterrupt() if an RF22 wakeup timer interrupt occurs. |
davidr99 | 0:ab4e012489ef | 1188 | /// This can only happen if wakeup timer interrupts are enabled in theRF22 |
davidr99 | 0:ab4e012489ef | 1189 | /// (which they are not by default). |
davidr99 | 0:ab4e012489ef | 1190 | /// Subclasses may override this function to get control when an RF22 wakeup timer interrupt occurs. |
davidr99 | 0:ab4e012489ef | 1191 | virtual void handleWakeupTimerInterrupt(); |
davidr99 | 0:ab4e012489ef | 1192 | |
davidr99 | 0:ab4e012489ef | 1193 | /// Start the transmission of the contents |
davidr99 | 0:ab4e012489ef | 1194 | /// of the Tx buffer |
davidr99 | 0:ab4e012489ef | 1195 | void startTransmit(); |
davidr99 | 0:ab4e012489ef | 1196 | |
davidr99 | 0:ab4e012489ef | 1197 | /// ReStart the transmission of the contents |
davidr99 | 0:ab4e012489ef | 1198 | /// of the Tx buffer after a atransmission failure |
davidr99 | 0:ab4e012489ef | 1199 | void restartTransmit(); |
davidr99 | 0:ab4e012489ef | 1200 | |
davidr99 | 0:ab4e012489ef | 1201 | void setThisAddress(uint8_t thisAddress); |
davidr99 | 0:ab4e012489ef | 1202 | |
davidr99 | 0:ab4e012489ef | 1203 | /// Sets the radio operating mode for the case when the driver is idle (ie not |
davidr99 | 0:ab4e012489ef | 1204 | /// transmitting or receiving), allowing you to control the idle mode power requirements |
davidr99 | 0:ab4e012489ef | 1205 | /// at the expense of slower transitions to transmit and receive modes. |
davidr99 | 0:ab4e012489ef | 1206 | /// By default, the idle mode is RH_RF22_XTON, |
davidr99 | 0:ab4e012489ef | 1207 | /// but eg setIdleMode(RH_RF22_PLL) will provide a much lower |
davidr99 | 0:ab4e012489ef | 1208 | /// idle current but slower transitions. Call this function after init(). |
davidr99 | 0:ab4e012489ef | 1209 | /// \param[in] idleMode The chip operating mode to use when the driver is idle. One of the valid definitions for RH_RF22_REG_07_OPERATING_MODE |
davidr99 | 0:ab4e012489ef | 1210 | void setIdleMode(uint8_t idleMode); |
davidr99 | 0:ab4e012489ef | 1211 | |
davidr99 | 0:ab4e012489ef | 1212 | protected: |
davidr99 | 0:ab4e012489ef | 1213 | /// Low level interrupt service routine for RF22 connected to interrupt 0 |
davidr99 | 0:ab4e012489ef | 1214 | static void isr0(); |
davidr99 | 0:ab4e012489ef | 1215 | |
davidr99 | 0:ab4e012489ef | 1216 | /// Low level interrupt service routine for RF22 connected to interrupt 1 |
davidr99 | 0:ab4e012489ef | 1217 | static void isr1(); |
davidr99 | 0:ab4e012489ef | 1218 | |
davidr99 | 0:ab4e012489ef | 1219 | /// Low level interrupt service routine for RF22 connected to interrupt 1 |
davidr99 | 0:ab4e012489ef | 1220 | static void isr2(); |
davidr99 | 0:ab4e012489ef | 1221 | |
davidr99 | 0:ab4e012489ef | 1222 | /// Array of instances connected to interrupts 0 and 1 |
davidr99 | 0:ab4e012489ef | 1223 | static RH_RF22* _deviceForInterrupt[]; |
davidr99 | 0:ab4e012489ef | 1224 | |
davidr99 | 0:ab4e012489ef | 1225 | /// Index of next interrupt number to use in _deviceForInterrupt |
davidr99 | 0:ab4e012489ef | 1226 | static uint8_t _interruptCount; |
davidr99 | 0:ab4e012489ef | 1227 | |
davidr99 | 0:ab4e012489ef | 1228 | #if (RH_PLATFORM == RH_PLATFORM_MBED) |
davidr99 | 0:ab4e012489ef | 1229 | /// The configured interrupt pin connected to this instance |
davidr99 | 0:ab4e012489ef | 1230 | InterruptIn _interruptPin; |
davidr99 | 0:ab4e012489ef | 1231 | #else |
davidr99 | 0:ab4e012489ef | 1232 | /// The configured interrupt pin connected to this instance |
davidr99 | 0:ab4e012489ef | 1233 | uint8_t _interruptPin; |
davidr99 | 0:ab4e012489ef | 1234 | #endif |
davidr99 | 0:ab4e012489ef | 1235 | |
davidr99 | 0:ab4e012489ef | 1236 | /// The index into _deviceForInterrupt[] for this device (if an interrupt is already allocated) |
davidr99 | 0:ab4e012489ef | 1237 | /// else 0xff |
davidr99 | 0:ab4e012489ef | 1238 | uint8_t _myInterruptIndex; |
davidr99 | 0:ab4e012489ef | 1239 | |
davidr99 | 0:ab4e012489ef | 1240 | /// The radio mode to use when mode is idle |
davidr99 | 0:ab4e012489ef | 1241 | uint8_t _idleMode; |
davidr99 | 0:ab4e012489ef | 1242 | |
davidr99 | 0:ab4e012489ef | 1243 | /// The device type reported by the RF22 |
davidr99 | 0:ab4e012489ef | 1244 | uint8_t _deviceType; |
davidr99 | 0:ab4e012489ef | 1245 | |
davidr99 | 0:ab4e012489ef | 1246 | /// The selected CRC polynomial |
davidr99 | 0:ab4e012489ef | 1247 | CRCPolynomial _polynomial; |
davidr99 | 0:ab4e012489ef | 1248 | |
davidr99 | 0:ab4e012489ef | 1249 | // These volatile members may get changed in the interrupt service routine |
davidr99 | 0:ab4e012489ef | 1250 | /// Number of octets in the receiver buffer |
davidr99 | 0:ab4e012489ef | 1251 | volatile uint8_t _bufLen; |
davidr99 | 0:ab4e012489ef | 1252 | |
davidr99 | 0:ab4e012489ef | 1253 | /// The receiver buffer |
davidr99 | 0:ab4e012489ef | 1254 | uint8_t _buf[RH_RF22_MAX_MESSAGE_LEN]; |
davidr99 | 0:ab4e012489ef | 1255 | |
davidr99 | 0:ab4e012489ef | 1256 | /// True when there is a valid message in the Rx buffer |
davidr99 | 0:ab4e012489ef | 1257 | volatile bool _rxBufValid; |
davidr99 | 0:ab4e012489ef | 1258 | |
davidr99 | 0:ab4e012489ef | 1259 | /// Index into TX buffer of the next to send chunk |
davidr99 | 0:ab4e012489ef | 1260 | volatile uint8_t _txBufSentIndex; |
davidr99 | 0:ab4e012489ef | 1261 | |
davidr99 | 0:ab4e012489ef | 1262 | /// Time in millis since the last preamble was received (and the last time the RSSI was measured) |
davidr99 | 0:ab4e012489ef | 1263 | uint32_t _lastPreambleTime; |
davidr99 | 0:ab4e012489ef | 1264 | }; |
davidr99 | 0:ab4e012489ef | 1265 | |
davidr99 | 0:ab4e012489ef | 1266 | /// @example rf22_client.pde |
davidr99 | 0:ab4e012489ef | 1267 | /// @example rf22_server.pde |
davidr99 | 0:ab4e012489ef | 1268 | |
davidr99 | 0:ab4e012489ef | 1269 | #endif |