1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
开启uart_rxfifo_tout中断,一次性发送数据给单片机,理论上串口接收超时中断只能触发一次中断,但却触发了两次中断rxfifo_tout中断。求解答。
发送数据Code: Select all 0x61 0x61 0x61 总返回数据Code: Select all 0x61 0x61 0x61 0x4F 0x4B 0x01 0x4F 0x4B 0x02 (0x4F 0x4B为OK) Code: Select all #include #include #include "soc/uart_periph.h" #include "driver/uart.h" #include "soc/uhci_reg.h" #include "driver/gpio.h" #include "esp_event.h" #include "esp_log.h" TaskHandle_t rx_task_handle; #define UART_LOG "uart_log" //串口TAG #define UART1_RX_IO GPIO_NUM_9 //UART1_RX引脚 -> GPIO9 #define UART1_TX_IO GPIO_NUM_10 //UART1_TX引脚 -> GPIO10 #define BUFF_SIZE 1024 uart_isr_handle_t uart1_handle; uint8_t rxbuf[128]; uint16_t urxlen; static void IRAM_ATTR uart_intr_handle(void *arg) { volatile uart_dev_t *uart = &UART1; static uint8_t count = 0; count++; volatile uint8_t flag = 0; //标志位判断是否触发rxfifo_tout中断 if(uart->int_st.rxfifo_tout == 1) { uart_clear_intr_status(UART_NUM_1, UART_RXFIFO_TOUT_INT_CLR); flag = 1; //触发rxfifo_tout中断,标志位置1 } while (uart->status.rxfifo_cnt) { uint8_t c = uart->ahb_fifo.rw_byte; uart_tx_chars(UART_NUM_1, (char *)&c, 1); //返回数据 } if(flag) uart_tx_chars(UART_NUM_1, "OK", 2); //进入rxfifo_tout中断返回OK uart_tx_chars(UART_NUM_1,(char *)&count,1); //返回当前进入中断次数 } void app_main(void) { uart_config_t uart_conf = { .baud_rate = 115200, //波特率:115200 .data_bits = UART_DATA_8_BITS, //数据位:八位 .parity = UART_PARITY_DISABLE, //校验位:不校验 .stop_bits = UART_STOP_BITS_1, //停止位:1 .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, //硬件控制流:不启用 .source_clk = UART_SCLK_APB, //时钟总线:APB总线 }; uart_port_t uart_port = UART_NUM_1; //UART1 uart_param_config(uart_port, &uart_conf); uart_set_pin(uart_port, UART1_TX_IO, UART1_RX_IO, GPIO_NUM_NC, GPIO_NUM_NC); uart_driver_install(uart_port, BUFF_SIZE*2, 0, 0, NULL, 0); //关闭预先创建的uart中断 uart_isr_free(uart_port); uart_isr_register(uart_port, uart_intr_handle,NULL, ESP_INTR_FLAG_IRAM, &uart1_handle); uart_disable_intr_mask(uart_port, 0x001FFFFF); //关闭预先的串口中断 uart_enable_intr_mask(uart_port, UART_RXFIFO_TOUT_INT_ENA); //开启RXFIFO_TOUT中断 while(1) { vTaskDelay(1); } } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
313 浏览 0 评论
1170 浏览 1 评论
585浏览 6评论
483浏览 5评论
有没有办法在不使用混杂模式的情况下实现Wifi驱动程序接收缓冲区访问中断呢?
468浏览 5评论
467浏览 4评论
442浏览 4评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-26 12:17 , Processed in 0.698780 second(s), Total 43, Slave 37 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号