7 years, 8 months ago.

Mbed to Mbed Serial Inconsistency

Hi there

I'm designing a data acquisition system for a car and I'm having a big problem with mbed to mbed serial. I'm trying to print out the characters a, b, c, d, e and f in succession repeatedly (just as a test, the completed system will be much more complex). The values I'm getting across are the right characters mostly, but in the wrong order, and with some anomaly characters. I've tried doing the same with hex values and the values I receive are more often than not completely wrong, and again in the wrong order.

I've tried using and not using interrupts, different serial pins, different mbed, different computer, each gives the same result of inconsistent data. The code I'm using is included below, can anyone think of anything that might be wrong?

Thanks for your help!

Serial in:

'#'include "mbed.h"

Serial in(NC,p10); Serial pc(USBTX, USBRX);

int main() { pc.baud(19200); in.baud(9600);

while(1) { char c = in.getc(); pc.printf("%c\n\r",c);

}

}

Serial out:

'#'include "mbed.h"

Serial out(p9,NC);

char alph[6]={'a','b','c','d','e','f'};

int main() {

out.baud(9600);

while(1) { for(int i=0; i<6; i++) { out.putc(alph[i]); } wait_ms(1); } }

1 Answer

7 years, 8 months ago.

Your mbed-to-mbed link is running at 9600 baud, pushing characters at full whack (with start & stop bits you'll only get 960 characters per second; the 1ms wait won't add any gap since the UART will still not be writable after the previous character).

For each character received, you print out 4 or 5 characters on another 9600 baud link, which won't be able to keep up! The getc() call ignores overrun errors.

Accepted Answer

Thank you so much for your help, that makes sense. How do I stop that from happening?

posted by Yola Jones 16 Sep 2016

You could run the console at a faster speed e.g. 115200, assuming your hardware is capable.

posted by Colin Hogben 16 Sep 2016

Thank you so much, it's now working perfectly. Your help is very very much appreciated!

posted by Yola Jones 16 Sep 2016