I'm sending data over Serial to a FRDM-kl25z via a printf statement on another uC;

    for (int i = 0; i <320; i++)
        sprintf(left_arr, "%d", left);
        sprintf(right_arr, "%d", right);
        frdm.printf("%s,%s \n\r", left_arr, right_arr);

And I receive the data with this code in a serial interrupt - called rx_data;

void rx_data()
    pc.printf("rx interrupted!\n\r");
    string current = ""; 
    while (rpi.readable())
        current += rpi.getc();

    PC.printf("%s", current);


I'm defining rpi as below;

Serial rpi(PTC4, PTC3);  // tx, rx

It only gets the first character, so the first byte, of the Serial transmission. I've tested with a counter too and the port is only readable for 1 loop iteration.

I've tested the code with other uC's - the LPC1768 - and it works fine.

It must be the fault of the Serial port on the FRDM I think, does it only have a 1 byte buffer or something?



2 Answers 2


It sounds like your interrupt is called at the start of a serial transaction. Assuming that, you would be trying to read a buffer with only one piece of data in it. Therefore it would exit out of your while loop early because the second time through there would be no valid data.

Also, an mbed platform should have a buffer size larger than one.

I assume that the interrupt above is called when data starts to come in. So to solve the problem you need to wait for the end of transmission before collecting that data. There may be an interrupt specifically for that.

  • \$\begingroup\$ What are you trying to say with this answer? I'm aware that this will happen if the buffer is only 1 byte - I am looking for a solution. \$\endgroup\$ Jan 31, 2015 at 10:56
  • \$\begingroup\$ I'm sorry but I don't believe you suggestion to be correct, have put waits and non-readable delays in the buffer reading loop and it makes no difference. The Serial reading works perfectly on other members of the mbed platform. When bytes arrive in the rx buffer the interrupt is called which then leads to buffer emptying. I think the issue is related to the buffer on the frdm controller - so I'm looking for info on this more than anything \$\endgroup\$ Feb 1, 2015 at 16:07

After all that turns out I was duped by a false pinout for the FRDM board. Pins PTC3/4 are denoted as a serial port. This one;


This pinout, the correct one, shows that these are just standard gpio (interesting they had a 1 byte buffer!).


I'm now defining the port as;

Serial rpi(PTE22, PTE23);  // tx, rx

which now allows it to work as normal.

  • \$\begingroup\$ Perhaps, but you seem to also be missing that a simple serial API only gives you characters already received. If you want some sort of defined message, you'll have to collect not until you temporarily run out of received data, but until you hit the message terminating condition. \$\endgroup\$ Feb 3, 2015 at 2:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.