|
【GD32-colibri-F350RX】+UART中断测试
[复制链接]
本帖最后由 damiaa 于 2018-9-18 14:44 编辑
【GD32-colibri-F350RX】+UART中断测试
继续上篇文章中提到的工程,准备用UART1(上篇中也是,不是UART0)1,拷贝中断例子Examples\USART\Transmitter&receiver_interrupt中的
main.c
gd32f3x0_it.c
gd32f3x0_it.h
替代现有的工程中的对应文件
2,gd32f3x0_it.c修改USART0_IRQHandler函数名为USART1_IRQHandler
3,nvic_irq_enable(USART0_IRQn, 0, 0);修改为
nvic_irq_enable(USART1_IRQn, 0, 0);
4,编译运行
5,设置为相应串口和115200,N,8,1。打开串口
6.调试看结果。
7,附件
GD32F3x0_Firmware_Library_V1.0.0_Colibri-F350_.zip
(4.29 MB, 下载次数: 27)
8,继续做了些修改,这样初始化2个串口方便些。
gd323x0_eval.h中
#define EVAL_COM1 USART0
#define EVAL_COM1_CLK RCU_USART0
#define EVAL_COM1_TX_PIN GPIO_PIN_9
#define EVAL_COM1_RX_PIN GPIO_PIN_10
#define EVAL_COM1_GPIO_PORT GPIOA
#define EVAL_COM1_GPIO_CLK RCU_GPIOA
#define EVAL_COM1_AF GPIO_AF_1
#define EVAL_COM1_IRQ USART0_IRQn
#define EVAL_COM2_IRQ USART1_IRQn
gd323x0_eval.c中
static rcu_periph_enum COM_CLK[COMn] = {EVAL_COM1_CLK,EVAL_COM2_CLK};
static uint32_t COM_TX_PIN[COMn] = {EVAL_COM1_TX_PIN,EVAL_COM2_TX_PIN};
static uint32_t COM_RX_PIN[COMn] = {EVAL_COM1_RX_PIN,EVAL_COM2_RX_PIN};
static uint32_t COM_GPIO_PORT[COMn] = {EVAL_COM1_GPIO_PORT,EVAL_COM2_GPIO_PORT};
static uint32_t EVAL_COM_AF[COMn] = {EVAL_COM1_AF,EVAL_COM2_AF};
static uint32_t EVAL_COM_GPIO_CLK[COMn] = {EVAL_COM1_GPIO_CLK,EVAL_COM2_GPIO_CLK};
void gd_eval_com_init(uint32_t com)
{
uint32_t COM_ID;
if(EVAL_COM1 == com){
COM_ID = 0U;
}
if(EVAL_COM2 == com){
COM_ID = 1U;
}
else{
}
/* enable COM GPIO clock */
rcu_periph_clock_enable(EVAL_COM_GPIO_CLK[COM_ID]);
/* enable USART clock */
rcu_periph_clock_enable(COM_CLK[COM_ID]);
/* connect port to USARTx_Tx */
gpio_af_set(COM_GPIO_PORT[COM_ID], EVAL_COM_AF[COM_ID], COM_TX_PIN[COM_ID]);
/* connect port to USARTx_Rx */
gpio_af_set(COM_GPIO_PORT[COM_ID], EVAL_COM_AF[COM_ID], COM_RX_PIN[COM_ID]);
/* configure USART Tx as alternate function push-pull */
gpio_mode_set(COM_GPIO_PORT[COM_ID], GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_TX_PIN[COM_ID]);
gpio_output_options_set(COM_GPIO_PORT[COM_ID], GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_TX_PIN[COM_ID]);
/* configure USART Rx as alternate function push-pull */
gpio_mode_set(COM_GPIO_PORT[COM_ID], GPIO_MODE_AF, GPIO_PUPD_PULLUP, COM_RX_PIN[COM_ID]);
gpio_output_options_set(COM_GPIO_PORT[COM_ID], GPIO_OTYPE_PP, GPIO_OSPEED_10MHZ, COM_RX_PIN[COM_ID]);
/* USART configure */
usart_deinit(com);
usart_baudrate_set(com, 115200U);
usart_receive_config(com, USART_RECEIVE_ENABLE);
usart_transmit_config(com, USART_TRANSMIT_ENABLE);
usart_enable(com);
}
关于UART:某些资料里有一点命名不一样
代码 uart0 uart1
某些资料 uart1 uart2 比如:管脚分配与开发板布局 GD32F3x0_User_Manual_CN_v1.0的某些部分。
|
|