STM32的uart1、uart2、uart3重定向函数(标准库版)

STM32的uart1、uart2、uart3重定向函数

标准库

//uart1
int fputc(int ch,FILE *f)  
{    
    while(USART_GetFlagStatus(USART1,USART_FLAG_TC) != SET);   
    USART_SendData(USART1,(unsigned char)ch);      
    while(USART_GetFlagStatus(USART1,USART_FLAG_TC) != SET);    
    return (ch);    
} 
//uart2
int fputc(int ch,FILE *f)  
{    
    while(USART_GetFlagStatus(USART2,USART_FLAG_TC) != SET);   
    USART_SendData(USART2,(unsigned char)ch);      
    while(USART_GetFlagStatus(USART2,USART_FLAG_TC) != SET);    
    return (ch);    
} 
//uart3
int fputc(int ch,FILE *f)  
{    
    while(USART_GetFlagStatus(USART3,USART_FLAG_TC) != SET);   
    USART_SendData(USART3,(unsigned char)ch);      
    while(USART_GetFlagStatus(USART3,USART_FLAG_TC) != SET);    
    return (ch);    
} 

你可能感兴趣的:(cks32,stm32f10x)