在使用stm32c8t6单片机时,由于需要使用两个串口usart1 、usart2。usart1用作程序烧录、调试作用,串口2用于与其它模块进行通信。
使用串口1时,正常工作,使用串口2时,无反应。查阅了相关资料串口2在PA2\PA3 引脚上。RX\TX正反插无反应。最终找出原因是程序配置出现问题,但编译是没有报错的。
下面是我个人发现的问题
问题程序:
void USART2_Init(u32 bound)
{
//GPIO端口设置
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE);//串口2在APB1时钟线上 **********************没开其APB1的时钟*********
/* 配置GPIO的模式和IO口 */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;//TX //串口输出PA2
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP; //复用推挽输出
GPIO_Init(GPIOA,&GPIO_InitStructure); /* 初始化串口输入IO */
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;//RX //串口输入PA3
GPIO_InitStructure.GP
8801



被折叠的 条评论
为什么被折叠?



