generated from hulk/gd32e23x_template_cmake_vscode
添加新版型
This commit is contained in:
@@ -102,15 +102,15 @@ void SysTick_Handler(void) {
|
||||
|
||||
void USART1_IRQHandler(void) {
|
||||
// 处理USART1的接收中断
|
||||
if(usart_interrupt_flag_get(USART1, USART_INT_FLAG_RBNE)) {
|
||||
uint8_t data = usart_data_receive(USART1);
|
||||
if(usart_interrupt_flag_get(RS485_PHY, USART_INT_FLAG_RBNE)) {
|
||||
uint8_t data = usart_data_receive(RS485_PHY);
|
||||
// 使用原有的环形缓冲区处理逻辑
|
||||
(void)uart_ring_buffer_put(data); // 缓冲满时丢弃,返回值可用于统计
|
||||
}
|
||||
|
||||
// 处理USART1的空闲中断
|
||||
if(usart_interrupt_flag_get(USART1, USART_INT_FLAG_IDLE)) {
|
||||
usart_interrupt_flag_clear(USART1, USART_INT_FLAG_IDLE);
|
||||
if(usart_interrupt_flag_get(RS485_PHY, USART_INT_FLAG_IDLE)) {
|
||||
usart_interrupt_flag_clear(RS485_PHY, USART_INT_FLAG_IDLE);
|
||||
// 在这里添加空闲中断处理逻辑
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,10 +65,10 @@ int main(void)
|
||||
|
||||
delay_ms(100);
|
||||
rs485_send_str((uint8_t*)"ok", 2);
|
||||
delay_ms(100);
|
||||
// delay_ms(100);
|
||||
// wait rs485 send complete: DE high -> low
|
||||
|
||||
while (uart_ring_buffer_get() != 0x30);
|
||||
while (uart_ring_buffer_get() != 0x31);
|
||||
rs485_send_str((uint8_t*)"ok", 2);
|
||||
|
||||
while (uart_ring_buffer_get() != 0x31);
|
||||
|
||||
12
Src/uart.c
12
Src/uart.c
@@ -12,13 +12,13 @@ void rs485_init(void) {
|
||||
rcu_periph_clock_enable(RS485_RCU);
|
||||
|
||||
/* 配置 PA2 为 USART0_TX,PA3 为 USART0_RX */
|
||||
gpio_af_set(RS485_GPIO_PORT, GPIO_AF_1, RS485_TX_PIN | RS485_RX_PIN | RS485_EN_PIN);
|
||||
gpio_af_set(RS485_GPIO_PORT, GPIO_AF_1, RS485_TX_PIN | RS485_RX_PIN );
|
||||
|
||||
gpio_mode_set(RS485_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_PULLUP, RS485_TX_PIN | RS485_RX_PIN);
|
||||
gpio_output_options_set(RS485_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_TX_PIN | RS485_RX_PIN);
|
||||
|
||||
gpio_mode_set(RS485_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, RS485_EN_PIN);
|
||||
gpio_output_options_set(RS485_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
|
||||
// gpio_mode_set(RS485_GPIO_PORT, GPIO_MODE_AF, GPIO_PUPD_NONE, RS485_EN_PIN);
|
||||
// gpio_output_options_set(RS485_GPIO_PORT, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, RS485_EN_PIN);
|
||||
|
||||
/* 配置波特率、数据位、停止位等 */
|
||||
usart_deinit(RS485_PHY);
|
||||
@@ -29,10 +29,10 @@ void rs485_init(void) {
|
||||
usart_receive_config(RS485_PHY, USART_RECEIVE_ENABLE);
|
||||
usart_transmit_config(RS485_PHY, USART_TRANSMIT_ENABLE);
|
||||
|
||||
usart_driver_assertime_config(RS485_PHY, 0x01);
|
||||
usart_driver_deassertime_config(RS485_PHY, 0x10);
|
||||
// usart_driver_assertime_config(RS485_PHY, 0x01);
|
||||
// usart_driver_deassertime_config(RS485_PHY, 0x10);
|
||||
|
||||
usart_rs485_driver_enable(RS485_PHY);
|
||||
// usart_rs485_driver_enable(RS485_PHY);
|
||||
|
||||
usart_interrupt_enable(RS485_PHY, USART_INT_RBNE);
|
||||
// usart_interrupt_enable(RS485_PHY, USART_INT_IDLE);
|
||||
|
||||
Reference in New Issue
Block a user