我把STM32F070的虚拟串口给搞出来了,COM9.现在我写了个程序,可是COM9数据收不到,也发不出来。
程序如下:
void uart1_init(INT32U Baud)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG|RCC_APB2Periph_USART1, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE); //ʹÄÜÓõ½µÄGPIOAʱÖÓ
//RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART1,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure); //ÅäÖÃPA9(´®¿Ú1TXD)ΪÊä³ö¸´ÓÃÍÆÍì
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
GPIO_Init(GPIOA,&GPIO_InitStructure); //ÅäÖÃPA10(´®¿Ú1RXD)ΪÊäÈë
USART_InitStructure.USART_BaudRate=Baud; //²¨ÌØÂÊ
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; //ģʽΪ·¢ËͺͽÓÊÕË«Ïò
USART_Init(USART1,&USART_InitStructure); //¸ù¾ÝUSART_InitStructureÒÑÌîдµÄ²ÎÊý³õʼ»¯´®¿Ú1
USART_Cmd(USART1,ENABLE); //ʹÄÜ´®¿Ú1
USART_GetFlagStatus(USART1,USART_FLAG_TC); //Çå³ý½ÓÊÕÖжϣ¬½â¾öµÚÒ»¸ö×Ö½Ú·¢²»³öÈ¥µÄÎÊÌâ
NVIC_InitStructure.NVIC_IRQChannel=USART1_IRQn; //USART1ÖжϺÅ
NVIC_InitStructure.NVIC_IRQChannelPriority=0;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //IRQͨµÀʹÄÜ
NVIC_Init(&NVIC_InitStructure); //¸ù¾ÝNVIC_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèNVIC¼Ä´æÆ÷
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE); //½ÓÊÕÖжÏʹÄÜ
}
。。。。。。。。。。。。。。。。。。。。
int main(void)
{
//SystemInit(); //ϵͳʱÖÓÅäÖú¯Êý£¬Í¨¹ý²»Í¬µÄʱÖÓ¶¨Ò壬À´Ñ¡Ôñ²»Í¬µÄÖ÷Ƶ
led_init();
uart1_init(9600);
while(1)
{
USART_SendData(USART1,0X55);
led_turn;
delay_ms(250);
}
}
请高手给看看,谢谢!
|