新手上路
- 积分
- 34
- 金钱
- 34
- 注册时间
- 2017-9-25
- 在线时间
- 3 小时
|
1金钱
使用的原子探索者开发板(STM32F407ZGT6)工程源码,在设备栏选择了STM32F407ZET6芯片,对应的设备FLASH也变更为512K,时钟因为使用的外部50M晶振,所以PLL_M修改为了50。
程序只驱动了一个串口4(PC10,PC11),现在问题是串口打印输出不对,输出是乱码,输出的字节数也不对。(猜测过是时钟问题,但是驱动定时器2、3、4、5输出PWM正常,读取RCC_GetClocksFreq(&RCC_Clocks)看了主频也正常)
串口初始化:
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStruct;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); //开启UART4时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
//串口中断优先级
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn; //中断源 UART4_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //响应优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4); //配置引脚复用
GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4); //配置引脚复用
//配置PC10作为UART4 Tx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //C10 TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//配置PC11作为UART4 Rx
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //C11 RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//中断被屏蔽了
USART_InitStructure.USART_BaudRate = br_num; //波特率配置
USART_InitStructure.USART_WordLength = USART_WordLength_8b; //8位数据
USART_InitStructure.USART_StopBits = USART_StopBits_1; //在帧结尾传输1个停止位
USART_InitStructure.USART_Parity = USART_Parity_No; //禁用奇偶校验
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; //硬件流控制失能
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; //发送、接收使能
USART_Init(UART4, &USART_InitStructure);
//使能UART4接收中断
USART_ITConfig(UART4, USART_IT_RXNE, ENABLE);
//使能UART4
USART_Cmd(UART4, ENABLE);
|
|