我目前正在开发一个小型库,它简化了433 the射频模块的使用。我现在面临的问题是,当我试图在UART0_RX Pin (GPIO1)上创建一个IRQ中断时,Pico将调用回调函数,执行第一条指令,然后冻结。
我在网上找不到任何关于它的东西。下面是我的代码片段:
#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;
}我已经尝试了这段代码的不同变体,不同的参数等等。我已经设置了一个GPIO,这也冻结了。
发布于 2022-06-29 10:16:33
不应在中断处理程序中使用睡眠函数。
https://raspberrypi.github.io/pico-sdk-doxygen/group__sleep.html
删除sleep_ms(500);从onDataReceived()中删除
您可以使用busy_wait_us()代替
https://stackoverflow.com/questions/69710084
复制相似问题