STM32 usart 问题笔记
2017-03-28 16:02
204 查看
1、USART 手册上给的基础配置源码有误,应该为:
变量声明必须放在主函数的最前面位置,不可以放在执行语句之后。
即
3、千万不要忘记配置RCC和GPIO的函数库,否则程序会一直卡在while检测的那句话。
void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
}
USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_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_ClockInitStructure.USART_Clock = USART_Clock_Disable; USART_ClockInitStructure.USART_CPOL = USART_CPOL_High; USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge; USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable; USART_Init(USART1, &USART_InitStructure); USART_ClockInit(USART1 , &USART_ClockInitStructure);2、error: #268: declaration may not appear after executablestatement 解决方法:
变量声明必须放在主函数的最前面位置,不可以放在执行语句之后。
即
USART_InitTypeDef USART_InitStructure; USART_ClockInitTypeDef USART_ClockInitStructure;//必须放在主函数的最前面。
3、千万不要忘记配置RCC和GPIO的函数库,否则程序会一直卡在while检测的那句话。
void RCC_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
}
void GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Configure PC.06, PC.07, PC.08 and PC.09 as Output push-pull */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOA, &GPIO_InitStructure); }
相关文章推荐
- STM32 Usart 上电发送一个无效字符的问题
- stm32 USART 学习笔记!
- STM32学习笔记一一USART
- STM32串行通信USART解说笔记
- STM32的串口函数_库函数USART_SendData问题和解决方法--硬件复位导致第一个字节丢失
- STM32笔记---DMA(USART)的演示
- 关于stm32的usart的接收中断使能问题
- STM32学习笔记8——串口输出数据丢失问题
- stm32学习笔记----双串口同时打开时的printf()问题
- STM32学习笔记9——结构体赋值问题
- stm32 cortext-M3 类型对齐问题【worldsing笔记】
- STM32笔记(四)DMA、USART的演示
- STM32关于USART的问题集锦
- STM32 USART调试笔记
- STM32串口通信USART1转USART2问题解决
- STM32 USART 一些问题
- STM32学习笔记——USART串口(向原子哥和火哥学习)
- STM32学习笔记——USART串口
- stm32笔记01——keil问题01.代码复制到Word出现乱码
- STM32单片机学习笔记——USART串口通信