How to react to incoming UART Messages?

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Stomper85
Posts: 23
Joined: Tue Mar 19, 2013 1:25 pm

How to react to incoming UART Messages?

Post by Stomper85 »

Hi,

i need some help - i want to do following:

I have serial connection to a PC and I want to send commands from PC to the Board.

A command from the PC could be "comm_setRelais1" or what ever.

My idea was, to send escape sing in front and after each command, so that i can parse the string with chibi easyly.
But it is not so easy as I thought.

I have no idea, wich Driver Routine I should use - how do the different receive methods behave?
Does uartStartReceive capture ALL received signs? What happens if buffer is full? Do I have to manualy empty it?
I couldn't find any good example or explanation on the UART Driver for such things - is there a part in the Docu I have missed?

Best regards
Stomper
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to react to incoming UART Messages?

Post by Giovanni »

Hi,

The Serial driver is better than the UART driver in that scenario, you can read one char at time because the driver is buffered.

Giovanni
Stomper85
Posts: 23
Joined: Tue Mar 19, 2013 1:25 pm

Re: How to react to incoming UART Messages?

Post by Stomper85 »

Thanks for that information.

Is there some example code how to manage receiving strings with the UART Driver?

And:
Stomper85 wrote:Hi,
What happens if buffer is full? Do I have to manualy empty it?


Best regards
Stomper
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to react to incoming UART Messages?

Post by Giovanni »

Yes, look into shell.c, there is a function reading lines of text using streams (so SERIAL driver, not UART driver).

Giovanni
Stomper85
Posts: 23
Joined: Tue Mar 19, 2013 1:25 pm

Re: How to react to incoming UART Messages?

Post by Stomper85 »

But in your first post you said, the UART Driver would be better.
What should I use now?

SERIAL or UART?

And how does the Buffer behave? Is it a ring-buffer or do I have to empty it manually?
What happens if several messages coming in very fast?

Isn´t there a small code snippet to see how to use UART the right way as receiver?
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: How to react to incoming UART Messages?

Post by Giovanni »

I wrote that serial would be better...

It has ring buffers and you are responsible for reading them quick enough, no explicit empting required.

Giovanni
Stomper85
Posts: 23
Joined: Tue Mar 19, 2013 1:25 pm

Re: How to react to incoming UART Messages?

Post by Stomper85 »

Sorry,

I got that wrong.

Normaly I am hardware developer - so software is kind of strange for me :D

I try the SERIAL driver, the examples of the shell.c should do.

Best regards
Stomper
Post Reply