From 814a7422602da0a3d72c0edbec95b7dad12799b2 Mon Sep 17 00:00:00 2001 From: huang <1085210385@qq.com> Date: Fri, 1 Mar 2024 16:35:02 +0800 Subject: [PATCH] add usart3 connect --- .../XiZi_IIoT/board/ch32v307vct6/board.c | 26 ++++++++++++++----- .../third_party_driver/uart/connect_uart.c | 18 ++++++++++++- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/board.c b/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/board.c index 4d7f3875d..addee633a 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/board.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/board.c @@ -60,6 +60,8 @@ static uint32_t _SysTick_Config(uint32_t ticks) extern RxBuffer2; extern uint16_t UART_ReceiveData(USART_TypeDef* USARTx); +extern void UART_SendData(USART_TypeDef* USARTx, uint16_t Data); + void InitBoardHardware() { _SysTick_Config(SystemCoreClock / TICK_PER_SECOND); @@ -78,10 +80,22 @@ void InitBoardHardware() KPrintf("board init done.\n"); KPrintf("start okernel...\n"); - // while (1) { - // uint32_t ans = (uint32_t)UART_ReceiveData(USART3); - // KPrintf("%d\n", ans); - // for (int i = 0; i < 10000; i++) - // ; - // } + + uint16_t ans = 0; + uint16_t recv_data = 0; + uint16_t send_data = 0; + int cnt = 0; + while (1) { + + recv_data = UART_ReceiveData(USART3); + + if (recv_data < 58 && recv_data > 47) { + ans = recv_data; + + KPrintf("recv data: %d\n", ans - 48); + } + send_data = ans + 17; + KPrintf("send data: %d\n", send_data); + UART_SendData(USART3, send_data); + } } diff --git a/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/third_party_driver/uart/connect_uart.c b/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/third_party_driver/uart/connect_uart.c index e2db436f2..e3e2b50d0 100644 --- a/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/third_party_driver/uart/connect_uart.c +++ b/Ubiquitous/XiZi_IIoT/board/ch32v307vct6/third_party_driver/uart/connect_uart.c @@ -177,6 +177,17 @@ static const struct SerialDataCfg data_cfg_init = { .serial_timeout = WAITING_FOREVER, }; +static const struct SerialDataCfg data_cfg_init_uart3 = { + .serial_baud_rate = BAUD_RATE_115200, + .serial_data_bits = DATA_BITS_8, + .serial_stop_bits = STOP_BITS_1, + .serial_parity_mode = PARITY_NONE, + .serial_bit_order = BIT_ORDER_LSB, + .serial_invert_mode = NRZ_NORMAL, + .serial_buffer_size = SERIAL_RB_BUFSZ, + .serial_timeout = WAITING_FOREVER, +}; + /*manage the serial device operations*/ static const struct SerialDrvDone drv_done = { .init = SerialInit, @@ -259,7 +270,12 @@ void USART1_IRQHandler(void) uint16_t UART_ReceiveData(USART_TypeDef* USARTx) { - return (uint16_t)(USARTx->DATAR); + return (uint16_t)(USARTx->DATAR & (uint16_t)0x01FF); +} + +void UART_SendData(USART_TypeDef* USARTx, uint16_t Data) +{ + USARTx->DATAR = (Data & (uint16_t)0x01FF); } #ifdef BSP_USING_UART2