UART5初始化后发不出数据,请帮忙看看
用的是403A的评估板,串口选的是UART5,管脚PB8,PB9,串口初始化代码如下void usart_configuration(void)
{
gpio_init_type gpio_init_struct;
/* enable the usart5 and gpio clock */
crm_periph_clock_enable(CRM_UART5_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable(CRM_GPIOB_PERIPH_CLOCK, TRUE);
gpio_default_para_init(&gpio_init_struct);
/* configure the usart5 tx pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_MUX;
gpio_init_struct.gpio_pins = GPIO_PINS_9;
gpio_init_struct.gpio_pull = GPIO_PULL_NONE;
gpio_init(GPIOB, &gpio_init_struct);
/* configure the usart5 rx pin */
gpio_init_struct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
gpio_init_struct.gpio_out_type = GPIO_OUTPUT_PUSH_PULL;
gpio_init_struct.gpio_mode = GPIO_MODE_INPUT;
gpio_init_struct.gpio_pins = GPIO_PINS_8;
gpio_init_struct.gpio_pull = GPIO_PULL_UP;
gpio_init(GPIOB, &gpio_init_struct);
/* config usart nvic interrupt */
nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
nvic_irq_enable(UART5_IRQn, 0, 0);
/* configure usart5 param */
usart_init(UART5, 115200, USART_DATA_8BITS, USART_STOP_1_BIT);
usart_transmitter_enable(UART5, TRUE);
usart_receiver_enable(UART5, TRUE);
usart_interrupt_enable(UART5, USART_IDLE_INT, TRUE);
usart_enable(UART5, TRUE);
}主程序中循环发送一个字节:
for(;;)
{
while(usart_flag_get(UART5, USART_TDBE_FLAG) == RESET);
usart_data_transmit(UART5, 0x55);
delay_ms(1);
}
用示波器测管脚PB9 (TXD5),没有高低变化
请问怎么回事?
要开AFIO时钟,并使能串口引脚的重映射 多谢,可以出信号了
下面要调试中断了,感觉挺麻烦的,ST的CubeMX用惯了,懒了 本帖最后由 话说当年 于 2022-6-1 21:16 编辑
你可用串口5的TX是PC12;RX是PD2.我已经把8个串口都试过了, 没啥问题。你重映射出现问题了
页:
[1]