Serial string receiving

26 Feb 2010 . Edited: 26 Feb 2010

Hi all,

I have 2 serial devices connected to my mbed, one is communicating at 57600 baud, and the other at 115200 baud. Both devices send sentences of around 30-80 bytes long that always terminate in the LF char ('/n' I guess).

I would simply like some way of attaching an interrupt when a whole sentence is received rather than handling stuff on a char by char basis. I see some of you have started to write libraries to handle similar things but I'm not sure where to get started. Any help appreciated!

26 Feb 2010

Also, when using simple debug code:

#include "mbed.h"

DigitalOut myled(LED1);
Serial pc(USBTX,USBRX);
Serial gps(p13,p14);
Serial imu(p9,p10);


int main() {
    pc.baud(921600);
    gps.baud(115200);
    imu.baud(57600);
    pc.printf("mbed Serial Terminal");
    wait(1);
    while (1) {
        if (pc.readable()) {
            imu.putc(pc.getc());
        }
        if (imu.readable()) {
            pc.putc(imu.getc());
        }
    }
}

I get this:

mbed Serial Terminal$@�0B¥H¥)¥JJ•*Æ„$@�0R¥H¥)¥JJ•*Æ„å3�¤Äß–B¥H¥)¥�JJu„%%©R!­*Æ
Æ­'þ$@�0B¥Hå)¥JJ•*Æ„å3�¤Äß–B¥Hå)¥�JJu„%%©R!­*ÆÆí'þ$@�0Z¥H%)¥JJ•*Æ„å3sÄĐߖB¥H%)
¥�JJu„%%©R!­*ÆÆmOü$@�0Z¥He)¥JJ•*Æ„å3sÄĐߖB¥He)¥�JJu„%%©R!­*ÆÆ-Oü$@�0B¥ˆ%)¥JJ•*Æ
„å3�$ĐߖB¥ˆ%)¥�JJu„%%©R!­*ÆÆ­Oü$@�0Z¥ˆe)¥JJ•*Æ„å3s�ĐߖB
If I connect the GPS or IMU to my pc using a usb-to-serial transceiver, they work fine so the mbed is at fault somewhere.

26 Feb 2010

Try, correct serial values :

maybe You schould write    pc.baud(115200);

Regards

macc

26 Feb 2010

Thanks for your reply!

921600 baud is a correct serial value. In the output snippet you'll see 'mbed Serial Terminal' so 921600 works happily.

26 Feb 2010
Mark B wrote:
I would simply like some way of attaching an interrupt when a whole sentence is received

Hi Mark

I've just written some code to receive lines from a serial device which sends out a line once per second terminated with <LF><CR>. I made the code so you can configure the new line termination.

It works on the serial interrupt, when the new line is seen it raises a delegate (I'm using the signals and slots code from here which is nice for this). You can then hook whatever you like onto the delegate; in my case it is to decode the string into an index of a sensor and the temperature associated with it.

My code might not be lightweight - I am using the streams and queues from the C++ libraries, but it might give you some ideas. I have it running with the mbed transmitting from one serial port to another for test purposes, so you could evaluate what I have done just with an mbed and a link.

Let me know if you want the code to look at. I'm not going to publish it generally for now because I'm changing it to adding tx for devices which need requests before they send a response.

Regards
Daniel

26 Feb 2010

Hi Igor, thanks for your reply!

Igor Skochinsky wrote:

http://mbed.org/projects/tickets/ticket/5

http://mbed.org/forum/mbed/topic/265/

I'd like to point out that the comms at 921600 is working between the mbed and the PC. The mbed just isn't receiving correctly from my other serial devices yet.

 

 

26 Feb 2010

With regards to the serial feedthrough- all is sorted- User Error! (I had the IMU set up as the GPS baud and vice versa!)

11 Jun 2010

Hi Daniel

 I am also working on a  serial device which sends out a line once per second not terminated but initialised with <LF><CR>.

Just wondered if you could publish or let me have a look at the code you mentioned?
Sorry to ask just after some ideas;) 

See my topic "Battery monitor Victron BMV602 - RS232/TTL serial port"


Best regards
John

11 Jun 2010
user avatar John Chilvers wrote:
Just wondered if you could publish or let me have a look at the code you mentioned?

Hi John

I've sent you a private message.

Regards
Daniel