send it with a queue to a task.
That is fine for low bandwidth comms, such as receiving key presses, but
very inefficient for high bandwidth comms where a circular buffer or DMA
is better.
while (1)
{
char string_received;
if(xQueueReceive( UART_queue , &string_received , 1000))
{
if( string_received=='s' )
{
LATAbits.LATA0=1;
}
else LATAbits.LATA0=0;
}
UART1PutChar(string_received);
}
}
If you receive only one character then this code will print out that
character every 1000 ticks. That is because you have the queue receive
timeout set to 1000, and print the character stored in string_received
whether a new value was received on the queue or not. Moving the
UART1PutChar() call inside the if() statement would fix that.
void attribute((interrupt, noautopsv)) _U1RXInterrupt(void)
I’m guessing this is a PIC32? Please read the documentation page for
this port as the way you are defining your interrupt is going to waste a
lot of RAM (although it will work).
xQueueSend(UART_queue , &data_in , 1000); // send data via queue
xQueueSend() cannot be called from an interrupt and
definitely cannot
attempt to block in an interrupt. Please use
xQueueSendFromISR()
instead and be sure to read the FAQs, especially the FAQ
“My application does not
run, what could be wrong?”.
Regards.