UART Rx event

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

UART Rx event

Post by JoVM »

I have a thread doing:

Code: Select all

 while (TRUE) {
    uartStartReceive(&UARTD1, 1, rxbuffer);
   chThdSleepMilliseconds(100);}


This thread need to receive a RxNE event. Is this done?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: UART Rx event

Post by Giovanni »

The UART driver uses callbacks in order to communicate relevant events. See the configuration structure documentation.

Giovanni
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: UART Rx event

Post by JoVM »

@Giovanni: I need to reinvoke uartStartReceive after each character received? I use the callbacks rxchar and rxend allready.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: UART Rx event

Post by Giovanni »

rxchar is invoked while there is NOT an uartStartReceive() in progress, rxchar is interrupt-driver while uartStartReceive() does the transfer using DMA with a single interrupt at the end.

I suggest you give a look to the state machine of the driver.

Giovanni
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: UART Rx event

Post by JoVM »

Image
In the state diagram it is not really clear what is interrupt driven.

I see some code doing (u->CR1) |= USART_CR1_RXNEIE; and then it uses rxChar as reception. But in previous post you state this is not prevered.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: UART Rx event

Post by Giovanni »

Don't think about interrupts, it was an implementation detail. The important part are the states, if you don't explicitly go in RX_ACTIVE the driver will provide you a callback for each received character (rxchar), of course this implies an interrupt for each character received and this is the least efficient mode. Using uartStartReceive() makes so that you only get one interrupt at the end of the whole transfer, then a callback is called from the ISR (rxend).

Using the various modes and states is up to you and your requirements.

Giovanni
JoVM
Posts: 89
Joined: Thu Mar 12, 2015 12:13 pm

Re: UART Rx event

Post by JoVM »

I agree it's the least efficient method. Nice state implementation cause sometimes you just want to bang the port for bytes.
Post Reply