2735 views|0 replies

57

Posts

0

Resources
The OP
 

[liklon plays with GD32F350] 2. Serial port interruption experiment [Copy link]

In subsequent development, two serial ports are needed. From the manual, we can see that this chip has two UART modules. The example given in the demo uses UART1 (although there are a few comments saying UART2, don't be misled). 1.demo code analysis
  1. void EvbUart1Config(void) { rcu_periph_clock_enable(RCU_GPIOA); rcu_periph_clock_enable(RCU_USART1); /* connect port to USART1_Tx */ gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_2); /* connect port to USARTx_R1 */ gpio_af_set(GPIOA, GPIO_AF_1, GPIO_PIN_3); /* configure USART1 Tx as alternate function push-pull */ gpio_mode_set(GPIOA, GPIO_MODE_AF, GPIO_PUPD_PULLUP,GPIO_PIN_2); gpio_output_options_set(GPIOA, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ,GPIO_PIN_2); /* This section is the initialization of the serial port in the demo. It can be seen that after deinit, only the baud rate is configured, and the rest of the check (none), data length (8 bits) and stop bit (1 bit) are all default. There is no configuration and enable interrupt. What I need is to receive triggered by interrupt, and then sort and modify it based on this. 2. Add receive interrupt[code]void uart_init() { usart_deinit(USART1); usart_baudrate_set(USART1,115200); usart_parity_config(USART1, USART_PM_NONE); usart_word_length_set(USART1, USART_WL_8BIT); usart_stop_bit_set(USART1, USART_STB_1BIT); usart_receive_config(USART1, USART_RECEIVE_ENABLE); usart_transmit_config(USART1, USART_TRANSMIT_ENABLE); usart_interrupt_enable(USART1, USART_INT_RBNEIE); nvic_irq_enable(USART1_IRQn, 0, 2); usart_enable(USART1); }
复制代码
In order to make the configuration look more reasonable, configure the checksum and other items once. The receive interrupt is enabled (the receive interrupt is triggered when it is not empty). It is not over yet. You need to add nvic_irq_enable(USART1_IRQn, 0, 2); to configure the priority and enable this interrupt channel. At the beginning of the main function, nvic_priority_group_set(NVIC_PRIGROUP_PRE0_SUB4) is set;
  1. void USART1_IRQHandler() { uint8_t tmp = 0; tmp = usart_data_receive(USART1); uart1_write_ch(tmp); }
复制代码
The interrupt handler sends the received data to verify whether it is successful. Sending 0x34 in hex format is the character '4'.

This post is from GD32 MCU
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list