文号
t28109
阅读
12328
回复
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:未同步
245668
1楼
STM32找猴子吧....
stm32据说稳定性不如avr, avr的价格啊........
我在2440和cortex-m0两个考虑中....
引用
评论
16年5个月前IP:未同步
245681
2楼
引用第1楼nhlijiaming于2010-08-06 21:56发表的  :
STM32找猴子吧....
stm32据说稳定性不如avr, avr的价格啊........
我在2440和cortex-m0两个考虑中....


AVR稳定性其实不如STM32,因为虽然AVR运行比STM32稳定,但是STM32的保护措施更多。比如我的ECG处理上就应用了时钟安全系统(CSS),如果晶振挂掉,系统切换到内部时钟,并且放出故障信号。STM32看门狗也是很强悍地说。NMI,定时器刹车和ADC看门狗更是利器。

2440和M0完全不同的档次,现在大家都用6410有条件搞个吧,性能好,用得爽。不过开发起来其实一样的。
M0号称代替51,因为硅片面积比51小。
STM8可以干掉AVR,STM8使用更方便。而且据说AVR以后要登记供货,比较麻烦,散货可能难以拿到。


LZ把整个工程打包吧,估计是哪里配置错了
引用
评论
16年5个月前IP:未同步
245690
3楼
反正AVR已经杯具了
6410.....先玩玩arm9再说
M0做小东西倒是方便些, 但现在推广还不怎么好...
(好像跑题了)
引用
评论
16年5个月前IP:未同步
245718
4楼
阿莫说实际上AT的大客户供货还是稳定的,散户懒得理而已..具体怎么样我也不知道了,不了解
上CM0吧,我前段时间也买了LPC1114的开发板,上面集成colink调试器,可是我电脑用不了 TAT.
引用
评论
16年5个月前IP:未同步
245722
5楼
~~~你也跑去玩哪东西~~~
引用
评论
16年5个月前IP:未同步
245727
6楼
啊ourdev上有人找到问题了,Tx端口PA9设置错,要设置成AF_PP,不能是OUT_PP
引用
评论
16年5个月前IP:未同步
245898
7楼
祝贺楼主解决问题
引用
评论
16年5个月前IP:未同步
246051
8楼
32位片子果然NB!俺看不懂!
引用
评论
16年5个月前IP:未同步
247665
9楼
请问楼主,我没有出现你写代码的错误,但是结果和你的一样,是怎么回事啊?急!!!!!!!!!!!!望尽快给答复,谢谢!

附我的代码:
#include "stm32f10x.h"

/* Private variables ---------------------------------------------------------*/
GPIO_InitTypeDef GPIO_InitStructure;

/* Private function prototypes -----------------------------------------------*/
void delay(uint32_t nCount);
void UART1_GPIO_Configuration(void);
void UART1_Configuration(void);

/**********************************主函数****************************************/
int main(void)
{
  /* Setup STM32 system (clock, PLL and Flash configuration) */
  SystemInit();

  /* GPIOx and AFIO clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO, ENABLE);
   /* USART1 clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

  UART1_GPIO_Configuration();
  UART1_Configuration();

  while(1)
  {
        GPIO_SetBits(GPIOB, GPIO_Pin_5);
        USART_SendData(USART1, (u8) 0xa4);
        while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
        delay(0xffff);
        GPIO_ResetBits(GPIOB, GPIO_Pin_5);
        delay(0xfffff);
  }

}

/*********************************配置UART的GPIO口*************************************/
void UART1_GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
// Configure USART1_Tx as alternate function push-pull
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);

// Configure USART1_Rx as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);

// Configure GPIOB
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);

}


/************************************配置串口参数***********************************/

void UART1_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(uint32_t nCount)
{
  for(; nCount != 0; nCount--);
}
/********************************End of function def********************************/

#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *   where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
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

/**
  * @}
  */
引用
评论
16年5个月前IP:未同步
248100
10楼
楼上...我也找不到什么问题...你上ourdev去问问吧
引用
评论
16年5个月前IP:未同步
248844
11楼
我都是上开发板和JLink,然后逐个比对寄存器数据。。。
引用
评论
笔记
{{note.content}}
{{n.user.username}}
{{fromNow(n.toc)}} {{n.status === noteStatus.disabled ? "已屏蔽" : ""}} {{n.status === noteStatus.unknown ? "正在审核" : ""}} {{n.status === noteStatus.deleted ? '已删除' : ''}}
  • 编辑
  • 删除
  • {{n.status === 'disabled' ? "解除屏蔽" : "屏蔽" }}
我也是有底线的