5 years, 4 months ago.

Why does this not work? - Serial Question..

From the pc i send serial data to sINPUT and expect it to send that data out of sOUTPUT

Serial cant send getc

#include "mbed.h"

Serial sOUTPUT(p9, p10);  // tx, rx
Serial sINPUT(USBTX, USBRX); // tx, rx

int main() {
    while (1)

3 Answers

5 years, 4 months ago.

If you are using a windows pc, lower the baudrate to 460800.

The baud is fine, It's this line that's the problem


posted by . . 23 Jun 2015
5 years, 4 months ago.

The first parameter to printf should be a string. You are giving it an int.

You could try sOutput.printf("%c", sINPUT.getc()), but it might be more efficient to use putc and getc instead. There is an example of doing this in the Handbook Serial page.

5 years, 4 months ago.

Use putc rather than printf. printf expects a char* and you're passing it a char.

The alternative would be sOutput.printf("%c",sINPUT.getc());

but that would be about 20 times slower than putc for no benefit