How to use USART2 on NUCLEO-L152RE and Mbed

Dependencies:   mbed

Committer:
emcu
Date:
Fri May 02 17:33:58 2014 +0000
Revision:
2:1b5f5a433ae8
Parent:
1:e9d1c42a73ae
NUCLEO_L152RE and UART2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 1:e9d1c42a73ae 1
emcu 2:1b5f5a433ae8 2 // Bye www.emcu.it
emcu 2:1b5f5a433ae8 3 // Tested on NUCLEO_L152RE
emcu 2:1b5f5a433ae8 4 // for more info see here: http://www.emcu.it/NUCLEOevaBoards/U2andL152/U2andL152.html#How_to_use_USART2
emcu 2:1b5f5a433ae8 5 //
emcu 2:1b5f5a433ae8 6 // This program send a character via USART2 and via USB (Virtual Com)
emcu 2:1b5f5a433ae8 7 // USART2 is connected to STLINK that send data via USB.
emcu 2:1b5f5a433ae8 8 // ATTENTION:
emcu 2:1b5f5a433ae8 9 // For connect USART2 to D1/TX and D0/RX it is necessary do a bridge on SB63 and SB62 that are on the rear of NUCLEO_L152RE board.
emcu 2:1b5f5a433ae8 10 // I suggest to use TeraTerm to connect the NUCLEO via CN1 (USB)
emcu 2:1b5f5a433ae8 11 // Configure TeraTerm with these parameters:
emcu 2:1b5f5a433ae8 12 // Baud: 9600 - Data: 8bit - Parity: None - Stop: 1bit - Flow Control: None
bcostm 1:e9d1c42a73ae 13
emcu 2:1b5f5a433ae8 14 #include "mbed.h"
bcostm 0:028fac66239d 15
emcu 2:1b5f5a433ae8 16 Serial pc(SERIAL_TX, SERIAL_RX); // tx, rx USB Virtual COM
emcu 2:1b5f5a433ae8 17
emcu 2:1b5f5a433ae8 18
bcostm 0:028fac66239d 19 int main() {
emcu 2:1b5f5a433ae8 20 while(1) {
emcu 2:1b5f5a433ae8 21
emcu 2:1b5f5a433ae8 22 if(pc.readable()) {
emcu 2:1b5f5a433ae8 23 pc.putc(pc.getc());
emcu 2:1b5f5a433ae8 24 }
emcu 2:1b5f5a433ae8 25
emcu 2:1b5f5a433ae8 26 wait(0.1);
emcu 2:1b5f5a433ae8 27 pc.printf("E");
emcu 2:1b5f5a433ae8 28
emcu 2:1b5f5a433ae8 29 }
bcostm 0:028fac66239d 30 }