This project explain how to use Nucleo-L152RE and AUREL RTX-MID-3V for create a intelligent radio control. In another words, there is two transceivers that send data and an ACK if the reception is correct.

Dependencies:   mbed

Committer:
emcu
Date:
Mon Jun 02 18:38:35 2014 +0000
Revision:
0:e3fc2197fe07
This project explain how to use Nucleo-L152RE and AUREL RTX-MID-3V for create a intelligent radio control.; In another words, there is two transceivers that send data and an ACK if the reception is correct.

Who changed what in which revision?

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