UART 串口中断接收问题

[复制链接]
查看80 | 回复7 | 2024-8-18 22:03:02 | 显示全部楼层 |阅读模式
按照 《零基础开发小安派-Eyes-S1【外设篇】——UART》 方法编译的代码,无法进入中断,串口接线正常,用轮询方法可以接到到串口数据。

//头文件
#include "bflb_mtimer.h"
#include "bflb_uart.h"
#include "bflb_gpio.h"
#include "board.h"

//设置名为uart1的外设句柄
static struct bflb_device_s* uart1;
struct bflb_device_s* gpio;

//定义需要轮询发送的数据
static uint8_t uart_txbuf[4] = { 0,1,2,3 };


static void uart_init(void);
// static void uart_isr(int irq, void *arg);

//中断服务函数,触发中断后会进入该函数

static void uart_isr(int irq, void *arg)
{
    printf("in put uart_isr ok");
    uint32_t intstatus = bflb_uart_get_intstatus(uart1);

   //这里注释了fifo管道的RX中断触发,fifo的触发方式也就是上面设置的字节数4,也就是要接收4个字节以上数据才会触发fifo中断

    if (intstatus & UART_INTSTS_RX_FIFO) {
        printf("rx fifo\r\n");
        while (bflb_uart_rxavailable(uart1)) {
            printf("0x%02x\r\n", bflb_uart_getchar(uart1));
        }
    }

   //接收超时中断,当一段时间内数据没有接收后便会停止,在触发中断后,轮询使用prtintf发送uart1接收到的字符,停止接收后清空中断标志等待下一次发送

    if (intstatus & UART_INTSTS_RTO) {
        printf("rto\r\n");
        while (bflb_uart_rxavailable(uart1)) {
            printf("0x%02x\r\n", bflb_uart_getchar(uart1));
        }
        bflb_uart_int_clear(uart1, UART_INTCLR_RTO);
    }
}


//初始化串口配置,如波特率,数据位和停止位
//tx_fifo_threshold 和 rx_fifo_threshold 参数设置表示为fifo中断的触发阈值

static void uart_init(void)
{
    struct bflb_device_s* gpio;
    struct bflb_uart_config_s cfg = {
        .baudrate = 115200,
        .data_bits = UART_DATA_BITS_8,
        .stop_bits = UART_STOP_BITS_1,
        .parity = UART_PARITY_NONE,
        .flow_ctrl = 0,
        .tx_fifo_threshold = 4,
        .rx_fifo_threshold = 4,
    };

    gpio = bflb_device_get_by_name("gpio");
    uart1 = bflb_device_get_by_name("uart1");

    //将GPIO_1和GPIO_0设置为TX和RX

    bflb_gpio_uart_init(gpio, GPIO_PIN_25, GPIO_UART_FUNC_UART1_TX);
    bflb_gpio_uart_init(gpio, GPIO_PIN_26, GPIO_UART_FUNC_UART1_RX);

    bflb_uart_init(uart1, &cfg);

    bflb_uart_txint_mask(uart1, false);
    bflb_uart_rxint_mask(uart1, false);
    bflb_irq_attach(uart1->irq_num, uart_isr, NULL);
    bflb_irq_enable(uart1->irq_num);

}


int main(void)
{
    board_init();
    uart_init();
    int i=0;
   
    //主函数每两秒轮询一次发送 uart_txbuf 数据
  
    while (1) {
        bflb_mtimer_delay_ms(2000);
        bflb_uart_put(uart1,uart_txbuf,4);
        printf("test ok 3 ");

        if(bflb_uart_rxavailable(uart1))
        printf("rx data ");

        //轮询接收
        i = bflb_uart_getchar(uart1);
        if(i !=-1){printf("0x%02x\r\n",i);}

    }
}
回复

使用道具 举报

WT_0213 | 2024-8-18 22:25:14 | 显示全部楼层
有没有可能轮询方法把数据接完了
回复 支持 反对

使用道具 举报

hnjztyx | 2024-8-18 22:46:54 | 显示全部楼层
不是的,我屏蔽轮询方法也测试过,屏蔽后就啥都看不到了,
回复 支持 反对

使用道具 举报

爱笑 | 2024-8-19 08:59:24 | 显示全部楼层
马上抓泽哥来给你瞧瞧!
用心做好保姆工作
回复 支持 反对

使用道具 举报

Ai-Thinker小泽 | 2024-8-19 10:11:21 | 显示全部楼层
换SDK,aithinker那个中断被屏蔽掉了
回复 支持 反对

使用道具 举报

hnjztyx | 2024-8-20 22:09:39 | 显示全部楼层
换哪一个?怎么换?有无教程?
回复 支持 反对

使用道具 举报

hnjztyx | 2024-8-24 14:26:40 | 显示全部楼层
hnjztyx 发表于 2024-8-20 22:09
换哪一个?怎么换?有无教程?

换了SDK  AiPi-BL618-Open-SDK  还是一样的
回复 支持 反对

使用道具 举报

hnjztyx | 2024-8-24 14:28:50 | 显示全部楼层
hnjztyx 发表于 2024-8-24 14:26
换了SDK  AiPi-BL618-Open-SDK  还是一样的

第一次烧录不行,重启后好了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则