完善资料让更多小伙伴认识你,还能领取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); } } |
|
相关推荐
|
|
只有小组成员才能发言,加入小组>>
945 浏览 0 评论
1672 浏览 0 评论
请问一下我想用ESP8685直接替换ESP8266而不用写程序,可以让ESP8685直接通过之前ESP8266的外挂的flash运行程序吗
1330 浏览 1 评论
1233 浏览 1 评论
5021 浏览 2 评论
为blufi_device设置自定义名称,但是无法修改,为什么?
1253浏览 4评论
请问ESP32-S2-WROOM怎么获得ESP32-S2外接FLASH的唯一序列号?
927浏览 3评论
2338浏览 3评论
ESP-IDF的VScode插件的build按钮点击会报错的原因?
2526浏览 3评论
ESP-Jumpstart例程中第5个工程:5_cloud连接报错是哪里的问题?
1052浏览 2评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 05:41 , Processed in 0.498566 second(s), Total 39, Slave 32 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
370
