[STM32F1] 有关串口程序在KEIL环境和在eclipse环境下的问题,有谁能给解答一下~~

[复制链接]
959|5
 楼主| zzzhangliyuan 发表于 2016-1-28 19:23 | 显示全部楼层 |阅读模式
STM32的串口程序,在KEIL环境下配置是这样的
  1. oid USART1_Config(void)
  2. {
  3.         GPIO_InitTypeDef GPIO_InitStructure;
  4.         USART_InitTypeDef USART_InitStructure;
  5.        
  6.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_WIRELESS_USART | RCC_APB2Periph_GPIOA, ENABLE);
  7.                
  8.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  9.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  10.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  11.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  12.        
  13.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  14.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  15.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  16.    
  17.         USART_InitStructure.USART_BaudRate = 115200;
  18.         USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  19.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  20.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  21.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  22.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  23.         USART_Init(WIRELESS_USART, &USART_InitStructure);
  24.         USART_ITConfig(WIRELESS_USART, USART_IT_RXNE, ENABLE);
  25.                    
  26.     USART_Cmd(USART1, ENABLE);       
  27. }

我运行了,是可以的。但是同样的代码在eclipse环境下却不可以,而必须加上
USART_ClockInitTypeDef  USART_ClockInitStruct;
程序是这样的
  1. void USART1_Config(void)
  2. {
  3.         GPIO_InitTypeDef GPIO_InitStructure;
  4.         USART_InitTypeDef USART_InitStructure;
  5.     USART_ClockInitTypeDef  USART_ClockInitStruct;
  6.        
  7.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_WIRELESS_USART | RCC_APB2Periph_GPIOA, ENABLE);
  8.                
  9.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  10.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  11.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  12.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  13.        
  14.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  15.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  16.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  17.    
  18.         USART_InitStructure.USART_BaudRate = 115200;
  19.         USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  20.         USART_InitStructure.USART_StopBits = USART_StopBits_1;
  21.         USART_InitStructure.USART_Parity = USART_Parity_No ;
  22.         USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  23.         USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  24.         USART_Init(WIRELESS_USART, &USART_InitStructure);
  25.         USART_ITConfig(WIRELESS_USART, USART_IT_RXNE, ENABLE);
  26.    
  27.     USART_ClockInitStruct.USART_Clock=USART_Clock_Disable;
  28.         USART_ClockInitStruct.USART_CPOL=USART_CPOL_Low;
  29.         USART_ClockInitStruct.USART_CPHA=USART_CPHA_2Edge;
  30.         USART_ClockInitStruct.USART_LastBit=USART_LastBit_Disable;
  31.    
  32.     USART_ClockInit(USART1, &USART_ClockInitStruct);
  33.                        
  34.     USART_Cmd(USART1, ENABLE);       
  35. }

这是为什么呢?
奥德赛 发表于 2016-1-28 20:54 | 显示全部楼层
没有试过你这个,我再我的eclipse里面试试
 楼主| zzzhangliyuan 发表于 2016-1-29 09:35 | 显示全部楼层
奥德赛 发表于 2016-1-28 20:54
没有试过你这个,我再我的eclipse里面试试

嗯嗯,是和异步通信、同步通信有关系吗?
Beckham_Owen 发表于 2016-1-29 10:22 | 显示全部楼层
感觉和编译器有关系,一个是gcc一个是mdk
 楼主| zzzhangliyuan 发表于 2016-1-29 10:37 | 显示全部楼层
Beckham_Owen 发表于 2016-1-29 10:22
感觉和编译器有关系,一个是gcc一个是mdk

嗯,确实有关系,但是为什么呐?我查了CLK应该是和串口同步通信有关系,但是在KEIL上为什么可以缺省呢?是有默认的模式吗?
Rooney30 发表于 2016-1-31 11:25 | 显示全部楼层
zzzhangliyuan 发表于 2016-1-29 10:37
嗯,确实有关系,但是为什么呐?我查了CLK应该是和串口同步通信有关系,但是在KEIL上为什么可以缺省呢? ...

有可能keil mdk默认状态下已经给弄好了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

45

主题

153

帖子

6

粉丝
快速回复 在线客服 返回列表 返回顶部