Reputation: 145
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.
Upvotes: 1
Views: 2133
Reputation: 11
If you are using simulation tool, even if you read the whole rx fifo it doesn't clear the flag.
Upvotes: 0
Reputation: 31
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
Upvotes: 1