This example show the mode to use UASRT1 and USART2 on NUCLEO-L152RE. USART2 it is used for debug (connected to the PC) using TeraTerm. USART1 it is used for show the way to use another USART.

Dependencies:   mbed

Committer:
emcu
Date:
Fri Jun 27 23:31:38 2014 +0000
Revision:
0:fb2930dc304c
Child:
1:676a504fc5e7
This example show the mode to use UASRT1 and USART2 on NUCLEO-L152RE.; USART2 it is used for debug (connected to the PC) using TeraTerm.; USART1 it is used for show the way to use another USART.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emcu 0:fb2930dc304c 1 //
emcu 0:fb2930dc304c 2 // U2andU1onL152
emcu 0:fb2930dc304c 3 //
emcu 0:fb2930dc304c 4 // From: www.emcu.it
emcu 0:fb2930dc304c 5 // Date: 24-06-2014
emcu 0:fb2930dc304c 6 // Tested on NUCLEO_L152RE
emcu 0:fb2930dc304c 7 // for more info see here: http://www.emcu.it/NUCLEOevaBoards/NUCLEOevaBoards.html#Tutorial
emcu 0:fb2930dc304c 8 //
emcu 0:fb2930dc304c 9 /*
emcu 0:fb2930dc304c 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
emcu 0:fb2930dc304c 11 * of this software and associated documentation files (the "Software"), to deal
emcu 0:fb2930dc304c 12 * in the Software without restriction, including without limitation the rights
emcu 0:fb2930dc304c 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
emcu 0:fb2930dc304c 14 * copies of the Software, and to permit persons to whom the Software is
emcu 0:fb2930dc304c 15 * furnished to do so, subject to the following conditions:
emcu 0:fb2930dc304c 16 *
emcu 0:fb2930dc304c 17 * The above copyright notice and this permission notice shall be included in
emcu 0:fb2930dc304c 18 * all copies or substantial portions of the Software.
emcu 0:fb2930dc304c 19 *
emcu 0:fb2930dc304c 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
emcu 0:fb2930dc304c 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
emcu 0:fb2930dc304c 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
emcu 0:fb2930dc304c 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
emcu 0:fb2930dc304c 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
emcu 0:fb2930dc304c 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
emcu 0:fb2930dc304c 26 * THE SOFTWARE.
emcu 0:fb2930dc304c 27
emcu 0:fb2930dc304c 28
emcu 0:fb2930dc304c 29 ++++++++++++++++++++++ CONFIGURATIONS +++++++++++++++++++++++++++++++
emcu 0:fb2930dc304c 30
emcu 0:fb2930dc304c 31 USART2 it is used for debug (connected to the PC) using TeraTerm
emcu 0:fb2930dc304c 32 USART1 it is used for show the way to use another USART
emcu 0:fb2930dc304c 33 Both USART are not used in Interrupt
emcu 0:fb2930dc304c 34
emcu 0:fb2930dc304c 35 The USART parameters are:
emcu 0:fb2930dc304c 36 Baud Rate: 9600
emcu 0:fb2930dc304c 37 Data: 8
emcu 0:fb2930dc304c 38 Parity: NONE
emcu 0:fb2930dc304c 39 Stop: 1
emcu 0:fb2930dc304c 40 Flow Control: NONE
emcu 0:fb2930dc304c 41
emcu 0:fb2930dc304c 42
emcu 0:fb2930dc304c 43 ++++++++++++++++++++++ How to use this example ++++++++++++++++++++++
emcu 0:fb2930dc304c 44
emcu 0:fb2930dc304c 45 For test this example connect with a jumper D2 to D8.
emcu 0:fb2930dc304c 46
emcu 0:fb2930dc304c 47 Press and release the Blue Button and you must see the green LED ON for 1 second.
emcu 0:fb2930dc304c 48 At the same time some message are displayed via USB Virtual COM on your PC.
emcu 0:fb2930dc304c 49
emcu 0:fb2930dc304c 50 Similar, if you press E on your Tera Term (PC) you must see the green LED ON for 1 second.
emcu 0:fb2930dc304c 51
emcu 0:fb2930dc304c 52
emcu 0:fb2930dc304c 53
emcu 0:fb2930dc304c 54 */
emcu 0:fb2930dc304c 55
emcu 0:fb2930dc304c 56
emcu 0:fb2930dc304c 57
emcu 0:fb2930dc304c 58 #include "mbed.h"
emcu 0:fb2930dc304c 59
emcu 0:fb2930dc304c 60 Serial pc(SERIAL_TX, SERIAL_RX); // This is USART2 tx, rx
emcu 0:fb2930dc304c 61 Serial Serial1(PA_9, PA_10); // This is USART1 tx, rx
emcu 0:fb2930dc304c 62 DigitalOut myled(LED1); // This LED is on NUCLEO-L152RE
emcu 0:fb2930dc304c 63 DigitalIn BlueButton(USER_BUTTON); // This is Blue-Button and is on NUCLEO-L153RE
emcu 0:fb2930dc304c 64
emcu 0:fb2930dc304c 65 #define Pressed 0
emcu 0:fb2930dc304c 66 #define NotPressed 1
emcu 0:fb2930dc304c 67
emcu 0:fb2930dc304c 68 int Car='\0';
emcu 0:fb2930dc304c 69 int CarSerial1='\0';
emcu 0:fb2930dc304c 70 int n=0;
emcu 0:fb2930dc304c 71
emcu 0:fb2930dc304c 72 int main() {
emcu 0:fb2930dc304c 73 myled = 0;
emcu 0:fb2930dc304c 74
emcu 0:fb2930dc304c 75 pc.printf("\n\r\n\r START MAIN \n\r");
emcu 0:fb2930dc304c 76
emcu 0:fb2930dc304c 77 while(1)
emcu 0:fb2930dc304c 78 {
emcu 0:fb2930dc304c 79
emcu 0:fb2930dc304c 80 // Test the Blue Button
emcu 0:fb2930dc304c 81 if (BlueButton == Pressed)
emcu 0:fb2930dc304c 82 {
emcu 0:fb2930dc304c 83 while(BlueButton == Pressed)
emcu 0:fb2930dc304c 84 {
emcu 0:fb2930dc304c 85 if (n == 0)
emcu 0:fb2930dc304c 86 pc.printf("Please release the BLUE Button\n\r");
emcu 0:fb2930dc304c 87 n++;
emcu 0:fb2930dc304c 88 }
emcu 0:fb2930dc304c 89 n = 0;
emcu 0:fb2930dc304c 90 pc.printf("Send char. E to USART1\n\r");
emcu 0:fb2930dc304c 91 Serial1.putc('E'); // Send char. E to USART1
emcu 0:fb2930dc304c 92 }
emcu 0:fb2930dc304c 93
emcu 0:fb2930dc304c 94 // Test the char. received from USART2 tha is USB Virtual COM
emcu 0:fb2930dc304c 95 if(pc.readable())
emcu 0:fb2930dc304c 96 {
emcu 0:fb2930dc304c 97 Car = pc.getc();
emcu 0:fb2930dc304c 98 if (Car == 'E')
emcu 0:fb2930dc304c 99 {
emcu 0:fb2930dc304c 100 pc.printf("Send char. E (received from USB_VirtualCOM) to USART1\n\r");
emcu 0:fb2930dc304c 101 Serial1.putc('E'); // Send char. E to USART1
emcu 0:fb2930dc304c 102 }
emcu 0:fb2930dc304c 103 Car = '\0';
emcu 0:fb2930dc304c 104 }
emcu 0:fb2930dc304c 105
emcu 0:fb2930dc304c 106 // Test the char. received from USART1
emcu 0:fb2930dc304c 107 if (Serial1.readable())
emcu 0:fb2930dc304c 108 {
emcu 0:fb2930dc304c 109 CarSerial1 = Serial1.getc(); // Get char. from USART1
emcu 0:fb2930dc304c 110 if (CarSerial1 == 'E')
emcu 0:fb2930dc304c 111 {
emcu 0:fb2930dc304c 112 pc.printf("RX char. E from USART1\n\r");
emcu 0:fb2930dc304c 113 myled = 1;
emcu 0:fb2930dc304c 114 wait(1);
emcu 0:fb2930dc304c 115 }
emcu 0:fb2930dc304c 116 myled = 0;
emcu 0:fb2930dc304c 117 CarSerial1 = '\0';
emcu 0:fb2930dc304c 118 }
emcu 0:fb2930dc304c 119
emcu 0:fb2930dc304c 120 }
emcu 0:fb2930dc304c 121 }