[英]Creating an IRQ for the Raspberry Pi Pico works in C but not C++?
[英]RPi Pico freezes on IRQ Interrupt call
我目前正在开发一个小型库,它可以简化 433MHz RF 模块的使用。 我现在面临的问题是,当我试图在 UART0_RX 引脚 (GPIO1) 上创建 IRQ 中断时,Pico 将调用回调 function,执行第一条指令然后冻结。
我在网上找不到任何相关信息。 这是我的代码片段:
#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 Pin IRQ,它也会冻结。
不应在中断处理程序中使用睡眠功能
https://raspberrypi.github.io/pico-sdk-doxygen/group__sleep.html
删除 sleep_ms(500); 从 onDataReceived()
您可以改用busy_wait_us()
如果您使用的是仿真工具,即使您读取了整个 rx fifo,它也不会清除标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.