用的是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);
}
|