打印
[STM32F1]

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

[复制链接]
726|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
zzzhangliyuan|  楼主 | 2016-1-28 19:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32的串口程序,在KEIL环境下配置是这样的
oid USART1_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_WIRELESS_USART | RCC_APB2Periph_GPIOA, ENABLE);
               
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
   
        USART_InitStructure.USART_BaudRate = 115200;
        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_Rx | USART_Mode_Tx;
        USART_Init(WIRELESS_USART, &USART_InitStructure);
        USART_ITConfig(WIRELESS_USART, USART_IT_RXNE, ENABLE);
                   
    USART_Cmd(USART1, ENABLE);       
}

我运行了,是可以的。但是同样的代码在eclipse环境下却不可以,而必须加上
USART_ClockInitTypeDef  USART_ClockInitStruct;
程序是这样的
void USART1_Config(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
    USART_ClockInitTypeDef  USART_ClockInitStruct;
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_WIRELESS_USART | RCC_APB2Periph_GPIOA, ENABLE);
               
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
        GPIO_Init(GPIOA, &GPIO_InitStructure);
   
        USART_InitStructure.USART_BaudRate = 115200;
        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_Rx | USART_Mode_Tx;
        USART_Init(WIRELESS_USART, &USART_InitStructure);
        USART_ITConfig(WIRELESS_USART, USART_IT_RXNE, ENABLE);
   
    USART_ClockInitStruct.USART_Clock=USART_Clock_Disable;
        USART_ClockInitStruct.USART_CPOL=USART_CPOL_Low;
        USART_ClockInitStruct.USART_CPHA=USART_CPHA_2Edge;
        USART_ClockInitStruct.USART_LastBit=USART_LastBit_Disable;
   
    USART_ClockInit(USART1, &USART_ClockInitStruct);
                       
    USART_Cmd(USART1, ENABLE);       
}

这是为什么呢?
沙发
奥德赛| | 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

使用特权

评论回复
5
zzzhangliyuan|  楼主 | 2016-1-29 10:37 | 只看该作者
Beckham_Owen 发表于 2016-1-29 10:22
感觉和编译器有关系,一个是gcc一个是mdk

嗯,确实有关系,但是为什么呐?我查了CLK应该是和串口同步通信有关系,但是在KEIL上为什么可以缺省呢?是有默认的模式吗?

使用特权

评论回复
6
Rooney30| | 2016-1-31 11:25 | 只看该作者
zzzhangliyuan 发表于 2016-1-29 10:37
嗯,确实有关系,但是为什么呐?我查了CLK应该是和串口同步通信有关系,但是在KEIL上为什么可以缺省呢? ...

有可能keil mdk默认状态下已经给弄好了

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

45

主题

153

帖子

6

粉丝