程序编译没问题,如下:(愁死了,一直都不行,使用的是USART3,无输出。如果换成USART1,程序做响应的修改,而且在配置option里选中use microlib 是可以的,但是为什么要选中use microlib?而且怎么才能使用USART3)用的STM32f107VC芯片串口调试助手没任何显示:
#include"stm32f10x.h"
#include<stdio.h>
void Delay_MS(u16 dly);
void COM_Configuration(void);
u8 tab[]="\nHello! everyone,welcome to class!";
int main(void)
{
u8 i;
COM_Configuration();
printf("\n Hello, very good,\t %d",0x55);
printf("\n\r WWW.ARMJISHU.COM! \n");
printf("\n\r WWW.ARMJISHU.COM! \n");
while(1)
{
for(i=0;i<33;i++)
{
USART_SendData(USART3, tab);
Delay_MS(2000);
}
}
}
void Delay_MS(u16 dly)
{
u16 i,j;
for(i=0;i<dly;i++)
for(j=1000;j>0;j--);
}
void COM_Configuration()
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef U3;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB,&GPIO_InitStructure);
U3.USART_BaudRate =115200;
U3.USART_WordLength = USART_WordLength_8b;
U3.USART_StopBits = USART_StopBits_1;
U3.USART_Parity = USART_Parity_No;
U3.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
U3.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(USART3, &U3);
USART_Cmd(USART3,ENABLE);
USART_ClearFlag(USART3, USART_FLAG_TXE);
}
int fputc(int ch, FILE *f)
{
/* e.g. write a character to the USART */
USART_SendData(USART3, (uint8_t) ch);
/* Loop until the end of transmission */
while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET);
return ch;
}
int fgetc(FILE *fp)
{
int ch = 0;
while(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET);
ch = (int)USART3->DR & 0xFF;
putchar(ch);
return ch;
}
|