From b98b4311d2e3d735a6920786e086be968952384b Mon Sep 17 00:00:00 2001 From: zwsd Date: Tue, 28 Jun 2022 11:52:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=B5=B5=E8=80=81=E5=B8=88?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 37 ++++++++++++++++++++++++++++++++++++- zstm32uart_irq_rx_service.c | 12 ++++++++++++ zstm32uart_irq_rx_service.h | 8 ++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 zstm32uart_irq_rx_service.c create mode 100644 zstm32uart_irq_rx_service.h diff --git a/README.md b/README.md index 43bd638..f5515b6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ -# copyZ_zstm32uart_irq_rx_service +# zstm32uart_irq_rx_service +## USAGE + +``` + 功能描述: + 初始化串口,让串口以中断的形式,持续不断的接收消息,接收到消息通过HOOK_ZUART_RxCpltCallback回调上来,同时如果串口发生异常,自动重启串口接收。 + +``` + +```c + +static zstm32uart_t s_uarts[] = { + { + .huart = &huart2, + } // +}; +... +void HOOK_ZUART_RxCpltCallback(UART_HandleTypeDef* huart, uint8_t rxdata) { + if (huart == &huart2) { + /** + * 处理接收到串口消息 + */ + + } +} +... +void main() { + .... + + //启动串口接收 + uart_service_start_all_uart_rx(s_uarts, ARRARY_SIZE(s_uarts)); + + ... +} + +``` \ No newline at end of file diff --git a/zstm32uart_irq_rx_service.c b/zstm32uart_irq_rx_service.c new file mode 100644 index 0000000..148b651 --- /dev/null +++ b/zstm32uart_irq_rx_service.c @@ -0,0 +1,12 @@ +#include "zstm32uart_irq_rx_service.h" + +static zstm32uart_t* s_table; +static int s_table_size; + +void uart_service_start_all_uart_rx(zstm32uart_t* table, int size) { + s_table = table; + s_table_size = size; + for (size_t i = 0; i < s_table_size; i++) { + HAL_UART_Receive_IT(s_table[i].huart, &s_table->rxbuf, 1); + } +} \ No newline at end of file diff --git a/zstm32uart_irq_rx_service.h b/zstm32uart_irq_rx_service.h new file mode 100644 index 0000000..092b570 --- /dev/null +++ b/zstm32uart_irq_rx_service.h @@ -0,0 +1,8 @@ +#include "main.h" + +typedef struct { + UART_HandleTypeDef* huart; + uint8_t rxbuf; +} zstm32uart_t; + +void uart_service_start_all_uart_rx(zstm32uart_t* table, int size); \ No newline at end of file