找到了407的例程了,串口可以打印数据了,把我的结果代码贴出来
与大家分享:
void COM1Init(u32 BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = BaudRate;//波特率设置
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_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_Cmd(USART1, ENABLE);
USART_ClearFlag(USART1, USART_FLAG_TC);
}
void TracePrintfln(char *format, ... )
{
char str_temp[256];
va_list vaotr;
int i, len;
va_start(vaotr, format);
vsprintf(str_temp, format, vaotr);
va_end(vaotr);
//h83029_sci1_UART_send_string(str_temp);
len = strlen(str_temp);
for (i = 0; i < len; i++) {
USART_SendData(USART1, str_temp);
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
USART_SendData(USART1, '\n');
while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);
}
使用的时候:
COM1Init(115200);
TracePrintfln("trace function ok!");
但是还有一个问题,我要打印的字符串的第一个字符丢失了,就是说,
上面语句打印出来的结果是 "race function ok!"。
不知道是怎么回事。
|