Electronic – FRDM-kl25z Serial Buffer Issue

bufferfreescalembedserial

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

    for (int i = 0; i <320; i++)
    {
        left--;
        right++;
        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?

Thanks!

Best Answer

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.