How to use USART2 on NUCLEO-L152RE and Mbed





Home Page


USART2 and Virtual Com Port at the same time
USART2 for communication with
shield or extension board






-
USART2 and Virtual Com Port at the same time

On STM NUCLEO_L152RE, by default the USART communication between the target MCU and ST-LINK MCU is enabled in order to support Virtual Com Port for mbed (SB13 and SB14 ON, SB62 and SB63 OFF).
for using USART2 and USB bridge (virtual com port) at the same time are necessary:
  1. SB63 and SB62 should be ON.
    SB63 and SB62 are on the rear of NUCLEO_L152RE board, see below.


    Click on the image below to enlarge it


  2. Use the simple example shown below (it is for mbed compiler).
    This SW is also, available from mbed web site, see here.

    #include "mbed.h"
     
    Serial pc(SERIAL_TX, SERIAL_RX);    // tx, rx USB Virtual COM

    int main() {
        while(1) {
         
            if(pc.readable()) {
                pc.putc(pc.getc());
            }
          
            wait(0.1);
            pc.printf("E");

        }

Now, for testing your work, I suggest to use TeraTerm to connect the NUCLEO_L152RE via CN1 (USB) to a PC.
Configure TeraTerm with these parameters:
Baud: 9600 - Data: 8bit - Parity: None - Stop: 1bit - Flow Control: None
On TeraTerm you must see a sequence of "E" (pc.printf("E");).

At the same time connect the circuit below in this manner:
PinA to 3V3 and PinB to D1 (TX), you see the LED that flashing.
This flashing indicate the transmission of the character "E" (pc.printf("E");).

Now connect PinB to DO (RX) and type a character in TeraTerm, you see the led that flashing.
This indicate the received characters from TeraTerm.


UP





-
USART2 for communication with
shield or extension board


ATTENTION:  
After the modified explain below, you lost the possibility to use the virtual comm to connect the NUCLEO to the PC.

On STM NUCLEO_L152RE
, if the communication between the USART2 and shield or extension board is required, this is the standard mode for interconnect for example two NUCLEO boards via USART, are necessary:
  1. SB62 and SB63 should be ON
    SB63 and SB62 are on the rear of NUCLEO_L152RE board, see below.

    Click on the image below to enlarge it


  2. SB13 and SB14 should be OFF
    SB13 and SB14 are on the rear of NUCLEO_L152RE board, near USB connector, see below.

    Click on the image below to enlarge it

  3. Now connect two NUCLEO-L152RE via USART2 and use this SW (developed for Mbed) on both the board.
    #include "mbed.h"
     
    Serial pc(SERIAL_TX, SERIAL_RX);    // 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 main() {
        while(1
        {
     
        if (BlueButton == Pressed)
            pc.putc('E');
        
        if(pc.readable()) 
            {
            Car = pc.getc();
            if (Car == 'E')
                {
                myled = 1;
                wait(0.1);
                }
            myled = 0;
            Car = '\0';
            }
     
        }
    }
    The connection are:
    NUCLEO n.1         NUCLEO n.2
    GND -------------- GND
    TX  -------------- RX
    RX  -------------- TX
    If you press the Blue button on Nucleo n.1 you must see the Green Led ON, on Nucleo n.2 and vice versa.

    Click on the image below to enlarge it
     

UP


Home Page