9 years, 1 month ago.

how to communicate between nucleo f411RE and pc through uart

Hello,

i'm trying to establish communication between the Nucleo F411RE board and a pc through uart, I'd like to know how i can read a string from the pc

Question relating to:

Intrrupt, scanf , printf, Timer

Thank you, it works fine.

posted by 'Nete Thahe 16 Oct 2015

1 Answer

9 years, 1 month ago.

Use the Serial class from mbed.h, with USBRX and USBTX as the RX and TX pins.

include the mbed library with this snippet

/*  example code */
#include "mbed.h"
Serial pc(USBTX, USBRX); //8N1
char buffer[256];

int main() {
  buffer[255]=0x00; // ensure a null terminator.
  while(true) {
    // read the pending data, and echo it back.
    
    if (pc.readable()) {
        pc.gets(buffer,255);
        pc.printf("read : %s",buffer);
    }    
  }
}

Accepted Answer

Tested the example code. Made a couple corrections along the way.

posted by Jason Daniels 16 Oct 2015

To test this you will need a terminal program. I did this on linux using moserial. you can also use the Arduino IDE's serial monitor if you have that, or any terminal program. (putty on windows for example)

posted by Jason Daniels 16 Oct 2015

Thank you very much Jason, it works

posted by 'Nete Thahe 16 Oct 2015

You're welcome.

posted by Jason Daniels 16 Oct 2015