文号
t28109
阅读
12347
回复
12
收藏
6
stm32的问题,.什么我这个USART通信程序发不出数据??
2010/08/06
IP:黑龙江
ourdev上发了没人回...
从上午一直折腾到现在..串口调试助手就是收不到数据...
开发版用英蓓特给的例程编译调试是可以正常发送数据的,可是上了我自己的程序就不行,不知道为什么TAT..
在这个程序要实现的功能是 每隔一段一段时间发0xa4到PC那,用的是V3.0的固件库(例程用的是2.0)
具体现象是,程序能正常运行,串口调试助手没有收到数据,但调试助手每次关闭->开启一次串口都会收到一个0x00,什么波特率下都会收到
大家帮帮看看为什么吧..我基本是一个字一个字跟搜到的例程对过了..可是就是发不出数据..

main.c文件内容如下:


#include "stm32f10x.h"
#include "misc.h"


/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;


/* Private function prototypes -----------------------------------------------*/
void RCC_Configuration(void);
void Delay(__IO uint32_t nCount);
void NVIC_Configuration(void);
void GPIO_Configuration(void);
void EXTI_Configuration(void);
void USART_Configuration(void);



/* Private function ----------------------------------------------------------*/
int main(void)
{
  RCC_Configuration();  
  NVIC_Configuration();
  GPIO_Configuration();  
  EXTI_Configuration();  
  USART_Configuration();
  
while (1)
  {
USART_SendData(USART1, (u8) 0xa4);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
      {
      }
Delay(0xaffff);
  }

}


/*-----------------------------------------------------------------------  
RCC配置函数,包括各个外设时钟的开启
-----------------------------------------------------------------------*/  
void RCC_Configuration(void)
{    
SystemInit();

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

}


/*-----------------------------------------------------------------------  
NVIC配置函数
此为模板
-----------------------------------------------------------------------*/  
void NVIC_Configuration(void)
{
#ifdef  VECT_TAB_RAM  
  /* Set the Vector Table base location at 0x20000000 */  
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);  
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */  
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);    
#endif

}


/*-----------------------------------------------------------------------  
GPIO配置函数
此为模板
-----------------------------------------------------------------------*/
void GPIO_Configuration(void)
{
/*TX在PA9,配置为推挽*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/*RX在PA10,配置为浮空[s:9]A8为发送按钮,配置为浮空*/
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_8 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}

/*-----------------------------------------------------------------------  
EXTI配置函数,对应GPIO端口与中断线的链接也在这里
此为模板
-----------------------------------------------------------------------*/
void EXTI_Configuration(void)
{

}

/*-----------------------------------------------------------------------  
USART配置
-----------------------------------------------------------------------*/  
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_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_ClockInit(USART1,&USART_ClockInitStructure);
USART_Init(USART1,&USART_InitStructure);


USART_Cmd(USART1,ENABLE);
}


/*-----------------------------------------------------------------------  
延时函数  
-----------------------------------------------------------------------*/  
void Delay(__IO uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}
/*-----------------------------------------------------------------------  
assert
-----------------------------------------------------------------------*/  
#ifdef  USE_FULL_ASSERT

void assert_failed(uint8_t* file, uint32_t line)
{  
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* Infinite loop */
  while (1)
  {
  }
}
#endif

/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
16年5个月前IP:未同步
245718
4楼
阿莫说实际上AT的大客户供货还是稳定的,散户懒得理而已..具体怎么样我也不知道了,不了解
上CM0吧,我前段时间也买了LPC1114的开发板,上面集成colink调试器,可是我电脑用不了 TAT.
引用
评论
16年5个月前IP:未同步
245727
6楼
啊ourdev上有人找到问题了,Tx端口PA9设置错,要设置成AF_PP,不能是OUT_PP
引用
评论
16年5个月前IP:未同步
248100
10楼
楼上...我也找不到什么问题...你上ourdev去问问吧
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的