Skip to content

[Question] Wake up from IRQ on RP2040? #857

@DatanoiseTV

Description

@DatanoiseTV

I am currently having trouble with RF24 to get the RP2040 to wake up from dormant mode.
It sucessfully received one packet and then stops receiving. Only resetting the MCU makes it receive another packet.

#include "common.h"
#include "pico/sleep.h"
#include "pico/stdlib.h"  // printf(), sleep_ms(), getchar_timeout_us(), to_us_since_boot(), get_absolute_time()
#include "pico/bootrom.h" // reset_usb_boot()
#include <tusb.h>         // tud_cdc_connected()
#include <RF24.h>         // RF24 radio object

RF24 radio(1, 5);

// on every successful transmission
uint8_t payload[4] = {0x23, 0x42, 0x05, 0x00};
uint8_t address[][6] = {"1Node", "2Node", "3Node", "4Node", "5Node", "6Node"};

bool initialized = 0;

#ifdef __cplusplus
extern "C"
{
#endif

    int main(void)
    {

        stdio_init_all();
        // initialize the transceiver on the SPI bus
        if (!radio.begin())
        {
            printf("radio hardware is not responding!!\n");
        }
        else
        {
            printf("radio hardware is responding!!\n");
        }

        radio.setDataRate(RF24_250KBPS);

        radio.setChannel(110);
        radio.maskIRQ(0, 0, 1);

        // Set the PA Level low to try preventing power supply related problems
        // because these examples are likely run with nodes in close proximity to
        // each other.
        radio.setPALevel(RF24_PA_MIN); // RF24_PA_MAX is default.

        // save on transmission time by setting the radio to only transmit the
        // number of bytes we need to transmit a float
        radio.setPayloadSize(sizeof(payload) / sizeof(uint8_t)); // float datatype occupies 4 bytes

        radio.enableDynamicPayloads();
        printf("Payload size is %d\n", sizeof(payload) / sizeof(uint8_t));

        // set the TX address of the RX node into the TX pipe
        radio.openWritingPipe(address[0]); // always uses pipe 0

        // set the RX address of the TX node into a RX pipe
        radio.openReadingPipe(1, address[1]); // using pipe

        radio.printDetails();       // (smaller) function that prints raw register values
        radio.printPrettyDetails(); // (larger) function that prints human readable data

        radio.startListening();

        // Wake GPIO
        gpio_init(0);
        gpio_set_dir(0, GPIO_IN);
        gpio_set_input_hysteresis_enabled(0, 0);

        // Debug LED
        gpio_init(15);
        gpio_set_dir(15, GPIO_OUT);

        while (1)
        {

            gpio_put(15, 0);

            if (radio.available())
            {
                gpio_put(15, 1);
                uint8_t payloadSize = radio.getDynamicPayloadSize();
                uint8_t payload[payloadSize];

                radio.read(&payload, payloadSize);

                printf("Payload size: %i\n", payloadSize);

                for (int i = 0; i < payloadSize; i++)
                {
                    printf("%02X ", payload[i]);
                }
                printf("\n");

                // radio.startListening();

                sleep_run_from_xosc();
                sleep_goto_dormant_until_pin(0, 0, false); // Wait till pin 0 is low.
            }
        }
    }

#ifdef __cplusplus
}
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions