Remote RX using NUCLEO_L152RE + AUREL RTX-MID-3V (Sub1GHz module). This SW working in conjunction of the TX part that is: Remote TX using NUCLEO_L152RE + AUREL RTX-MID-3V (Sub1GHz module)

Dependencies:   mbed

Committer:
emcu
Date:
Sun Jan 08 01:51:51 2017 +0000
Revision:
0:691c0986df45
Remote RX using NUCLEO_L152RE + AUREL RTX-MID-3V (Sub1GHz module). ; This SW working in conjunction of the TX part that is: ; Remote TX using NUCLEO_L152RE + AUREL RTX-MID-3V (Sub1GHz module)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emcu 0:691c0986df45 1 /*
emcu 0:691c0986df45 2
emcu 0:691c0986df45 3 RX for remote Thermostat
emcu 0:691c0986df45 4
emcu 0:691c0986df45 5 By: www.emcu.eu
emcu 0:691c0986df45 6 Date: 04-January-2017
emcu 0:691c0986df45 7
emcu 0:691c0986df45 8 NUCLEO-L152RE and AUREL RTX-MID-3V (433.92 MHz - mod. ASK - 3Vcc)
emcu 0:691c0986df45 9
emcu 0:691c0986df45 10 AUREL RTX-MID-3V
emcu 0:691c0986df45 11 Italian AUREL manual is here: http://www.aurelwireless.com/wp-content/uploads/manuale-uso/650201033G_mu.pdf
emcu 0:691c0986df45 12 English AUREL manual is here: http://www.aurelwireless.com/en/radiomodem-data-transceivers/
emcu 0:691c0986df45 13 https://www.futurashop.it/index.php?route=product/product&filter_name=RTX-MID-3V&product_id=2788
emcu 0:691c0986df45 14
emcu 0:691c0986df45 15 CONNECTIONS from AUREL RTX-MID-3V to NUCLEO L152RE
emcu 0:691c0986df45 16 PIN1 Antenna 17cm
emcu 0:691c0986df45 17 PIN2 GND
emcu 0:691c0986df45 18 PIN4 TX connected to TX on NUCLEO L152RE
emcu 0:691c0986df45 19 PIN5 Tx/Rx connected to PA_10 on NUCLEO L152RE
emcu 0:691c0986df45 20 PIN6 ENABLE connected to PB_3 on NUCLEO L152RE
emcu 0:691c0986df45 21 PIN7 GND
emcu 0:691c0986df45 22 PIN8 Analog Out not connected
emcu 0:691c0986df45 23 PIN9 RX connected to RX on NUCLEO L152RE
emcu 0:691c0986df45 24 PIN10 VCC connected to 3,3V on NUCLEO L152RE
emcu 0:691c0986df45 25
emcu 0:691c0986df45 26 NOTE: between GND and VCC put a capacitor of 0,1uF and a second capacitor
emcu 0:691c0986df45 27 of 10uF
emcu 0:691c0986df45 28
emcu 0:691c0986df45 29
emcu 0:691c0986df45 30 ********** IMPORTANT IMPORTANT IMPORTANT IMPORTANT **********
emcu 0:691c0986df45 31
emcu 0:691c0986df45 32 This project use the USART for this reason you must do the below
emcu 0:691c0986df45 33 modifications on NUCLEO-L152RE, more info are here:
emcu 0:691c0986df45 34 http://www.emcu.it/NUCLEOevaBoards/U2andL152/U2andL152.html#USART2_for_communication_with_shield_or
emcu 0:691c0986df45 35
emcu 0:691c0986df45 36 Put a jumper on SB62 and on SB63
emcu 0:691c0986df45 37 Remove a 0 ohm resistor from SB13 and SB14
emcu 0:691c0986df45 38
emcu 0:691c0986df45 39 ATTENTION:
emcu 0:691c0986df45 40 After this modifications, you lost the possibility to use the virtual comm
emcu 0:691c0986df45 41 to connect the NUCLEO to the PC .
emcu 0:691c0986df45 42
emcu 0:691c0986df45 43 *************************************************************
emcu 0:691c0986df45 44
emcu 0:691c0986df45 45
emcu 0:691c0986df45 46 ********** EXPLANATIONS:
emcu 0:691c0986df45 47
emcu 0:691c0986df45 48 Build two boards one with RX software and another with TX software.
emcu 0:691c0986df45 49 When you press Blue button (and hold it)
emcu 0:691c0986df45 50 on the board_TX, the green LED must turn ON, the same 
emcu 0:691c0986df45 51 on the board_RX the green LED must turn ON.
emcu 0:691c0986df45 52 If you release the Blue button (on the board_TX) the green LED must go OFF
emcu 0:691c0986df45 53 on both on the boards.
emcu 0:691c0986df45 54
emcu 0:691c0986df45 55 *
emcu 0:691c0986df45 56 * Permission is hereby granted, free of charge, to any person obtaining a copy
emcu 0:691c0986df45 57 * of this software and associated documentation files (the "Software"), to deal
emcu 0:691c0986df45 58 * in the Software without restriction, including without limitation the rights
emcu 0:691c0986df45 59 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
emcu 0:691c0986df45 60 * copies of the Software, and to permit persons to whom the Software is
emcu 0:691c0986df45 61 * furnished to do so, subject to the following conditions:
emcu 0:691c0986df45 62 *
emcu 0:691c0986df45 63 * The above copyright notice and this permission notice shall be included in
emcu 0:691c0986df45 64 * all copies or substantial portions of the Software.
emcu 0:691c0986df45 65 *
emcu 0:691c0986df45 66 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
emcu 0:691c0986df45 67 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
emcu 0:691c0986df45 68 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
emcu 0:691c0986df45 69 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
emcu 0:691c0986df45 70 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emcu 0:691c0986df45 71 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
emcu 0:691c0986df45 72 * THE SOFTWARE.
emcu 0:691c0986df45 73
emcu 0:691c0986df45 74
emcu 0:691c0986df45 75 */
emcu 0:691c0986df45 76
emcu 0:691c0986df45 77
emcu 0:691c0986df45 78 #include "mbed.h"
emcu 0:691c0986df45 79
emcu 0:691c0986df45 80 Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx
emcu 0:691c0986df45 81 DigitalOut RTX_DIR(PA_10); // 1 == TX 0 == RX
emcu 0:691c0986df45 82 DigitalOut RTX_Enable(PB_3); // 1 == RTX enable 0 == RTX disable
emcu 0:691c0986df45 83
emcu 0:691c0986df45 84 DigitalOut myled(LED1); // This LED is on NUCLEO-L152RE
emcu 0:691c0986df45 85 DigitalIn BlueButton(USER_BUTTON); // This is Blue-Button and is on NUCLEO-L153RE
emcu 0:691c0986df45 86
emcu 0:691c0986df45 87 #define Pressed 0
emcu 0:691c0986df45 88 #define NotPressed 1
emcu 0:691c0986df45 89 #define Enable 1
emcu 0:691c0986df45 90 #define Disable 0
emcu 0:691c0986df45 91 #define ACK 2
emcu 0:691c0986df45 92 #define OK 1
emcu 0:691c0986df45 93 #define FAIL 0
emcu 0:691c0986df45 94 #define Received 0
emcu 0:691c0986df45 95 #define NotReceived 1
emcu 0:691c0986df45 96
emcu 0:691c0986df45 97 #define ON 1
emcu 0:691c0986df45 98 #define OFF 0
emcu 0:691c0986df45 99 #define TX 1
emcu 0:691c0986df45 100 #define RX 0
emcu 0:691c0986df45 101
emcu 0:691c0986df45 102 #define Baud 1200 // 9600
emcu 0:691c0986df45 103 #define DlyForEndTX 220 // 220
emcu 0:691c0986df45 104 #define MaxReTX 40
emcu 0:691c0986df45 105 #define DebTime 100 // Debounce time
emcu 0:691c0986df45 106
emcu 0:691c0986df45 107 int Car='\0';
emcu 0:691c0986df45 108 int RisultatoRX=FAIL;
emcu 0:691c0986df45 109 int MemBlueButton=10;
emcu 0:691c0986df45 110 int MemOkFail=FAIL;
emcu 0:691c0986df45 111 int MemOK=FAIL;
emcu 0:691c0986df45 112 int MemOFF=NotReceived;
emcu 0:691c0986df45 113 int MemON=NotReceived;
emcu 0:691c0986df45 114
emcu 0:691c0986df45 115 int MemBB = NotPressed;
emcu 0:691c0986df45 116
emcu 0:691c0986df45 117
emcu 0:691c0986df45 118 int TestRX_Data(void);
emcu 0:691c0986df45 119 void RTX_StartUp(void);
emcu 0:691c0986df45 120 void RTX_PowerDown(void);
emcu 0:691c0986df45 121 void RTX_PowerON(void);
emcu 0:691c0986df45 122 void RTX_TX(void);
emcu 0:691c0986df45 123 void RTX_RX(void);
emcu 0:691c0986df45 124
emcu 0:691c0986df45 125 int CarStr[3];
emcu 0:691c0986df45 126 int PuntCar = 0;
emcu 0:691c0986df45 127
emcu 0:691c0986df45 128 void callback() {
emcu 0:691c0986df45 129 // Note: you need to actually read from the serial to clear the RX interrupt
emcu 0:691c0986df45 130 Car = pc.getc();
emcu 0:691c0986df45 131 if (Car == '#' & PuntCar == 0)
emcu 0:691c0986df45 132 {
emcu 0:691c0986df45 133 PuntCar = 0;
emcu 0:691c0986df45 134 CarStr[PuntCar] = Car;
emcu 0:691c0986df45 135 PuntCar++;
emcu 0:691c0986df45 136 }
emcu 0:691c0986df45 137 else if (PuntCar > 0 & PuntCar < 3)
emcu 0:691c0986df45 138 {
emcu 0:691c0986df45 139 CarStr[PuntCar] = Car;
emcu 0:691c0986df45 140 PuntCar++;
emcu 0:691c0986df45 141 }
emcu 0:691c0986df45 142 }
emcu 0:691c0986df45 143
emcu 0:691c0986df45 144
emcu 0:691c0986df45 145 //
emcu 0:691c0986df45 146 // MAIN *****************************************************************
emcu 0:691c0986df45 147 //
emcu 0:691c0986df45 148 int main()
emcu 0:691c0986df45 149 {
emcu 0:691c0986df45 150 int n=0;
emcu 0:691c0986df45 151
emcu 0:691c0986df45 152 pc.baud(Baud);
emcu 0:691c0986df45 153 pc.attach(&callback, pc.RxIrq); // It is for reading under Interrupt the
emcu 0:691c0986df45 154 // RX from USART
emcu 0:691c0986df45 155
emcu 0:691c0986df45 156 // Start Up of the RTX-MID and put it in RX mode
emcu 0:691c0986df45 157 RTX_StartUp();
emcu 0:691c0986df45 158
emcu 0:691c0986df45 159 MemBB = Pressed;
emcu 0:691c0986df45 160 MemOFF = NotReceived;
emcu 0:691c0986df45 161 MemON = NotReceived;
emcu 0:691c0986df45 162
emcu 0:691c0986df45 163 while (1)
emcu 0:691c0986df45 164 {
emcu 0:691c0986df45 165
emcu 0:691c0986df45 166 // RX mode ************************************************************
emcu 0:691c0986df45 167 // Decode Message
emcu 0:691c0986df45 168 // 1==OK==ON 2==ACK==OFF
emcu 0:691c0986df45 169 RisultatoRX = TestRX_Data();
emcu 0:691c0986df45 170 if (RisultatoRX == OK) // OK==ON
emcu 0:691c0986df45 171 {
emcu 0:691c0986df45 172 myled = ON;
emcu 0:691c0986df45 173 // Send ON
emcu 0:691c0986df45 174 // and test if the Message is arrived
emcu 0:691c0986df45 175 n=0;
emcu 0:691c0986df45 176 wait_ms(10);
emcu 0:691c0986df45 177 while (TestRX_Data() != OK)
emcu 0:691c0986df45 178 {
emcu 0:691c0986df45 179 RTX_TX(); // RTX-MID on TX mode
emcu 0:691c0986df45 180 // Send Message
emcu 0:691c0986df45 181 pc.printf("#1@"); // Send Command
emcu 0:691c0986df45 182 wait_ms(DlyForEndTX);
emcu 0:691c0986df45 183 RTX_RX(); // RTX-MID on RX mode
emcu 0:691c0986df45 184 n++;
emcu 0:691c0986df45 185 if (n > MaxReTX)
emcu 0:691c0986df45 186 break;
emcu 0:691c0986df45 187 }
emcu 0:691c0986df45 188 MemOFF = NotReceived;
emcu 0:691c0986df45 189 MemON = Received;
emcu 0:691c0986df45 190 RTX_RX(); // RTX-MID on RX mod
emcu 0:691c0986df45 191 }
emcu 0:691c0986df45 192
emcu 0:691c0986df45 193 if (RisultatoRX == ACK) // ACK==OFF
emcu 0:691c0986df45 194 {
emcu 0:691c0986df45 195 myled = OFF;
emcu 0:691c0986df45 196 // Send OFF
emcu 0:691c0986df45 197 // and test if the Message is arrived
emcu 0:691c0986df45 198 n=0;
emcu 0:691c0986df45 199 wait_ms(10);
emcu 0:691c0986df45 200 while (TestRX_Data() != ACK)
emcu 0:691c0986df45 201 {
emcu 0:691c0986df45 202 RTX_TX(); // RTX-MID on TX mode
emcu 0:691c0986df45 203 // Send Message
emcu 0:691c0986df45 204 pc.printf("#2@"); // Send Command OFF
emcu 0:691c0986df45 205 wait_ms(DlyForEndTX);
emcu 0:691c0986df45 206 RTX_RX(); // RTX-MID on RX mode
emcu 0:691c0986df45 207 n++;
emcu 0:691c0986df45 208 if (n > MaxReTX)
emcu 0:691c0986df45 209 break;
emcu 0:691c0986df45 210 }
emcu 0:691c0986df45 211 MemOFF = Received;
emcu 0:691c0986df45 212 MemON = NotReceived;
emcu 0:691c0986df45 213 RTX_RX(); // RTX-MID on RX mod
emcu 0:691c0986df45 214 }
emcu 0:691c0986df45 215 // END RX mode ********************************************************
emcu 0:691c0986df45 216 }
emcu 0:691c0986df45 217 }
emcu 0:691c0986df45 218
emcu 0:691c0986df45 219 //
emcu 0:691c0986df45 220 // END MAIN *************************************************************
emcu 0:691c0986df45 221 //
emcu 0:691c0986df45 222
emcu 0:691c0986df45 223
emcu 0:691c0986df45 224 //
emcu 0:691c0986df45 225 // Decode Message
emcu 0:691c0986df45 226 //
emcu 0:691c0986df45 227 // REMEMBER:
emcu 0:691c0986df45 228 // before to use this function must put in RX mode the RTX
emcu 0:691c0986df45 229 //
emcu 0:691c0986df45 230 int TestRX_Data(void)
emcu 0:691c0986df45 231 {
emcu 0:691c0986df45 232 int OkFail=0; // 1==OK==ON 2==ACK==OFF
emcu 0:691c0986df45 233
emcu 0:691c0986df45 234 if (CarStr[0]=='#' & CarStr[1]=='1' & CarStr[2]=='@')
emcu 0:691c0986df45 235 OkFail=1; // OK==ON
emcu 0:691c0986df45 236 else if (CarStr[0]=='#' & CarStr[1]=='2' & CarStr[2]=='@')
emcu 0:691c0986df45 237 OkFail=2; // ACK==OFF
emcu 0:691c0986df45 238 else;
emcu 0:691c0986df45 239
emcu 0:691c0986df45 240 if (PuntCar >= 3) // Reset the CarStr & PuntCar
emcu 0:691c0986df45 241 {
emcu 0:691c0986df45 242 CarStr[0] = '0';
emcu 0:691c0986df45 243 CarStr[1] = '1';
emcu 0:691c0986df45 244 CarStr[2] = '2';
emcu 0:691c0986df45 245 PuntCar = 0;
emcu 0:691c0986df45 246 }
emcu 0:691c0986df45 247
emcu 0:691c0986df45 248 return OkFail;
emcu 0:691c0986df45 249 }
emcu 0:691c0986df45 250
emcu 0:691c0986df45 251 void RTX_StartUp(void)
emcu 0:691c0986df45 252 {
emcu 0:691c0986df45 253 RTX_Enable = Disable;
emcu 0:691c0986df45 254 wait_ms(10);
emcu 0:691c0986df45 255 RTX_Enable = Enable;
emcu 0:691c0986df45 256 wait_ms(1);
emcu 0:691c0986df45 257 RTX_DIR = TX; // RTX-MID in TX mode
emcu 0:691c0986df45 258 wait_ms(1); // Wait the stabilizzation of the transceiver
emcu 0:691c0986df45 259 RTX_Enable = Disable;
emcu 0:691c0986df45 260 wait_ms(10);
emcu 0:691c0986df45 261 RTX_Enable = Enable;
emcu 0:691c0986df45 262 wait_ms(1);
emcu 0:691c0986df45 263 RTX_DIR = RX; // RTX-MID in RX mode
emcu 0:691c0986df45 264 wait_ms(1); // Wait the stabilizzation of the transceiver
emcu 0:691c0986df45 265 RTX_Enable = Disable;
emcu 0:691c0986df45 266 wait_ms(1);
emcu 0:691c0986df45 267 RTX_Enable = Enable;
emcu 0:691c0986df45 268 wait_ms(1);
emcu 0:691c0986df45 269 }
emcu 0:691c0986df45 270
emcu 0:691c0986df45 271 void RTX_PowerDown(void)
emcu 0:691c0986df45 272 {
emcu 0:691c0986df45 273 RTX_Enable = Disable;
emcu 0:691c0986df45 274 wait_ms(10);
emcu 0:691c0986df45 275 }
emcu 0:691c0986df45 276
emcu 0:691c0986df45 277 void RTX_PowerON(void)
emcu 0:691c0986df45 278 {
emcu 0:691c0986df45 279 RTX_Enable = Disable;
emcu 0:691c0986df45 280 wait_ms(1);
emcu 0:691c0986df45 281 }
emcu 0:691c0986df45 282
emcu 0:691c0986df45 283 void RTX_TX(void)
emcu 0:691c0986df45 284 {
emcu 0:691c0986df45 285 // RTX_Enable = Disable;
emcu 0:691c0986df45 286 // wait_ms(10);
emcu 0:691c0986df45 287 // RTX_Enable = Enable;
emcu 0:691c0986df45 288 // wait_ms(1);
emcu 0:691c0986df45 289 RTX_DIR = TX; // RTX-MID in TX mode
emcu 0:691c0986df45 290 wait_us(400); // Wait the stabilizzation of the transceiver
emcu 0:691c0986df45 291 }
emcu 0:691c0986df45 292
emcu 0:691c0986df45 293 void RTX_RX(void)
emcu 0:691c0986df45 294 {
emcu 0:691c0986df45 295 // RTX_Enable = Disable;
emcu 0:691c0986df45 296 // wait_ms(10);
emcu 0:691c0986df45 297 // RTX_Enable = Enable;
emcu 0:691c0986df45 298 // wait_ms(1);
emcu 0:691c0986df45 299 // RTX_DIR = TX; // RTX-MID in TX mode
emcu 0:691c0986df45 300 // wait_ms(1); // Wait the stabilizzation of the transceiver
emcu 0:691c0986df45 301 RTX_DIR = RX; // RTX-MID in RX mode
emcu 0:691c0986df45 302 wait_us(40);
emcu 0:691c0986df45 303 RTX_Enable = Disable;
emcu 0:691c0986df45 304 wait_us(20);
emcu 0:691c0986df45 305 RTX_Enable = Enable;
emcu 0:691c0986df45 306 wait_us(200);
emcu 0:691c0986df45 307 }
emcu 0:691c0986df45 308
emcu 0:691c0986df45 309