From 70e3e162aebf7cecfe4699a665886c285dea66e2 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Thu, 28 Nov 2024 17:23:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0RS485=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/ultrasonic_driver.h | 4 +++- openocd_gd32e230f4.cfg | 2 +- src/ultrasonic_driver.c | 12 ++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/inc/ultrasonic_driver.h b/inc/ultrasonic_driver.h index 614d213..d4db545 100644 --- a/inc/ultrasonic_driver.h +++ b/inc/ultrasonic_driver.h @@ -34,12 +34,14 @@ #define USART_RCU RCU_USART0 #define USART_GPIO_RCU RCU_GPIOA -#define USARET_GPIO_PORT GPIOA +#define USART_GPIO_PORT GPIOA #define USART_TX_PIN GPIO_PIN_2 #define USART_RX_PIN GPIO_PIN_3 #define USART0_PHY USART0 #define USART_BAUDRATE 115200U +#define USART_EN_PIN GPIO_PIN_4 + #define US_TRAN_GPIO_RCU RCU_GPIOB #define US_TRAN_GPIO_PORT GPIOB #define US_TRAN_PIN GPIO_PIN_1 diff --git a/openocd_gd32e230f4.cfg b/openocd_gd32e230f4.cfg index 8484dd8..ca19139 100644 --- a/openocd_gd32e230f4.cfg +++ b/openocd_gd32e230f4.cfg @@ -1,7 +1,7 @@ # 连接cmsis-dap(喝粥) ; interface cmsis-dap source [find interface/cmsis-dap.cfg] - +; source [find interface/jlink.cfg] # 选择SWD transport select swd diff --git a/src/ultrasonic_driver.c b/src/ultrasonic_driver.c index 2a8061c..2877c80 100644 --- a/src/ultrasonic_driver.c +++ b/src/ultrasonic_driver.c @@ -39,11 +39,15 @@ void usart_config(void) rcu_periph_clock_enable(USART_GPIO_RCU); rcu_periph_clock_enable(USART_RCU); - gpio_af_set(USARET_GPIO_PORT, GPIO_AF_1, GPIO_PIN_2 | GPIO_PIN_3); + gpio_af_set(USART_GPIO_PORT, GPIO_AF_1, GPIO_PIN_2 | GPIO_PIN_3); - /* configure USART Tx as alternate function push-pull */ - gpio_mode_set(USARET_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_TX_PIN | USART_RX_PIN); - gpio_output_options_set(USARET_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, USART_TX_PIN | USART_RX_PIN); + /* configure USART Tx&Rx as alternate function push-pull */ + gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_TX_PIN | USART_RX_PIN); + gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, USART_TX_PIN | USART_RX_PIN); + + /* configure RS485 EN Pin */ + gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_PULLUP, USART_EN_PIN); + gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART_EN_PIN); /* USART configure */ usart_deinit(USART0_PHY);