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

Dependencies:   mbed

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

Who changed what in which revision?

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