#include "stm32f10x.h"
u16 sheng[]={1,2,3,4,5,6,7,8,9};
int i=0;
void GPIO_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN;//设置管脚模式为模拟输入
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
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_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void RCC_Configuration()
{
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC|RCC_APB2Periph_USART1,ENABLE);//使能时钟
}
void USART_Configuration()
{
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate=115200;//设置波特率
USART_InitStructure.USART_WordLength=USART_WordLength_8b;//设置数据位长度
USART_InitStructure.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
USART_InitStructure.USART_Parity=USART_Parity_No;
USART_InitStructure.USART_StopBits=USART_StopBits_1;
USART_Init( USART1, &USART_InitStructure);
}
int main()
{
RCC_Configuration();
GPIO_Configuration();
USART_Configuration();
USART_Cmd( USART1, ENABLE);
USART_ClearFlag(USART1,USART_FLAG_TC);
delay(10);
while(i<9)
{
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
USART_ClearFlag(USART1,USART_IT_TC);
USART_SendData(USART1,sheng[i]);
i++;
}
}
这个程序运行后PC机上串口小助手不显示接收数据 但奇怪的是只要把while(i<9)改成while(1)就接收数据,希望大神们能帮忙看看问题出在哪里