From 699a8218f7362436ed1ab8dad9f912a6e1abc9a6 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Fri, 29 Nov 2024 18:21:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0485=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=89=B9=E5=AE=9A=E5=91=BD=E4=BB=A4=E7=9A=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 1 + inc/RS485.h | 11 +++++++++++ src/RS485.c | 29 +++++++++++++++++++++++++++++ src/ultrasonic_driver.c | 3 ++- 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 inc/RS485.h create mode 100644 src/RS485.c diff --git a/CMakeLists.txt b/CMakeLists.txt index efb9a6f..713384c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,6 +29,7 @@ set(TARGET_C_SRC ${CMAKE_SOURCE_DIR}/src/systick.c ${CMAKE_SOURCE_DIR}/src/ultrasonic_driver.c ${CMAKE_SOURCE_DIR}/src/mlx90614.c + ${CMAKE_SOURCE_DIR}/src/RS485.c ) add_executable(xlsw_3dp_ultrasonic_300K ${TARGET_C_SRC}) diff --git a/inc/RS485.h b/inc/RS485.h new file mode 100644 index 0000000..ee2dbd0 --- /dev/null +++ b/inc/RS485.h @@ -0,0 +1,11 @@ +// +// Created by dell on 24-11-29. +// + +#ifndef RS485_H +#define RS485_H + +#include +#include + +#endif //RS485_H diff --git a/src/RS485.c b/src/RS485.c new file mode 100644 index 0000000..16d6164 --- /dev/null +++ b/src/RS485.c @@ -0,0 +1,29 @@ +// +// Created by dell on 24-11-29. +// + +#include "RS485.h" +#include "gd32e23x.h" +#include "systick.h" +#include +#include + +#define MAX_CMD_SIZE 16 +#define BUFSIZE 8 + +static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE]; +static char *strchr_pointer = NULL; + +static int bufindr = 0; +static int bufindw = 0; +static int buflen = 0; + +bool code_seen(char code) +{ + strchr_pointer = strchr(cmdbuffer[bufindr], code); + return (strchr_pointer != NULL); //Return True if a character was found +} +float code_value(void) +{ + return (strtod(&cmdbuffer[bufindr][strchr_pointer - cmdbuffer[bufindr] + 1], NULL)); +} \ No newline at end of file diff --git a/src/ultrasonic_driver.c b/src/ultrasonic_driver.c index 2877c80..bc7c7ae 100644 --- a/src/ultrasonic_driver.c +++ b/src/ultrasonic_driver.c @@ -46,8 +46,9 @@ void usart_config(void) 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_mode_set(USART_GPIO_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, USART_EN_PIN); gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, USART_EN_PIN); + gpio_bit_write(USART_GPIO_PORT, USART_EN_PIN, SET); /* USART configure */ usart_deinit(USART0_PHY);