Code based on the emcu example, for more info under the first example see here: http://www.emcu.it/NUCLEOevaBoards/U2andL152/U2andL152.html

Dependencies:   mbed-src mbed

Fork of NucleoL152RE_two_boards_connected_via_USART2 by Enrico Marinoni

Committer:
emcu
Date:
Tue May 13 06:50:08 2014 +0000
Revision:
1:e83589b5888f
Parent:
0:5bb2b3fd5215
Child:
2:7ddee354bdfa
Added the schematics for connecting two NUCLEO via USART.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emcu 0:5bb2b3fd5215 1
emcu 0:5bb2b3fd5215 2 // Bye www.emcu.it
emcu 0:5bb2b3fd5215 3 // Tested on NUCLEO_L152RE
emcu 0:5bb2b3fd5215 4 // for more info see here: http://www.emcu.it/NUCLEOevaBoards/U2andL152/U2andL152.html#How_to_use_USART2
emcu 0:5bb2b3fd5215 5 //
emcu 0:5bb2b3fd5215 6 /*
emcu 0:5bb2b3fd5215 7 * Permission is hereby granted, free of charge, to any person obtaining a copy
emcu 0:5bb2b3fd5215 8 * of this software and associated documentation files (the "Software"), to deal
emcu 0:5bb2b3fd5215 9 * in the Software without restriction, including without limitation the rights
emcu 0:5bb2b3fd5215 10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
emcu 0:5bb2b3fd5215 11 * copies of the Software, and to permit persons to whom the Software is
emcu 0:5bb2b3fd5215 12 * furnished to do so, subject to the following conditions:
emcu 0:5bb2b3fd5215 13 *
emcu 0:5bb2b3fd5215 14 * The above copyright notice and this permission notice shall be included in
emcu 0:5bb2b3fd5215 15 * all copies or substantial portions of the Software.
emcu 0:5bb2b3fd5215 16 *
emcu 0:5bb2b3fd5215 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
emcu 0:5bb2b3fd5215 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
emcu 0:5bb2b3fd5215 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
emcu 0:5bb2b3fd5215 20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
emcu 0:5bb2b3fd5215 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emcu 0:5bb2b3fd5215 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
emcu 0:5bb2b3fd5215 23 * THE SOFTWARE.
emcu 0:5bb2b3fd5215 24 */
emcu 0:5bb2b3fd5215 25 //
emcu 0:5bb2b3fd5215 26 // This program send a character (E) via USART2 by pressing USER button (Blue Button) on NUCLEO board.
emcu 0:5bb2b3fd5215 27 // For test this example are necessary two NUCLEO-L152RE connected as shown below.
emcu 0:5bb2b3fd5215 28 //
emcu 0:5bb2b3fd5215 29 // NUCLEO-L152RE n.1 NUCLEO-L152RE n.2
emcu 0:5bb2b3fd5215 30 // TX-D1 ----------------- RX-D0
emcu 0:5bb2b3fd5215 31 // RX-D0 ----------------- TX-D1
emcu 1:e83589b5888f 32 // GND ----------------- GND
emcu 0:5bb2b3fd5215 33 //
emcu 0:5bb2b3fd5215 34 // ATTENTION:
emcu 0:5bb2b3fd5215 35 // For connect USART2 to D1/TX and D0/RX it is necessary do a bridge on SB63 and SB62 and
emcu 0:5bb2b3fd5215 36 // it is also necessary remove the bridge (0 ohm resistor) from SB13 and SB14.
emcu 0:5bb2b3fd5215 37 // SB62,62,13 and SB14 are on the rear of NUCLEO_L152RE board
emcu 0:5bb2b3fd5215 38
emcu 0:5bb2b3fd5215 39
emcu 0:5bb2b3fd5215 40 #include "mbed.h"
emcu 0:5bb2b3fd5215 41
emcu 0:5bb2b3fd5215 42 Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx
emcu 0:5bb2b3fd5215 43 DigitalOut myled(LED1); // This LED is on NUCLEO-L152RE
emcu 0:5bb2b3fd5215 44 DigitalIn BlueButton(USER_BUTTON); // This is Blue-Button and is on NUCLEO-L153RE
emcu 0:5bb2b3fd5215 45
emcu 0:5bb2b3fd5215 46 #define Pressed 0
emcu 0:5bb2b3fd5215 47 #define NotPressed 1
emcu 0:5bb2b3fd5215 48
emcu 0:5bb2b3fd5215 49 int Car='\0';
emcu 0:5bb2b3fd5215 50
emcu 0:5bb2b3fd5215 51 int main() {
emcu 0:5bb2b3fd5215 52 while(1)
emcu 0:5bb2b3fd5215 53 {
emcu 0:5bb2b3fd5215 54
emcu 0:5bb2b3fd5215 55 if (BlueButton == Pressed)
emcu 0:5bb2b3fd5215 56 pc.putc('E');
emcu 0:5bb2b3fd5215 57
emcu 0:5bb2b3fd5215 58 if(pc.readable())
emcu 0:5bb2b3fd5215 59 {
emcu 0:5bb2b3fd5215 60 Car = pc.getc();
emcu 0:5bb2b3fd5215 61 if (Car == 'E')
emcu 0:5bb2b3fd5215 62 {
emcu 0:5bb2b3fd5215 63 myled = 1;
emcu 0:5bb2b3fd5215 64 wait(0.1);
emcu 0:5bb2b3fd5215 65 }
emcu 0:5bb2b3fd5215 66 myled = 0;
emcu 0:5bb2b3fd5215 67 Car = '\0';
emcu 0:5bb2b3fd5215 68 }
emcu 0:5bb2b3fd5215 69
emcu 0:5bb2b3fd5215 70 }
emcu 0:5bb2b3fd5215 71 }