Unfinished v0.7, added bearing detection
Fork of Pi_Swarm_Library_v06_alpha by
alpha433.h@9:7a4fc1d7e484, 2014-02-18 (annotated)
- Committer:
- jah128
- Date:
- Tue Feb 18 17:14:03 2014 +0000
- Revision:
- 9:7a4fc1d7e484
- Parent:
- 8:08dec9c7d3f6
- Child:
- 11:5ebcb52726cf
Draft v0.6 Library (unfinished)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jah128 | 4:52b3e4c5a425 | 1 | /******************************************************************************************* |
jah128 | 4:52b3e4c5a425 | 2 | * |
jah128 | 8:08dec9c7d3f6 | 3 | * University of York Robot Lab Pi Swarm Library: 433MHz Alpha Transceiver Driver |
jah128 | 0:9ffe8ebd1c40 | 4 | * |
jah128 | 0:9ffe8ebd1c40 | 5 | * (C) Dr James Hilder, Dept. Electronics & Computer Science, University of York |
jah128 | 1:b067a08ff54e | 6 | * |
jah128 | 9:7a4fc1d7e484 | 7 | * Version 0.6 February 2014 |
jah128 | 0:9ffe8ebd1c40 | 8 | * |
jah128 | 0:9ffe8ebd1c40 | 9 | * Designed for use with the Pi Swarm Board (enhanced MBED sensor board) v1.2 |
jah128 | 0:9ffe8ebd1c40 | 10 | * |
jah128 | 4:52b3e4c5a425 | 11 | ******************************************************************************************/ |
jah128 | 0:9ffe8ebd1c40 | 12 | |
jah128 | 0:9ffe8ebd1c40 | 13 | #ifndef ALPHA433_H |
jah128 | 0:9ffe8ebd1c40 | 14 | #define ALPHA433_H |
jah128 | 0:9ffe8ebd1c40 | 15 | |
jah128 | 0:9ffe8ebd1c40 | 16 | |
jah128 | 0:9ffe8ebd1c40 | 17 | // |
jah128 | 0:9ffe8ebd1c40 | 18 | // Defines |
jah128 | 0:9ffe8ebd1c40 | 19 | // |
jah128 | 0:9ffe8ebd1c40 | 20 | #define ALPHA433_FREQUENCY_315 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 21 | #define ALPHA433_FREQUENCY_433 0x0010 |
jah128 | 0:9ffe8ebd1c40 | 22 | #define ALPHA433_FREQUENCY_868 0x0020 |
jah128 | 0:9ffe8ebd1c40 | 23 | #define ALPHA433_FREQUENCY_915 0x0030 |
jah128 | 0:9ffe8ebd1c40 | 24 | #define ALPHA433_CRYSTAL_LOAD_85 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 25 | #define ALPHA433_CRYSTAL_LOAD_90 0x0001 |
jah128 | 0:9ffe8ebd1c40 | 26 | #define ALPHA433_CRYSTAL_LOAD_95 0x0002 |
jah128 | 0:9ffe8ebd1c40 | 27 | #define ALPHA433_CRYSTAL_LOAD_100 0x0003 |
jah128 | 0:9ffe8ebd1c40 | 28 | #define ALPHA433_CRYSTAL_LOAD_105 0x0004 |
jah128 | 0:9ffe8ebd1c40 | 29 | #define ALPHA433_CRYSTAL_LOAD_110 0x0005 |
jah128 | 0:9ffe8ebd1c40 | 30 | #define ALPHA433_CRYSTAL_LOAD_115 0x0006 |
jah128 | 0:9ffe8ebd1c40 | 31 | #define ALPHA433_CRYSTAL_LOAD_120 0x0007 |
jah128 | 0:9ffe8ebd1c40 | 32 | #define ALPHA433_CRYSTAL_LOAD_125 0x0008 |
jah128 | 0:9ffe8ebd1c40 | 33 | #define ALPHA433_CRYSTAL_LOAD_130 0x0009 |
jah128 | 0:9ffe8ebd1c40 | 34 | #define ALPHA433_CRYSTAL_LOAD_135 0x000A |
jah128 | 0:9ffe8ebd1c40 | 35 | #define ALPHA433_CRYSTAL_LOAD_140 0x000B |
jah128 | 0:9ffe8ebd1c40 | 36 | #define ALPHA433_CRYSTAL_LOAD_145 0x000C |
jah128 | 0:9ffe8ebd1c40 | 37 | #define ALPHA433_CRYSTAL_LOAD_150 0x000D |
jah128 | 0:9ffe8ebd1c40 | 38 | #define ALPHA433_CRYSTAL_LOAD_155 0x000E |
jah128 | 0:9ffe8ebd1c40 | 39 | #define ALPHA433_CRYSTAL_LOAD_160 0x000F |
jah128 | 0:9ffe8ebd1c40 | 40 | #define ALPHA433_USE_FIFO_YES 0x00C0 |
jah128 | 0:9ffe8ebd1c40 | 41 | #define ALPHA433_USE_FIFO_NO 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 42 | #define ALPHA433_PIN20_INTERRUPT_IN 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 43 | #define ALPHA433_PIN20_VDI_OUT 0x0400 |
jah128 | 0:9ffe8ebd1c40 | 44 | #define ALPHA433_VDI_RESPONSE_FAST 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 45 | #define ALPHA433_VDI_RESPONSE_MEDIUM 0x0100 |
jah128 | 0:9ffe8ebd1c40 | 46 | #define ALPHA433_VDI_RESPONSE_SLOW 0x0200 |
jah128 | 0:9ffe8ebd1c40 | 47 | #define ALPHA433_VDI_RESPONSE_ALWAYS 0x0300 |
jah128 | 0:9ffe8ebd1c40 | 48 | #define ALPHA433_BANDWIDTH_400 0x0020 |
jah128 | 0:9ffe8ebd1c40 | 49 | #define ALPHA433_BANDWIDTH_340 0x0040 |
jah128 | 0:9ffe8ebd1c40 | 50 | #define ALPHA433_BANDWIDTH_270 0x0060 |
jah128 | 0:9ffe8ebd1c40 | 51 | #define ALPHA433_BANDWIDTH_200 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 52 | #define ALPHA433_BANDWIDTH_134 0x00A0 |
jah128 | 0:9ffe8ebd1c40 | 53 | #define ALPHA433_BANDWIDTH_67 0x00C0 |
jah128 | 0:9ffe8ebd1c40 | 54 | #define ALPHA433_LNA_GAIN_0 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 55 | #define ALPHA433_LNA_GAIN_6 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 56 | #define ALPHA433_LNA_GAIN_14 0x0100 |
jah128 | 0:9ffe8ebd1c40 | 57 | #define ALPHA433_LNA_GAIN_20 0x0180 |
jah128 | 0:9ffe8ebd1c40 | 58 | #define ALPHA433_RSSI_103 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 59 | #define ALPHA433_RSSI_97 0x0001 |
jah128 | 0:9ffe8ebd1c40 | 60 | #define ALPHA433_RSSI_91 0x0002 |
jah128 | 0:9ffe8ebd1c40 | 61 | #define ALPHA433_RSSI_85 0x0003 |
jah128 | 0:9ffe8ebd1c40 | 62 | #define ALPHA433_RSSI_79 0x0004 |
jah128 | 0:9ffe8ebd1c40 | 63 | #define ALPHA433_RSSI_73 0x0005 |
jah128 | 0:9ffe8ebd1c40 | 64 | #define ALPHA433_RSSI_67 0x0006 |
jah128 | 0:9ffe8ebd1c40 | 65 | #define ALPHA433_RSSI_61 0x0007 |
jah128 | 0:9ffe8ebd1c40 | 66 | #define ALPHA433_CLOCK_RECOVERY_AUTO 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 67 | #define ALPHA433_CLOCK_RECOVERY_FAST 0x0040 |
jah128 | 0:9ffe8ebd1c40 | 68 | #define ALPHA433_CLOCK_RECOVERY_SLOW 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 69 | #define ALPHA433_FILTER_DIGITAL 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 70 | #define ALPHA433_FILTER_ANALOG 0x0010 |
jah128 | 0:9ffe8ebd1c40 | 71 | #define ALPHA433_DQD_0 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 72 | #define ALPHA433_DQD_1 0x0001 |
jah128 | 0:9ffe8ebd1c40 | 73 | #define ALPHA433_DQD_2 0x0002 |
jah128 | 0:9ffe8ebd1c40 | 74 | #define ALPHA433_DQD_3 0x0003 |
jah128 | 0:9ffe8ebd1c40 | 75 | #define ALPHA433_DQD_4 0x0004 |
jah128 | 0:9ffe8ebd1c40 | 76 | #define ALPHA433_DQD_5 0x0005 |
jah128 | 0:9ffe8ebd1c40 | 77 | #define ALPHA433_DQD_6 0x0006 |
jah128 | 0:9ffe8ebd1c40 | 78 | #define ALPHA433_DQD_7 0x0007 |
jah128 | 0:9ffe8ebd1c40 | 79 | #define ALPHA433_FIFO_LEVEL_0 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 80 | #define ALPHA433_FIFO_LEVEL_1 0x0010 |
jah128 | 0:9ffe8ebd1c40 | 81 | #define ALPHA433_FIFO_LEVEL_2 0x0020 |
jah128 | 0:9ffe8ebd1c40 | 82 | #define ALPHA433_FIFO_LEVEL_3 0x0030 |
jah128 | 0:9ffe8ebd1c40 | 83 | #define ALPHA433_FIFO_LEVEL_4 0x0040 |
jah128 | 0:9ffe8ebd1c40 | 84 | #define ALPHA433_FIFO_LEVEL_5 0x0050 |
jah128 | 0:9ffe8ebd1c40 | 85 | #define ALPHA433_FIFO_LEVEL_6 0x0060 |
jah128 | 0:9ffe8ebd1c40 | 86 | #define ALPHA433_FIFO_LEVEL_7 0x0070 |
jah128 | 0:9ffe8ebd1c40 | 87 | #define ALPHA433_FIFO_LEVEL_8 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 88 | #define ALPHA433_FIFO_LEVEL_9 0x0090 |
jah128 | 0:9ffe8ebd1c40 | 89 | #define ALPHA433_FIFO_LEVEL_10 0x00A0 |
jah128 | 0:9ffe8ebd1c40 | 90 | #define ALPHA433_FIFO_LEVEL_11 0x00B0 |
jah128 | 0:9ffe8ebd1c40 | 91 | #define ALPHA433_FIFO_LEVEL_12 0x00C0 |
jah128 | 0:9ffe8ebd1c40 | 92 | #define ALPHA433_FIFO_LEVEL_13 0x00D0 |
jah128 | 0:9ffe8ebd1c40 | 93 | #define ALPHA433_FIFO_LEVEL_14 0x00E0 |
jah128 | 0:9ffe8ebd1c40 | 94 | #define ALPHA433_FIFO_LEVEL_15 0x00F0 |
jah128 | 0:9ffe8ebd1c40 | 95 | #define ALPHA433_FIFO_FILL_PATTERN 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 96 | #define ALPHA433_FIFO_FILL_ALWAYS 0x0004 |
jah128 | 0:9ffe8ebd1c40 | 97 | #define ALPHA433_HI_SENS_RESET_ENABLE 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 98 | #define ALPHA433_HI_SENS_RESET_DISABLE 0x0001 |
jah128 | 0:9ffe8ebd1c40 | 99 | #define ALPHA433_AFC_MODE_NOAUTO 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 100 | #define ALPHA433_AFC_MODE_ONCE 0x0040 |
jah128 | 0:9ffe8ebd1c40 | 101 | #define ALPHA433_AFC_MODE_VDI 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 102 | #define ALPHA433_AFC_MODE_INDEPENDENT 0x00C0 |
jah128 | 0:9ffe8ebd1c40 | 103 | #define ALPHA433_AFC_RANGE_3TO4 0x0030 |
jah128 | 0:9ffe8ebd1c40 | 104 | #define ALPHA433_AFC_RANGE_7TO8 0x0020 |
jah128 | 0:9ffe8ebd1c40 | 105 | #define ALPHA433_AFC_RANGE_15TO16 0x0010 |
jah128 | 0:9ffe8ebd1c40 | 106 | #define ALPHA433_AFC_RANGE_NO_RES 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 107 | #define ALPHA433_AFC_FINE_ENABLE 0x0004 |
jah128 | 0:9ffe8ebd1c40 | 108 | #define ALPHA433_AFC_FINE_DISABLE 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 109 | #define ALPHA433_AFC_ENABLE 0x0003 |
jah128 | 0:9ffe8ebd1c40 | 110 | #define ALPHA433_AFC_DISABLE 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 111 | #define ALPHA433_MOD_POLARITY_P 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 112 | #define ALPHA433_MOD_POLARITY_N 0x0100 |
jah128 | 0:9ffe8ebd1c40 | 113 | #define ALPHA433_MOD_FREQUENCY_15 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 114 | #define ALPHA433_MOD_FREQUENCY_30 0x0010 |
jah128 | 0:9ffe8ebd1c40 | 115 | #define ALPHA433_MOD_FREQUENCY_45 0x0020 |
jah128 | 0:9ffe8ebd1c40 | 116 | #define ALPHA433_MOD_FREQUENCY_60 0x0030 |
jah128 | 0:9ffe8ebd1c40 | 117 | #define ALPHA433_MOD_FREQUENCY_75 0x0040 |
jah128 | 0:9ffe8ebd1c40 | 118 | #define ALPHA433_MOD_FREQUENCY_90 0x0050 |
jah128 | 0:9ffe8ebd1c40 | 119 | #define ALPHA433_MOD_FREQUENCY_105 0x0060 |
jah128 | 0:9ffe8ebd1c40 | 120 | #define ALPHA433_MOD_FREQUENCY_120 0x0070 |
jah128 | 0:9ffe8ebd1c40 | 121 | #define ALPHA433_MOD_FREQUENCY_135 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 122 | #define ALPHA433_MOD_FREQUENCY_150 0x0090 |
jah128 | 0:9ffe8ebd1c40 | 123 | #define ALPHA433_MOD_FREQUENCY_165 0x00A0 |
jah128 | 0:9ffe8ebd1c40 | 124 | #define ALPHA433_MOD_FREQUENCY_180 0x00B0 |
jah128 | 0:9ffe8ebd1c40 | 125 | #define ALPHA433_MOD_FREQUENCY_195 0x00C0 |
jah128 | 0:9ffe8ebd1c40 | 126 | #define ALPHA433_MOD_FREQUENCY_210 0x00D0 |
jah128 | 0:9ffe8ebd1c40 | 127 | #define ALPHA433_MOD_FREQUENCY_225 0x00E0 |
jah128 | 0:9ffe8ebd1c40 | 128 | #define ALPHA433_MOD_FREQUENCY_240 0x00F0 |
jah128 | 0:9ffe8ebd1c40 | 129 | #define ALPHA433_TX_POWER_0 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 130 | #define ALPHA433_TX_POWER_3 0x0001 |
jah128 | 0:9ffe8ebd1c40 | 131 | #define ALPHA433_TX_POWER_6 0x0002 |
jah128 | 0:9ffe8ebd1c40 | 132 | #define ALPHA433_TX_POWER_9 0x0003 |
jah128 | 0:9ffe8ebd1c40 | 133 | #define ALPHA433_TX_POWER_12 0x0004 |
jah128 | 0:9ffe8ebd1c40 | 134 | #define ALPHA433_TX_POWER_15 0x0005 |
jah128 | 0:9ffe8ebd1c40 | 135 | #define ALPHA433_TX_POWER_18 0x0006 |
jah128 | 0:9ffe8ebd1c40 | 136 | #define ALPHA433_TX_POWER_21 0x0007 |
jah128 | 0:9ffe8ebd1c40 | 137 | #define ALPHA433_CLK_OUT_1 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 138 | #define ALPHA433_CLK_OUT_125 0x0020 |
jah128 | 0:9ffe8ebd1c40 | 139 | #define ALPHA433_CLK_OUT_166 0x0040 |
jah128 | 0:9ffe8ebd1c40 | 140 | #define ALPHA433_CLK_OUT_2 0x0060 |
jah128 | 0:9ffe8ebd1c40 | 141 | #define ALPHA433_CLK_OUT_25 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 142 | #define ALPHA433_CLK_OUT_333 0x00A0 |
jah128 | 0:9ffe8ebd1c40 | 143 | #define ALPHA433_CLK_OUT_5 0x00C0 |
jah128 | 0:9ffe8ebd1c40 | 144 | #define ALPHA433_CLK_OUT_10 0x00E0 |
jah128 | 0:9ffe8ebd1c40 | 145 | #define ALPHA433_LOW_BAT22 0x0000 |
jah128 | 0:9ffe8ebd1c40 | 146 | #define ALPHA433_STATUS_TX_NEXT_BYTE 0x8000 |
jah128 | 0:9ffe8ebd1c40 | 147 | #define ALPHA433_STATUS_FIFO_LIMIT_REACHED 0x8000 |
jah128 | 0:9ffe8ebd1c40 | 148 | #define ALPHA433_STATUS_POWER_ON_RESET 0x4000 |
jah128 | 0:9ffe8ebd1c40 | 149 | #define ALPHA433_STATUS_RX_OVERFLOW 0x2000 |
jah128 | 0:9ffe8ebd1c40 | 150 | #define ALPHA433_STATUS_TX_UNDERRUN 0x2000 |
jah128 | 0:9ffe8ebd1c40 | 151 | #define ALPHA433_STATUS_WAKEUP 0x1000 |
jah128 | 0:9ffe8ebd1c40 | 152 | #define ALPHA433_STATUS_EXT 0x0800 |
jah128 | 0:9ffe8ebd1c40 | 153 | #define ALPHA433_STATUS_LOW_BATTERY 0x0400 |
jah128 | 0:9ffe8ebd1c40 | 154 | #define ALPHA433_STATUS_FIFO_EMPTY 0x0200 |
jah128 | 0:9ffe8ebd1c40 | 155 | #define ALPHA433_STATUS_STRONG_SIGNAL 0x0100 |
jah128 | 0:9ffe8ebd1c40 | 156 | #define ALPHA433_STATUS_RSSI 0x0100 |
jah128 | 0:9ffe8ebd1c40 | 157 | #define ALPHA433_STATUS_DQD 0x0080 |
jah128 | 0:9ffe8ebd1c40 | 158 | #define ALPHA433_STATUS_CLOCK_LOCKED 0x0040 |
jah128 | 0:9ffe8ebd1c40 | 159 | #define ALPHA433_TRANSMIT_OK 0 |
jah128 | 0:9ffe8ebd1c40 | 160 | #define ALPHA433_TRANSMIT_TIMEOUT 1 |
jah128 | 0:9ffe8ebd1c40 | 161 | #define ALPHA433_TRANSMIT_PARITY_ERROR 2 |
jah128 | 0:9ffe8ebd1c40 | 162 | #define ALPHA433_RECEIVE_OK 0 |
jah128 | 0:9ffe8ebd1c40 | 163 | #define ALPHA433_RECEIVE_TIMEOUT 1 |
jah128 | 0:9ffe8ebd1c40 | 164 | #define ALPHA433_RECEIVE_PARITY_ERROR 2 |
jah128 | 0:9ffe8ebd1c40 | 165 | #define ALPHA433_NODATA 0 |
jah128 | 0:9ffe8ebd1c40 | 166 | #define ALPHA433_DATA_AVAIABLE 1 |
jah128 | 0:9ffe8ebd1c40 | 167 | #define ALPHA433_MODE_TRANSMITTING 1 |
jah128 | 0:9ffe8ebd1c40 | 168 | #define ALPHA433_MODE_RECEIVING 2 |
jah128 | 0:9ffe8ebd1c40 | 169 | #define ALPHA433_MODE_SWITCHING 0 |
jah128 | 0:9ffe8ebd1c40 | 170 | |
jah128 | 0:9ffe8ebd1c40 | 171 | // ----------------------------- default user configuration -------------------------------- |
jah128 | 0:9ffe8ebd1c40 | 172 | |
jah128 | 0:9ffe8ebd1c40 | 173 | #define ALPHA433_FREQUENCY ALPHA433_FREQUENCY_433 |
jah128 | 0:9ffe8ebd1c40 | 174 | #define ALPHA433_CRYSTAL_LOAD ALPHA433_CRYSTAL_LOAD_100 |
jah128 | 0:9ffe8ebd1c40 | 175 | #define ALPHA433_USE_FIFO ALPHA433_USE_FIFO_YES |
jah128 | 0:9ffe8ebd1c40 | 176 | #define ALPHA433_PIN20 ALPHA433_PIN20_INTERRUPT_IN |
jah128 | 0:9ffe8ebd1c40 | 177 | #define ALPHA433_VDI_RESPONSE ALPHA433_VDI_RESPONSE_SLOW |
jah128 | 0:9ffe8ebd1c40 | 178 | #define ALPHA433_BANDWIDTH ALPHA433_BANDWIDTH_134 |
jah128 | 0:9ffe8ebd1c40 | 179 | #define ALPHA433_LNA_GAIN ALPHA433_LNA_GAIN_0 |
jah128 | 0:9ffe8ebd1c40 | 180 | #define ALPHA433_RSSI ALPHA433_RSSI_97 |
jah128 | 0:9ffe8ebd1c40 | 181 | #define ALPHA433_CLOCK_RECOVERY ALPHA433_CLOCK_RECOVERY_SLOW |
jah128 | 0:9ffe8ebd1c40 | 182 | #define ALPHA433_FILTER ALPHA433_FILTER_DIGITAL |
jah128 | 0:9ffe8ebd1c40 | 183 | #define ALPHA433_DQD ALPHA433_DQD_4 |
jah128 | 0:9ffe8ebd1c40 | 184 | #define ALPHA433_FIFO_LEVEL ALPHA433_FIFO_LEVEL_8 |
jah128 | 0:9ffe8ebd1c40 | 185 | #define ALPHA433_FIFO_FILL ALPHA433_FIFO_FILL_PATTERN |
jah128 | 0:9ffe8ebd1c40 | 186 | #define ALPHA433_HI_SENS_RESET ALPHA433_HI_SENS_RESET_DISABLE |
jah128 | 0:9ffe8ebd1c40 | 187 | #define ALPHA433_AFC_MODE ALPHA433_AFC_MODE_INDEPENDENT |
jah128 | 0:9ffe8ebd1c40 | 188 | #define ALPHA433_AFC_RANGE ALPHA433_AFC_RANGE_3TO4 |
jah128 | 0:9ffe8ebd1c40 | 189 | #define ALPHA433_AFC_FINE_MODE ALPHA433_AFC_FINE_DISABLE |
jah128 | 0:9ffe8ebd1c40 | 190 | #define ALPHA433_AFC ALPHA433_AFC_DISABLE |
jah128 | 0:9ffe8ebd1c40 | 191 | #define ALPHA433_MOD_POLARITY ALPHA433_MOD_POLARITY_P |
jah128 | 0:9ffe8ebd1c40 | 192 | #define ALPHA433_MOD_FREQUENCY ALPHA433_MOD_FREQUENCY_90 |
jah128 | 0:9ffe8ebd1c40 | 193 | #define ALPHA433_TX_POWER ALPHA433_TX_POWER_0 |
jah128 | 0:9ffe8ebd1c40 | 194 | #define ALPHA433_CLK_OUT ALPHA433_CLK_OUT_2 |
jah128 | 0:9ffe8ebd1c40 | 195 | #define ALPHA433_LOW_BAT ALPHA433_LOW_BAT22 |
jah128 | 0:9ffe8ebd1c40 | 196 | #define ALPHA433_TIMEOUT 100 |
jah128 | 0:9ffe8ebd1c40 | 197 | #define TIMEOUT 8.0 |
jah128 | 0:9ffe8ebd1c40 | 198 | |
jah128 | 1:b067a08ff54e | 199 | class Alpha433 : public Stream |
jah128 | 1:b067a08ff54e | 200 | { |
jah128 | 0:9ffe8ebd1c40 | 201 | |
jah128 | 0:9ffe8ebd1c40 | 202 | // Public Functions |
jah128 | 0:9ffe8ebd1c40 | 203 | |
jah128 | 0:9ffe8ebd1c40 | 204 | public: |
jah128 | 0:9ffe8ebd1c40 | 205 | |
jah128 | 1:b067a08ff54e | 206 | /** Create the alpha433 object connected to the default pins |
jah128 | 1:b067a08ff54e | 207 | * |
jah128 | 1:b067a08ff54e | 208 | * @param mosi pin - default is p5 |
jah128 | 1:b067a08ff54e | 209 | * @param miso pin - default is p6 |
jah128 | 1:b067a08ff54e | 210 | * @param sck pin - default is p7 |
jah128 | 1:b067a08ff54e | 211 | * @param fss pin - default is p8 |
jah128 | 1:b067a08ff54e | 212 | * @param nirq pin - default is p11 |
jah128 | 1:b067a08ff54e | 213 | */ |
jah128 | 0:9ffe8ebd1c40 | 214 | Alpha433(); |
jah128 | 1:b067a08ff54e | 215 | |
jah128 | 0:9ffe8ebd1c40 | 216 | /** Create the alpha433 object connected to specific pins |
jah128 | 0:9ffe8ebd1c40 | 217 | * |
jah128 | 0:9ffe8ebd1c40 | 218 | */ |
jah128 | 0:9ffe8ebd1c40 | 219 | Alpha433(PinName mosi, PinName miso, PinName sck, PinName fss, PinName nirq); |
jah128 | 0:9ffe8ebd1c40 | 220 | |
jah128 | 0:9ffe8ebd1c40 | 221 | |
jah128 | 0:9ffe8ebd1c40 | 222 | // Send a string to the RF transmitter |
jah128 | 1:b067a08ff54e | 223 | unsigned long sendString(char ucCount, char* ucBuffer); |
jah128 | 0:9ffe8ebd1c40 | 224 | |
jah128 | 0:9ffe8ebd1c40 | 225 | // Enable RF Transmitter |
jah128 | 1:b067a08ff54e | 226 | void enableTransmitter(void); |
jah128 | 0:9ffe8ebd1c40 | 227 | |
jah128 | 0:9ffe8ebd1c40 | 228 | // Disable RF Transmitter |
jah128 | 1:b067a08ff54e | 229 | void disableTransmitter(void); |
jah128 | 0:9ffe8ebd1c40 | 230 | |
jah128 | 0:9ffe8ebd1c40 | 231 | // Enable RF Receiver |
jah128 | 1:b067a08ff54e | 232 | void enableReceiver(void); |
jah128 | 0:9ffe8ebd1c40 | 233 | |
jah128 | 0:9ffe8ebd1c40 | 234 | // Disable RF Receiver |
jah128 | 1:b067a08ff54e | 235 | void disableReceiver(void); |
jah128 | 0:9ffe8ebd1c40 | 236 | |
jah128 | 0:9ffe8ebd1c40 | 237 | // SSI FiFo Clear |
jah128 | 1:b067a08ff54e | 238 | void clearBuffer(void); |
jah128 | 0:9ffe8ebd1c40 | 239 | |
jah128 | 0:9ffe8ebd1c40 | 240 | // Reset RF |
jah128 | 1:b067a08ff54e | 241 | void rf_reset(void); |
jah128 | 0:9ffe8ebd1c40 | 242 | |
jah128 | 0:9ffe8ebd1c40 | 243 | // Initialise RF |
jah128 | 1:b067a08ff54e | 244 | void rf_init(void); |
jah128 | 0:9ffe8ebd1c40 | 245 | |
jah128 | 0:9ffe8ebd1c40 | 246 | // RF Interrupt |
jah128 | 1:b067a08ff54e | 247 | void interrupt(void); |
jah128 | 0:9ffe8ebd1c40 | 248 | |
jah128 | 0:9ffe8ebd1c40 | 249 | // RF Set Datarate |
jah128 | 1:b067a08ff54e | 250 | void setDatarate(unsigned long ulValue); |
jah128 | 0:9ffe8ebd1c40 | 251 | |
jah128 | 0:9ffe8ebd1c40 | 252 | // RF Set Frequency |
jah128 | 1:b067a08ff54e | 253 | void setFrequency(unsigned long ulValue); |
jah128 | 0:9ffe8ebd1c40 | 254 | |
jah128 | 0:9ffe8ebd1c40 | 255 | // Enable RF Receiver FiFo fill |
jah128 | 1:b067a08ff54e | 256 | void enableFifoFill(void); |
jah128 | 0:9ffe8ebd1c40 | 257 | |
jah128 | 0:9ffe8ebd1c40 | 258 | // Disable RF Receiver FiFo fill |
jah128 | 1:b067a08ff54e | 259 | void disableFifoFill(void); |
jah128 | 0:9ffe8ebd1c40 | 260 | |
jah128 | 0:9ffe8ebd1c40 | 261 | // Handle new RF Data |
jah128 | 1:b067a08ff54e | 262 | void dataAvailable(char cCount, char* cBuffer); |
jah128 | 0:9ffe8ebd1c40 | 263 | |
jah128 | 0:9ffe8ebd1c40 | 264 | // Read status byte |
jah128 | 1:b067a08ff54e | 265 | int readStatusByte(); |
jah128 | 0:9ffe8ebd1c40 | 266 | |
jah128 | 0:9ffe8ebd1c40 | 267 | // Reset timeout: stops hanging on bad receive; resets alpha 433 |
jah128 | 1:b067a08ff54e | 268 | void timeout(); |
jah128 | 0:9ffe8ebd1c40 | 269 | |
jah128 | 0:9ffe8ebd1c40 | 270 | private : |
jah128 | 0:9ffe8ebd1c40 | 271 | |
jah128 | 4:52b3e4c5a425 | 272 | SPI _spi; |
jah128 | 0:9ffe8ebd1c40 | 273 | DigitalOut _fss; |
jah128 | 0:9ffe8ebd1c40 | 274 | DigitalIn _nirq_test; |
jah128 | 0:9ffe8ebd1c40 | 275 | InterruptIn _nirq; |
jah128 | 1:b067a08ff54e | 276 | |
jah128 | 1:b067a08ff54e | 277 | //Write a byte (data) to address |
jah128 | 0:9ffe8ebd1c40 | 278 | void _write(int address); |
jah128 | 0:9ffe8ebd1c40 | 279 | |
jah128 | 0:9ffe8ebd1c40 | 280 | //Read a byte (return val) from address |
jah128 | 0:9ffe8ebd1c40 | 281 | int _read(int address); |
jah128 | 1:b067a08ff54e | 282 | |
jah128 | 0:9ffe8ebd1c40 | 283 | virtual int _putc(int c); |
jah128 | 0:9ffe8ebd1c40 | 284 | virtual int _getc(); |
jah128 | 1:b067a08ff54e | 285 | |
jah128 | 0:9ffe8ebd1c40 | 286 | }; |
jah128 | 0:9ffe8ebd1c40 | 287 | |
jah128 | 9:7a4fc1d7e484 | 288 | |
jah128 | 9:7a4fc1d7e484 | 289 | // These counters are used to monitor the RF transceiver operations |
jah128 | 9:7a4fc1d7e484 | 290 | extern volatile int gi_RF_messages_sent; |
jah128 | 9:7a4fc1d7e484 | 291 | extern volatile int gi_RF_messages_received; |
jah128 | 9:7a4fc1d7e484 | 292 | extern volatile int gi_RF_bytes_sent; |
jah128 | 9:7a4fc1d7e484 | 293 | extern volatile int gi_RF_bytes_received; |
jah128 | 9:7a4fc1d7e484 | 294 | extern volatile int gi_RF_reset_cycles; |
jah128 | 9:7a4fc1d7e484 | 295 | extern volatile int gi_RF_received_length_error; |
jah128 | 9:7a4fc1d7e484 | 296 | extern volatile int gi_RF_received_checksum_failure; |
jah128 | 9:7a4fc1d7e484 | 297 | extern volatile int gi_RF_received_invalid_sender; |
jah128 | 9:7a4fc1d7e484 | 298 | extern volatile int gi_RF_received_invalid_target; |
jah128 | 9:7a4fc1d7e484 | 299 | extern volatile int gi_RF_received_invalid_format; |
jah128 | 9:7a4fc1d7e484 | 300 | extern volatile int gi_RF_received_not_for_me; |
jah128 | 9:7a4fc1d7e484 | 301 | extern volatile int gi_RF_received_broadcast; |
jah128 | 9:7a4fc1d7e484 | 302 | extern volatile int gi_RF_received_targeted_to_me; |
jah128 | 9:7a4fc1d7e484 | 303 | extern volatile int gi_RF_received_unexpected_response; |
jah128 | 9:7a4fc1d7e484 | 304 | extern volatile int gi_RF_received_invalid_response; |
jah128 | 9:7a4fc1d7e484 | 305 | extern volatile int gi_RF_commands_actioned; |
jah128 | 9:7a4fc1d7e484 | 306 | extern volatile int gi_RF_commands_invalid; |
jah128 | 9:7a4fc1d7e484 | 307 | extern volatile int gi_RF_commands_blocked; |
jah128 | 9:7a4fc1d7e484 | 308 | extern volatile int gi_RF_requests_actioned; |
jah128 | 9:7a4fc1d7e484 | 309 | extern volatile int gi_RF_commands_sent; |
jah128 | 9:7a4fc1d7e484 | 310 | extern volatile int gi_RF_responses_sent; |
jah128 | 9:7a4fc1d7e484 | 311 | |
jah128 | 0:9ffe8ebd1c40 | 312 | #endif // ALPHA433_H |