FreeRTOS xTaskCreatePinnedToCore for rak4631 LoRa send and receive

My platformio.ini file contains the following

[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino

I want to use the FreeRTOS method xTaskCreatePinnedToCore() from task.h however when I use

#include <task.h>

I get the compilation error

error: ‘xTaskCreatePinnedToCore’ was not declared in this scope

Is it possible to do this without using the ESP32 module?

I want to have a task running to receive data from the SX126x LoRa chip whilst the main loop is concerned with sending data

I accept that this might not be the best way to achieve my desired outcome, I want to receive data and send data, so it might be simpler (or even preferred) to perform the send operation after receiving data.

Hello @billr ,

xTaskCreatePinnedToCore is not defined for RAK4631, because the Nordic nRF52 has only one core (The ESP32 has two cores), so the command makes no sense.

But you can use xTaskCreate() instead.

It is not a good idea to run concurrent running tasks for sending and receiving, unless you use semaphores to block the other task while a sending or receiving is ongoing.

What you can do is (assuming you use LoRa P2P)

  • Put LoRa transceiver in receive mode
  • When packet is ready to send, put LoRa transceiver into send mode and send the packet
  • When callback TX Done or TX Error is called handle the result
  • After handling event, put LoRa transceiver back to receive mode

When you are using LoRaWAN protocol, receiving is only possible after a TX was done.

Of course: I’d actually answered the question myself already. It was 3am here and I think I’d just thought myself into a corner. That will teach me to try and “get it finished” :joy: :rofl:

Thank you @beegee

What you can do is (assuming you use LoRa P2P)

  • Put LoRa transceiver in receive mode
  • When packet is ready to send, put LoRa transceiver into send mode and send the packet
  • When callback TX Done or TX Error is called handle the result
  • After handling event, put LoRa transceiver back to receive mode

When you are using LoRaWAN protocol, receiving is only possible after a TX was done.

This was the plan:

  1. set to Rx mode
  2. place received data into a queue
  3. when queue contains required data switch to Tx mode
  4. empty queue and send data
  5. rinse and repeat

except for some reason I just didn’t think about xTaskCreate … but like I said, it was really late

Thanks again @beegee

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.