Compare commits
2 Commits
V0.0.13
...
699a8218f7
Author | SHA1 | Date | |
---|---|---|---|
699a8218f7 | |||
70e3e162ae |
@@ -29,6 +29,7 @@ set(TARGET_C_SRC
|
|||||||
${CMAKE_SOURCE_DIR}/src/systick.c
|
${CMAKE_SOURCE_DIR}/src/systick.c
|
||||||
${CMAKE_SOURCE_DIR}/src/ultrasonic_driver.c
|
${CMAKE_SOURCE_DIR}/src/ultrasonic_driver.c
|
||||||
${CMAKE_SOURCE_DIR}/src/mlx90614.c
|
${CMAKE_SOURCE_DIR}/src/mlx90614.c
|
||||||
|
${CMAKE_SOURCE_DIR}/src/RS485.c
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(xlsw_3dp_ultrasonic_300K ${TARGET_C_SRC})
|
add_executable(xlsw_3dp_ultrasonic_300K ${TARGET_C_SRC})
|
||||||
|
11
inc/RS485.h
Normal file
11
inc/RS485.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
//
|
||||||
|
// Created by dell on 24-11-29.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef RS485_H
|
||||||
|
#define RS485_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#endif //RS485_H
|
@@ -34,12 +34,14 @@
|
|||||||
|
|
||||||
#define USART_RCU RCU_USART0
|
#define USART_RCU RCU_USART0
|
||||||
#define USART_GPIO_RCU RCU_GPIOA
|
#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_TX_PIN GPIO_PIN_2
|
||||||
#define USART_RX_PIN GPIO_PIN_3
|
#define USART_RX_PIN GPIO_PIN_3
|
||||||
#define USART0_PHY USART0
|
#define USART0_PHY USART0
|
||||||
#define USART_BAUDRATE 115200U
|
#define USART_BAUDRATE 115200U
|
||||||
|
|
||||||
|
#define USART_EN_PIN GPIO_PIN_4
|
||||||
|
|
||||||
#define US_TRAN_GPIO_RCU RCU_GPIOB
|
#define US_TRAN_GPIO_RCU RCU_GPIOB
|
||||||
#define US_TRAN_GPIO_PORT GPIOB
|
#define US_TRAN_GPIO_PORT GPIOB
|
||||||
#define US_TRAN_PIN GPIO_PIN_1
|
#define US_TRAN_PIN GPIO_PIN_1
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# 连接cmsis-dap(喝粥)
|
# 连接cmsis-dap(喝粥)
|
||||||
; interface cmsis-dap
|
; interface cmsis-dap
|
||||||
source [find interface/cmsis-dap.cfg]
|
source [find interface/cmsis-dap.cfg]
|
||||||
|
; source [find interface/jlink.cfg]
|
||||||
# 选择SWD
|
# 选择SWD
|
||||||
transport select swd
|
transport select swd
|
||||||
|
|
||||||
|
29
src/RS485.c
Normal file
29
src/RS485.c
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// Created by dell on 24-11-29.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "RS485.h"
|
||||||
|
#include "gd32e23x.h"
|
||||||
|
#include "systick.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#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));
|
||||||
|
}
|
@@ -39,11 +39,16 @@ void usart_config(void)
|
|||||||
rcu_periph_clock_enable(USART_GPIO_RCU);
|
rcu_periph_clock_enable(USART_GPIO_RCU);
|
||||||
rcu_periph_clock_enable(USART_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 */
|
/* configure USART Tx&Rx as alternate function push-pull */
|
||||||
gpio_mode_set(USARET_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_TX_PIN | USART_RX_PIN);
|
gpio_mode_set(USART_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);
|
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_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 configure */
|
||||||
usart_deinit(USART0_PHY);
|
usart_deinit(USART0_PHY);
|
||||||
|
Reference in New Issue
Block a user