今天调试了一个MDK自带的串口例程,遇到一点小问题:
main.c(94): error: #136: struct "<unnamed>" has no field "USART_Clock"
main.c(96): error: #136: struct "<unnamed>" has no field "USART_CPOL"
main.c(98): error: #136: struct "<unnamed>" has no field "USART_CPHA"
main.c(100): error: #136: struct "<unnamed>" has no field "USART_LastBit"
编译没通过,到处找问题。由于是软件自带的例程,开始没有怀疑代码本身的问题,以为是库文件不对,折腾了半天也没调出来%……&¥*&
后来在网上看人家说例程也有问题,才静下心来一条一条的语句分析,终于发现问题所在
发现有两个结构定义USART Init Structure definition和USART Clock Init Structure definition
在main.c中的USART初始化时只用了一个结构类USART_InitStructure进行初始化设置。
/* Private variables ---------------------------------------------------------*/
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;//这句是新加进去的
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/*注释掉得是源代码*/
//USART_InitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_Clock=USART_Clock_Disable;
//USART_InitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPOL=USART_CPOL_Low;
//USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_CPHA=USART_CPHA_2Edge;
//USART_InitStructure.USART_LastBit = USART_LastBit_Disable;
USART_ClockInitStructure.USART_LastBit=USART_LastBit_Disable;
再编译看看
FromELF: creating hex file...
".\output\release.axf" - 0 Error(s), 0 Warning(s).
接上串口看看
CAO QUANYONG
CAO QUANYONG
CAO QUANYONG
CAO QUANYONG
CAO QUANYONG
OK!有数据出来了太高兴了^^
看来写MDK例程的人也没有调试每个程序啊,看来不要过于相信人家的东西啊。。。
用户1338607 2011-12-12 13:41