9 years, 10 months ago.

FRDM KL25Z USBSerial - send data problem

Hi, I have tried some examples USBSerial on KL25Z, but I have problem with sending of data. Receivenig is OK. Have someone got some experiences with this problem?Thanks.

Serial works fine over OpenSDA USB, but when I try USBserial over KL25 USB, I have problem with transmitting. I tryed other KL25Z board, but it is same.I thounght, that USB port is wrong, but USBmouse example works fine.

posted by Lukas Kratina 06 Jan 2015

Hey Lukas! What program are you using to receive data? I had a problem with one program that wasnt receive putc once.

posted by Thiago . 19 Jun 2015

3 Answers

9 years, 9 months ago.

I believe I have the same problem on K64F:

Serial over OpenSDA usb works fine. Hardware serial through UART3 works fine. USBserial through K64 usb connector receives data, but does not send data.

This works fine (receive from USBserial, echo to SDA USB serial port):

#include "mbed.h"
#include "USBSerial.h"

Serial pc(USBTX,USBRX);
USBSerial vcom;
char rx;

int main(void)
{
    while(1) {
        rx=vcom.getc();
        pc.putc(rx);
        pc.putc(10);
        pc.putc(13);
    }
}

This doesn't work(receive from USBserial, echo to USBserial):

#include "mbed.h"
#include "USBSerial.h"

USBSerial vcom;
char rx;

int main(void)
{
    while(1) {
        rx=vcom.getc();
        vcom.putc(rx);
        vcom.putc(10);
        vcom.putc(13);
    }
}

putc() returns true, that means no error - but nothing is sent. I use RealTerm i Win 7. I have tried other terminals with same result. All libs are newest revision. The Handbook examples don't work either (at least, for me...)

9 years, 10 months ago.

Erik's answer to this question may help:

https://developer.mbed.org/questions/5840/Help-with-debug-mode-what-s-std-out/

Thank you for your answer, but it isnť my problem.

posted by Lukas Kratina 06 Jan 2015
9 years, 9 months ago.

If you have a look at the USBSerial handbook here http://developer.mbed.org/handbook/USBSerial you will see that the correct syntax requires an underscore (_) before the usual putc and getc, i.e. vcom._putc and vcom._getc. I'm not sure why vcom.getc works for you though. Anyway hope this helps your problem.

Peter

Yes, I missed the underscores. vcom._putc() doesn't work either, though (But at least it returns 0=failure when it fails...)

vcom.writeBlock() works fine, so I will use that for now.

Thanks Peter!

posted by Tobias Have 24 Feb 2015

USBSerial worked fine for me on the FRDM KL46Z. I used a constructor as follows USBSerial vcom (0x1f00, 0x2012, 0x0001, false); Virtual serial port over USB, connect_blocking = false and used _getc, _putc and printf successfully. Also take note of the types; you have used a char for variable rx but the USBSerial functions use int types. I used the int8_t type. Don't know if the functions are that particular but it's worth trying.

posted by Peter Ampt 24 Feb 2015