Page 1 of 1
UART Rx event
Posted: Wed Mar 18, 2015 4:22 pm
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?
Re: UART Rx event
Posted: Wed Mar 18, 2015 4:25 pm
by Giovanni
The UART driver uses callbacks in order to communicate relevant events. See the configuration structure documentation.
Giovanni
Re: UART Rx event
Posted: Wed Mar 18, 2015 4:41 pm
by JoVM
@Giovanni: I need to reinvoke uartStartReceive after each character received? I use the callbacks rxchar and rxend allready.
Re: UART Rx event
Posted: Wed Mar 18, 2015 4:46 pm
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
Re: UART Rx event
Posted: Wed Mar 18, 2015 5:16 pm
by JoVM

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.
Re: UART Rx event
Posted: Wed Mar 18, 2015 7:00 pm
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
Re: UART Rx event
Posted: Wed Mar 18, 2015 8:02 pm
by JoVM
I agree it's the least efficient method. Nice state implementation cause sometimes you just want to bang the port for bytes.