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

main.cpp

Committer:
emcu
Date:
2014-06-28
Revision:
1:676a504fc5e7
Parent:
0:fb2930dc304c

File content as of revision 1:676a504fc5e7:

//
// U2andU1onL152
//
// From: www.emcu.it
// Date: 24-06-2014
// Tested on NUCLEO_L152RE
// for more info see here: http://www.emcu.it/NUCLEOevaBoards/NUCLEOevaBoards.html#Tutorial
//
/*
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 
 
 ++++++++++++++++++++++ CONFIGURATIONS +++++++++++++++++++++++++++++++
 
 USART2 it is used for debug (connected to the PC) using TeraTerm
 USART1 it is used for show the way to use another USART
 Both USART are not used in Interrupt
 
 The USART parameters are:
 Baud Rate: 9600 
 Data: 8
 Parity: NONE
 Stop: 1
 Flow Control: NONE
  
  
 ++++++++++++++++++++++ How to use this example ++++++++++++++++++++++
 
 For test this example connect with a jumper D2 (SERIAL1_RX) to D10 (SERIAL1_TX).
 
 Press and release the Blue Button and you must see the green LED ON for 1 second. 
 At the same time some message are displayed via USB Virtual COM on your PC.
 
 Similar, if you press E on your Tera Term (PC) you must see the green LED ON for 1 second.
 
 
 ++++++++++++++++++++++ Changes
  
 28-06-2014
 Change SERIAL1_TX from D8 (PA_9) to D10 (PB_6) 
 
 
 */



#include "mbed.h"
 
Serial pc(SERIAL_TX, SERIAL_RX);    // This is USART2 tx, rx
Serial Serial1(PB_6, PA_10);        // This is USART1 tx, rx
DigitalOut myled(LED1);             // This LED is on NUCLEO-L152RE
DigitalIn BlueButton(USER_BUTTON);  // This is Blue-Button and is on NUCLEO-L153RE

#define Pressed 0
#define NotPressed 1

int Car='\0';
int CarSerial1='\0';
int n=0;

int main() {
    myled = 0;
    
    pc.printf("\n\r\n\r START MAIN \n\r");
    
    while(1) 
    {
    
    // Test the Blue Button
    if (BlueButton == Pressed)
        {
        while(BlueButton == Pressed)
            {
            if (n == 0)
                pc.printf("Please release the BLUE Button\n\r");
            n++;
            }
        n = 0;
        pc.printf("Send char. E to USART1\n\r");
        Serial1.putc('E');      // Send char. E to USART1
        }
       
    // Test the char. received from USART2 tha is USB Virtual COM 
    if(pc.readable()) 
        {
        Car = pc.getc();
        if (Car == 'E')
            {
            pc.printf("Send char. E (received from USB_VirtualCOM) to USART1\n\r");
            Serial1.putc('E');  // Send char. E to USART1
            }
        Car = '\0';
        }
    
    // Test the char. received from USART1
    if (Serial1.readable())
        {
        CarSerial1 = Serial1.getc();    // Get char. from USART1
        if (CarSerial1 == 'E')
            {
            pc.printf("RX char. E from USART1\n\r");
            myled = 1;
            wait(1);
            }
        myled = 0;
        CarSerial1 = '\0';
        }        

    }
}