0

I want to poll to check if there is any data to be read for serial communication from PC in Pi pico. i do not want the blocking types like getchar for scanf to be used in microcontroller. Is there a way to poll?

  • Why not set the UART on interrupt to automatically process data as it becomes available? There is no need to block, your read-interrupt will simply tell you you have data to process (generally done by setting a global flag (e.g. `static volatile bool havedata;`) and then in your `main()` function you have `if (havedata) { /* process it */; havedata = 0; }` as part of your main-program `while (1) { ... }` loop. – David C. Rankin Jun 10 '23 at 23:54
  • The [Pico Examples - UART Advanced](https://github.com/raspberrypi/pico-examples/blob/master/uart/uart_advanced/uart_advanced.c) example shows a similar approach for reading and writing when data is ready using interrupts. The only difference is they process the data in the interrupt service request (ISR) function (which is generally discouraged due to processing time potentially taking longer than the time the next interrupt occurs), but here the while test on `uart_is_readable()` mitigates that to some extent. It will give you the basic approach. – David C. Rankin Jun 11 '23 at 00:01
  • I was searching for a similar function which is available in micropython version "serial.poll()" in C sdk. – Yatin Goyal Jun 11 '23 at 06:41
  • No such animal unless you use FreeRTOS. – David C. Rankin Jun 11 '23 at 08:13

0 Answers0