专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > 硬件开发

stm32一个串口接收另一个串口发送数据程序哪里出错?解决方案

发布时间:2010-06-13 21:44:22 文章来源:www.iduyao.cn 采编人员:星星草
stm32一个串口接收另一个串口发送数据程序哪里出错?
我用的是stm32zet6 程序的目的是用串口2接收我的gps模块发送来的gps信息 ,然后利用串口1将信息发送出去,在电脑上用串口调试助手能够看到数据。





#include "stm32_eval.h"
#include "stm32f10x.h"
#include "platform_config.h"
#include<stdio.h>




GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;


void RCC_Configuration(void);


void Delay(vu32 nCount)
{
  for(; nCount != 0; nCount--);
}
int main(void)
{
  RCC_Configuration();
  USART_InitStructure.USART_BaudRate = 115200; /*设置波特率为115200*/
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;/*设置数据位为8*/
  USART_InitStructure.USART_StopBits = USART_StopBits_1; /*设置停止位为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; /*发送和接收*/

  /*配置串口1 */
  USART_Init(USART1, &USART_InitStructure);
  /*配置串口2*/
  USART_Init(USART2, &USART_InitStructure);
  
 

  /* 使能串口1 */
  USART_Cmd(USART1, ENABLE);
  /* 使能串口2 */
  USART_Cmd(USART2, ENABLE);

  /* Wait until end of transmission from USART1 to USART2 */
  STM_EVAL_COMInit(COM1, &USART_InitStructure);



  while (1)
 {
  if(USART_GetFlagStatus(USART2,USART_FLAG_RXNE)==SET)
  {
  USART_SendData(USART1,USART_ReceiveData(USART2));
  while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);
  Delay(0XFFFFF);
  }
 }

}

/**
  * @brief Configures the different system clocks.
  * @param None
  * @retval None
  */
void RCC_Configuration(void)
{  
  /*使能串口1和串口2使用的GPIO时钟*/
  RCC_APB2PeriphClockCmd(USART1_GPIO_CLK |USART2_GPIO_CLK, ENABLE);
  /* Enable USART1 Clock */
  /*使能串口1时钟*/
  RCC_APB2PeriphClockCmd(USART1_CLK, ENABLE); 
  /*使能串口2时钟*/
  RCC_APB1PeriphClockCmd(USART2_CLK, ENABLE);  

}


------解决方案--------------------
探讨
……在电脑上用串口调试助手能够看到数据。





……
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: