For more info see here: http://www.emcu.it/NUCLEOevaBoards/U2andL152/U2andL152.html

Dependencies:   mbed

Committer:
emcu
Date:
Fri Jun 27 22:56:14 2014 +0000
Revision:
2:7ddee354bdfa
Parent:
1:e83589b5888f
Some minor changes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emcu 0:5bb2b3fd5215 1
emcu 2:7ddee354bdfa 2 // By: 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 2:7ddee354bdfa 38 /*
emcu 2:7ddee354bdfa 39 After this modifications, you lost the possibility to use the virtual comm to connect
emcu 2:7ddee354bdfa 40 the NUCLEO to the PC.
emcu 2:7ddee354bdfa 41
emcu 2:7ddee354bdfa 42 */
emcu 0:5bb2b3fd5215 43
emcu 0:5bb2b3fd5215 44
emcu 0:5bb2b3fd5215 45 #include "mbed.h"
emcu 0:5bb2b3fd5215 46
emcu 0:5bb2b3fd5215 47 Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx
emcu 0:5bb2b3fd5215 48 DigitalOut myled(LED1); // This LED is on NUCLEO-L152RE
emcu 0:5bb2b3fd5215 49 DigitalIn BlueButton(USER_BUTTON); // This is Blue-Button and is on NUCLEO-L153RE
emcu 0:5bb2b3fd5215 50
emcu 0:5bb2b3fd5215 51 #define Pressed 0
emcu 0:5bb2b3fd5215 52 #define NotPressed 1
emcu 0:5bb2b3fd5215 53
emcu 0:5bb2b3fd5215 54 int Car='\0';
emcu 0:5bb2b3fd5215 55
emcu 0:5bb2b3fd5215 56 int main() {
emcu 0:5bb2b3fd5215 57 while(1)
emcu 0:5bb2b3fd5215 58 {
emcu 0:5bb2b3fd5215 59
emcu 0:5bb2b3fd5215 60 if (BlueButton == Pressed)
emcu 0:5bb2b3fd5215 61 pc.putc('E');
emcu 0:5bb2b3fd5215 62
emcu 0:5bb2b3fd5215 63 if(pc.readable())
emcu 0:5bb2b3fd5215 64 {
emcu 0:5bb2b3fd5215 65 Car = pc.getc();
emcu 0:5bb2b3fd5215 66 if (Car == 'E')
emcu 0:5bb2b3fd5215 67 {
emcu 0:5bb2b3fd5215 68 myled = 1;
emcu 0:5bb2b3fd5215 69 wait(0.1);
emcu 0:5bb2b3fd5215 70 }
emcu 0:5bb2b3fd5215 71 myled = 0;
emcu 0:5bb2b3fd5215 72 Car = '\0';
emcu 0:5bb2b3fd5215 73 }
emcu 0:5bb2b3fd5215 74
emcu 0:5bb2b3fd5215 75 }
emcu 0:5bb2b3fd5215 76 }