Use queue in arduino

How can I send data from built-in serialevent () function of arduino to freertos queue ?
Serialevent () function does not run in arduino interrupt context nor run in any task so i can not use queuesend () nor queuesendfromisr () functions.

If it doesn’t run in an ISR or a task, where does it run?

I tested it without freertos and found that it run in background context. I think uart isr sent some condition variables to make serialevent() function run in background. I tested by put infinie loop inside loop() function of arduino, if serialevent() run in interrupt context, it should interrupt in the infinite loop whenI sent data to uart but it could not, when I removed infinite loop from loop(), the serialevent() could run when I sent data to uart.

I believe the answer is here:

https://assiss.github.io/arduino-zhcn/cn/Tutorial/SerialEvent.html

The comment reads this:

/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/

Thank you so much. The document show that serialevent() run in background and is not called from uart isr directly, but my problem is how to send data of uart rx read by serialevent() to freertos queue because queue function of freertos allow to be called from task or isr only.

I am not familiar with the Arduino platform but looking at this code, loop function is called from the idle task: Arduino_FreeRTOS_Library/variantHooks.cpp at master · feilipu/Arduino_FreeRTOS_Library · GitHub

So you should be okay calling queue send function from the loop function.

Thanks.

Thank you so much. Your suggestion is very useful for me.

If it is called from the Idle task then it is very important it doesn’t block - so you can only use a block time of 0.

2 Likes

Thank you so much. I did it.

1 Like