求助stm32的usart程序问题在哪里

[复制链接]
3020|11
 楼主| tang20063260 发表于 2012-4-25 14:44 | 显示全部楼层 |阅读模式
我弄了一个stm32串口的程序,在调试时发现usart的dr全是零,不是我发送的值而且串口助手也没收到值,麻烦各位大侠帮我看看,提点意见,谢谢!
#include "stm32f10x.h"
GPIO_InitTypeDef GPIO_InitStructure;
void RCC_Configuration(void); $W5EJ02[HR$%GJ~CF{~PN69.jpg
void Delay(uint32_t delaytime);
void GPIO_Configuration(void);
void USART_Configuration(void);


int main(void)
{
  RCC_Configuration();  
  
  GPIO_Configuration();  
   
  USART_Configuration();
  GPIO_ResetBits(GPIOA,GPIO_Pin_11);  //485只发送
  while (1)
  {
  
  USART_SendData(USART1, (u8) 0xa4);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
      {
      }
Delay(0xaffff);
  }
}
   

void RCC_Configuration(void)
{   
SystemInit();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
}
void GPIO_Configuration(void)
{
/*TX在PA9,配置为推挽*/
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_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA,&GPIO_InitStructure);
  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
   
}
void USART_Configuration(void)
{
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
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_ClockInit(USART1,&USART_ClockInitStructure);

USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;
USART_Init(USART1,&USART_InitStructure);

USART_Cmd(USART1,ENABLE);
}

void Delay(uint32_t delaytime)
  {
  for(;delaytime>0;delaytime--);
   }
RH$OJ@OJA{2]1P8TFQ~M1PO.jpg
jgphu 发表于 2012-4-25 14:55 | 显示全部楼层
这种问题,你要先测量一下,你发送的串口数据的波特率是不是115200,换句话说,你的时钟搞对了没有。
logokfu 发表于 2012-4-25 15:04 | 显示全部楼层
mage心寒 发表于 2012-4-25 17:09 | 显示全部楼层
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

把这两句话加到RCC_Config里面看看放到最后面,我的就是这个问题前几天刚调试的。。亲加油哇。。
ucuser 发表于 2012-4-25 17:16 | 显示全部楼层
没找到,不好意思
 楼主| tang20063260 发表于 2012-4-26 08:48 | 显示全部楼层
大家辛苦了
 楼主| tang20063260 发表于 2012-4-26 09:28 | 显示全部楼层
不好意思这两个函数的原定义在哪里,我没搜索到
logokfu 发表于 2012-4-26 09:30 | 显示全部楼层
find 啊
 楼主| tang20063260 发表于 2012-4-27 10:28 | 显示全部楼层
没找到,能告诉我在那个文件里吗
fq1110 发表于 2012-4-29 00:56 | 显示全部楼层
这个函数只有STM32F2XX与STM32F4xx系列才有,STM32F1xx系列没有....
spsonic 发表于 2012-5-1 17:53 | 显示全部楼层
楼主,你的电路是不是有问题呀,R26下拉, R27上拉,C24去掉,这样试试
 楼主| tang20063260 发表于 2012-5-7 17:31 | 显示全部楼层
是波特率没匹配好
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

33

帖子

0

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