generated from hulk/gd32e23x_template
更改为非自动换向SP3485接口芯片,更改代码预期适配
This commit is contained in:
parent
1f64a500f9
commit
da00f1d758
@ -51,7 +51,7 @@
|
|||||||
#define USART_PHY USART0
|
#define USART_PHY USART0
|
||||||
#define USART_PHY_BAUDRATE 115200U
|
#define USART_PHY_BAUDRATE 115200U
|
||||||
#define RS485_EN_PORT GPIOA
|
#define RS485_EN_PORT GPIOA
|
||||||
#define RS485_EN_PIN GPIO_PIN_4
|
#define RS485_EN_PIN GPIO_PIN_1
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
#include "gd32e23x.h"
|
#include "gd32e23x.h"
|
||||||
#include "board_config.h"
|
#include "board_config.h"
|
||||||
|
|
||||||
void usart_config(void);
|
|
||||||
|
|
||||||
void rs485_config(void);
|
void rs485_config(void);
|
||||||
|
|
||||||
#endif //USART_H
|
#endif //USART_H
|
||||||
|
@ -21,12 +21,12 @@ void process_command(uint8_t *cmd, size_t length) {
|
|||||||
sprintf(combined_str, "%c%c", cmd[3], cmd[4]);
|
sprintf(combined_str, "%c%c", cmd[3], cmd[4]);
|
||||||
if (strcmp(combined_str, "M1") == 0) {
|
if (strcmp(combined_str, "M1") == 0) {
|
||||||
ultrasonic_distance_report();
|
ultrasonic_distance_report();
|
||||||
} else if (strcmp(combined_str, "M2") == 0) {
|
// } else if (strcmp(combined_str, "M2") == 0) {
|
||||||
gd60914_tempture_report();
|
// gd60914_tempture_report();
|
||||||
} else if (strcmp(combined_str, "M3") == 0)
|
// } else if (strcmp(combined_str, "M3") == 0)
|
||||||
{
|
// {
|
||||||
printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
// printf("%c%c%c%c%c%c", 0xB5, 0xF1, 0x02, 0x6F, 0x6B, 0xCC);
|
||||||
fwdgt_reset_mcu();
|
// fwdgt_reset_mcu();
|
||||||
} else {
|
} else {
|
||||||
printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
|
printf("%c%c%c%c%c%c%c", 0xB5, 0xF0, 0x03, 0x65, 0x72, 0x72, 0x3C);
|
||||||
return;
|
return;
|
||||||
|
67
src/usart.c
67
src/usart.c
@ -4,36 +4,6 @@
|
|||||||
|
|
||||||
#include "usart.h"
|
#include "usart.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief configure the USART
|
|
||||||
* @param none
|
|
||||||
* @retval none
|
|
||||||
*/
|
|
||||||
void usart_config(void)
|
|
||||||
{
|
|
||||||
rcu_periph_clock_enable(USART_GPIO_RCU);
|
|
||||||
rcu_periph_clock_enable(USART_RCU);
|
|
||||||
|
|
||||||
gpio_af_set(USART_GPIO_PORT, USART_GPIO_AF, USART_RX_PIN);
|
|
||||||
gpio_af_set(USART_GPIO_PORT, USART_GPIO_AF, USART_TX_PIN);
|
|
||||||
|
|
||||||
gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_RX_PIN);
|
|
||||||
gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, USART_RX_PIN);
|
|
||||||
gpio_mode_set(USART_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, USART_TX_PIN);
|
|
||||||
gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, USART_TX_PIN);
|
|
||||||
|
|
||||||
usart_deinit(USART_PHY);
|
|
||||||
usart_baudrate_set(USART_PHY, USART_PHY_BAUDRATE);
|
|
||||||
usart_receive_config(USART_PHY, USART_RECEIVE_ENABLE);
|
|
||||||
usart_transmit_config(USART_PHY, USART_TRANSMIT_ENABLE);
|
|
||||||
|
|
||||||
usart_enable(USART_PHY);
|
|
||||||
|
|
||||||
nvic_irq_enable(USART0_IRQn, 0);
|
|
||||||
usart_interrupt_enable(USART_PHY, USART_INT_RBNE);
|
|
||||||
usart_interrupt_enable(USART_PHY, USART_INT_IDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief configure the RS485(MAX13487) driver
|
* @brief configure the RS485(MAX13487) driver
|
||||||
* @param none
|
* @param none
|
||||||
@ -41,10 +11,39 @@ void usart_config(void)
|
|||||||
*/
|
*/
|
||||||
void rs485_config(void)
|
void rs485_config(void)
|
||||||
{
|
{
|
||||||
usart_config();
|
rcu_periph_clock_enable(USART_GPIO_RCU);
|
||||||
|
rcu_periph_clock_enable(USART_RCU);
|
||||||
|
|
||||||
gpio_mode_set(RS485_EN_PORT, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, RS485_EN_PIN);
|
gpio_af_set(USART_GPIO_PORT, GPIO_AF_1, USART_TX_PIN | USART_RX_PIN | RS485_EN_PIN);
|
||||||
gpio_output_options_set(RS485_EN_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
|
|
||||||
|
|
||||||
gpio_bit_write(RS485_EN_PORT, RS485_EN_PIN, SET); //auto dircetion control
|
/* 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_AF, GPIO_PUPD_NONE, RS485_EN_PIN);
|
||||||
|
gpio_output_options_set(USART_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
|
||||||
|
// gpio_bit_write(RS485_GPIO_PORT, RS485_EN_PIN, SET);
|
||||||
|
|
||||||
|
/* USART configure */
|
||||||
|
usart_deinit(USART_PHY);
|
||||||
|
usart_baudrate_set(USART_PHY, USART_PHY_BAUDRATE);
|
||||||
|
// usart_parity_config(RS485_PHY, USART_PM_NONE);
|
||||||
|
// usart_word_length_set(RS485_PHY, USART_WL_8BIT);
|
||||||
|
// usart_stop_bit_set(RS485_PHY, USART_STB_1BIT);
|
||||||
|
usart_receive_config(USART_PHY, USART_RECEIVE_ENABLE);
|
||||||
|
usart_transmit_config(USART_PHY, USART_TRANSMIT_ENABLE);
|
||||||
|
|
||||||
|
usart_driver_assertime_config(USART_PHY, 0x01);
|
||||||
|
usart_driver_deassertime_config(USART_PHY, 0x01);
|
||||||
|
|
||||||
|
// usart_depolarity_config(USART0, USART_DEP_HIGH);
|
||||||
|
// usart_depolarity_config(USART0, USART_DEP_LOW);
|
||||||
|
|
||||||
|
usart_rs485_driver_enable(USART_PHY);
|
||||||
|
usart_enable(USART_PHY);
|
||||||
|
|
||||||
|
nvic_irq_enable(USART0_IRQn, 0);
|
||||||
|
usart_interrupt_enable(USART_PHY, USART_INT_RBNE);
|
||||||
|
usart_interrupt_enable(USART_PHY, USART_INT_IDLE);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user