打印
[应用相关]

帮忙看看这个串口程序怎么不对

[复制链接]
482|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
后会无期1|  楼主 | 2015-4-24 20:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include "stm32f10x.h"
void USART1_Init(void)
{
USART_InitTypeDef USART_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_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_Init(USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);
}
void USART1_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
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);
}
void Delay(vu32 nCount)
{
for(;nCount!=0;nCount--);
}
int main(void)
{
USART1_Init();
USART1_GPIO_Config();
while(1)
{
USART_SendData(USART1,‘a’);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);
Delay(0xfff);
}
}

沙发
我是MT| | 2015-4-24 20:51 | 只看该作者
提示: 该帖被管理员或版主屏蔽
板凳
fhguo1990| | 2015-4-24 20:51 | 只看该作者
串口时钟没开

使用特权

评论回复
地板
后会无期1|  楼主 | 2015-4-24 20:52 | 只看该作者
提示: 该帖被管理员或版主屏蔽
5
后会无期1|  楼主 | 2015-4-24 20:52 | 只看该作者
我是MT 发表于 2015-4-24 20:51
串口的rcc没有enbale

有一句RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
这个也一样的吧

使用特权

评论回复
6
我思故我在12345| | 2015-4-24 20:53 | 只看该作者
提示: 该帖被管理员或版主屏蔽
7
我思故我在12345| | 2015-4-24 20:54 | 只看该作者
看看这个一定可以//======================================================
void USART1_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        USART_InitTypeDef USART_InitStructure;
        
        /* Enable USART1 clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
        //USART1
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;                 //USART1 TX
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;    //复用推挽输出
        GPIO_Init(GPIOA, &GPIO_InitStructure);                    //A端口
        
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;                 //USART1 RX
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   //复用开漏输入
        GPIO_Init(GPIOA, &GPIO_InitStructure);                         //A端口
         
    /* USART1 configuration ------------------------------------------------------*/
        /* USART and USART2 configured as follow:
              - BaudRate = 115200 baud  
              - Word Length = 8 Bits
              - One Stop Bit
              - No parity
              - Hardware flow control disabled (RTS and CTS signals)
              - Receive and transmit enabled
        */
        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;
        
        /* Configure USART1 */
        USART_Init(USART1, &USART_InitStructure);
        /* Enable USART1 Receive and Transmit interrupts */
        USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
        USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
        
        /* Enable the USART1 */
        USART_Cmd(USART1, ENABLE);
}:

使用特权

评论回复
8
后会无期1|  楼主 | 2015-4-24 20:54 | 只看该作者
提示: 该帖被管理员或版主屏蔽
9
后会无期1|  楼主 | 2015-4-24 20:55 | 只看该作者
提示: 该帖被管理员或版主屏蔽
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

20

主题

208

帖子

0

粉丝