Skip to content

Instantly share code, notes, and snippets.

@DatanoiseTV
Created July 21, 2022 18:49
Show Gist options
  • Save DatanoiseTV/5e5059a4e3947e1859e5af303d7464d9 to your computer and use it in GitHub Desktop.
Save DatanoiseTV/5e5059a4e3947e1859e5af303d7464d9 to your computer and use it in GitHub Desktop.
#include "common.h"
#include "pico/sleep.h"
#include "hardware/clocks.h"
#include "hardware/rosc.h"
#include "hardware/structs/scb.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;
volatile uint32_t scb_orig, en0_orig, en1_orig;
#ifdef __cplusplus
extern "C"
{
#endif
// this was used to test if the interrupt is firing.
void gpio_callback(uint gpio, uint32_t events)
{
gpio_put(15, 1); // debug led
printf("gpio_callback from gpio %d: %i\n", gpio, events);
uint8_t dummy[1];
radio.read(dummy, 1);
gpio_put(15, 0);
}
void setup_radio()
{
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(1, 1, 0);
// 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();
}
int main(void)
{
stdio_init_all();
// initialize the transceiver on the SPI bus
setup_radio();
// Wake GPIO
gpio_init(14);
gpio_set_dir(14, GPIO_IN);
gpio_pull_up(14);
// gpio_pull_up(0);
//
// Debug LED
gpio_init(15);
gpio_set_dir(15, GPIO_OUT);
// This works and sees interrupts, but dormant mode doesn't
// gpio_set_irq_enabled_with_callback(14, GPIO_IRQ_EDGE_FALL, 1, gpio_callback);
while (1)
{
if (radio.available())
{
uint8_t payloadSize = radio.getDynamicPayloadSize();
uint8_t payload[payloadSize];
radio.read(&payload, payloadSize);
// radio.stopListening();
printf("Payload size: %i\n", payloadSize);
for (int i = 0; i < payloadSize; i++)
{
printf("%02X ", payload[i]);
}
printf("\n");
radio.startListening();
// Enter dormant mode after processing packet
sleep_run_from_xosc();
sleep_goto_dormant_until_pin(14, 0, false); // Wait till pin 14 is low.
// Perform dummy read to clear the nRF24L01+ IRQ flag
uint8_t dummy[1];
radio.read(dummy, 1);
}
}
}
#ifdef __cplusplus
}
#endif
@2bndy5
Copy link

2bndy5 commented Jul 21, 2022

The trailing edge will be the one that returns to HIGH. Remember that leading or trailing edges are not dependent on state of the signal between them. I still think this call should be

sleep_goto_dormant_until_pin(14, true, false); // Wait till pin 14 is low. (detects leading edge)

A falling edge is synonymous with "trailing"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment