1

I'm currently working on a small library that simplifies the use of 433MHz RF modules. The problem I'm facing right now is that when I'm trying to create an IRQ interrupt on the UART0_RX Pin (GPIO1), the Pico will call the callback function, execute the first instruction and then freeze.

I cannot find anything about it online. Here is my code snippet:

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/irq.h"
#include "hardware/uart.h"

void onDataReceived()
{
    // Let the LED blink on GPIO16
    gpio_put(16, 1);

    /*
    *   Annnnnnd.... freeze, the Pico won't execute further
    *   instructions. It stays frozen until reset.
    */

    sleep_ms(500);
    gpio_put(16, 0);
    sleep_ms(500);
}

int main()
{
    // Normal initialization
    stdio_init_all();
    gpio_init(PICO_DEFAULT_LED_PIN);
    gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
    gpio_init(16);
    gpio_set_dir(16, GPIO_OUT);

    // Setup UART communication
    uart_init(uart0, 115200);
    gpio_set_function(1, GPIO_FUNC_UART);
    gpio_set_function(0, GPIO_FUNC_UART);

    // Setup IRQ handler
    irq_set_exclusive_handler(UART0_IRQ, onDataReceived);
    irq_set_enabled(UART0_IRQ, true);

    // Only call interrupt when RX data arrives
    uart_set_irq_enables(uart0, true, false);

    while (1)
    {
        // Default Pico LED blinking
        gpio_put(PICO_DEFAULT_LED_PIN, 1);
        sleep_ms(200);
        gpio_put(PICO_DEFAULT_LED_PIN, 0);
        sleep_ms(200);
    }

    return 0;
}

I already tried different variations of this code, different parameters etc. And I have had setup a GPIO Pin IRQ, which also freeze.

The Origin
  • 135
  • 1
  • 10
  • Don't put massive delays in your interrupt callback function. And also consider DMA if that's an option. Also, watch dog is what...? Disabled? Merrily asleep? Angry? – Lundin Oct 25 '21 at 14:55
  • The delays in the interrupt cb are just for testing, I of course have tried without them. I should take a look into DMA. And the watch dog is disabled. I mostly relied on the pico example code, which should work (or why should it be in the examples?). I also think that the watch dog would be a bit too messy for my purpose (I want to make a library) – The Origin Oct 25 '21 at 15:13

2 Answers2

1

sleep function should not be used in interrupt handler

https://raspberrypi.github.io/pico-sdk-doxygen/group__sleep.html

remove sleep_ms(500); from onDataReceived()

you may use busy_wait_us() instead

0

If you are using simulation tool, even if you read the whole rx fifo it doesn't clear the flag.