Serial parameter (like baudrate)

25 Jul 2009 . Edited: 26 Jul 2009

In the following example program, how do we change the baudrate to 19200 (for example).

#include "mbed.h"

Serial pc(USBTX, USBRX);

// baud(19200) <== to be formatted correctly

int main() {
pc.printf("Hello World!");
while(1) {
pc.putc(pc.getc());
}
}

26 Jul 2009

Hi!

The full api for Serial can be found @ http://mbed.co.uk/projects/libraries/api/mbed/trunk/Serial (or now directly within the compiler by clicking on the library!), but looking at what it documents, i've realised there is no example :(

The important bit of information which may not be obvious is that these are all "methods"; functions that operate on a C++ object (in this case, a "Serial" object called "pc"). So, you just do something like:

#include "mbed.h"

Serial pc(USBTX, USBRX);

int main() {
    pc.baud(19200);
    pc.printf("Hello World!");
    while(1) {
        pc.putc(pc.getc());
    }
}

The other important thing to remember is that what it is talking to (e.g. Teraterm on your PC) needs to be setup at the same baud rate, else you'll get garbage!

Hope this gets you going!

Simon

26 Jul 2009

Hello Simon!

Thank you very much!

I am trying to go through all functions and add for my own understanding some examples.

A small example for each function would be much appreciated and would help grasp the concepts more rapidly and facilitate the harvesting of the fruits of this powerful tool you’ve built.

Gratefully yours, 

René-Jean

 

26 Jul 2009

Hi René-Jean,

A small example for each function would be much appreciated and would help grasp the concepts more rapidly and facilitate the harvesting of the fruits of this powerful tool you’ve built.

Thanks for the feedback; I totally agree. Always good to be nudged to make sure we do :)

Any other hints about where you (or others) have got stuck are always welcome.

Thanks again for being involved in the beta testing!

Simon