具体程序如下:
///******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/
//*******************************
//********************************
//***********************************
#include"stm32f10x_lib.h"
//*******************************]
//*********************************************
//********************************************
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
//****************************
//*****************************************
void GPIO_Configuration(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE); //¿ªÆôIO¿ÚDµÄµÆµÄ³õʼ»¯
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_SetBits(GPIOD,GPIO_Pin_2);
GPIO_Init(GPIOD,&GPIO_InitStructure);
//****************************************
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10|GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_SetBits(GPIOC,GPIO_Pin_10|GPIO_Pin_11);
GPIO_Init(GPIOC,&GPIO_InitStructure);
//*****************************************************
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE); //¿ªÆôUSARTµÄÊý¾ÝÊäÈë¡¢Êä³ö¿Ú
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING;
//GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
//********************************************
void USART_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2,ENABLE); //ÅäÖÃUSARTµÄ»ù±¾Êý¾Ý
USART_InitStructure.USART_BaudRate=9600;
USART_InitStructure.USART_WordLength=USART_WordLength_8b;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_Mode=USART_Mode_Tx|USART_Mode_Rx;
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_Init(USART2,&USART_InitStructure);
//***********************************************
int main(void)
{
int i;
unsigned char TxBuf1[]="Welcome to my!";
USART_ClearFlag(USART2,USART_FLAG_TC);
GPIO_Configuration();
USART_Configuration();
// NVIC_Configuration();
while(1)
{
for(i=0;TxBuf1
!=' ';i++)
{
USART_SendData(USART2,TxBuf1);
GPIO_SetBits(GPIOC,GPIO_Pin_10);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET);
GPIO_ResetBits(GPIOC,GPIO_Pin_10);
}
i=0;
}
}
软件仿真可以看到:
file:///C:/Users/Administrator/AppData/Roaming/Tencent/Users/805958628/QQ/WinTemp/RichOle/42BSERR~%7BVGBJ0UH12%7BMKRI.jpg
,但是在串口调试助手上看不到任何数据输出
此帖出自小平头技术问答
一周热门 更多>