• STM32F4库函数初始化系列:串口发送


     1 void Configuration(void)
     2 {
     3   USART_InitTypeDef USART_InitStructure;
     4   GPIO_InitTypeDef GPIO_InitStructure;
     5   RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
     6    //TX
     7   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; 
     8   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
     9   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    10   GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
    11   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
    12   GPIO_Init(GPIOB, &GPIO_InitStructure);
    13   //RX
    14   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; 
    15   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
    16   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    17   GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    18   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    19   GPIO_Init(GPIOB, &GPIO_InitStructure);
    20   
    21   GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
    22   GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
    23   
    24   
    25   USART_OverSampling8Cmd(USART3, ENABLE);  
    26   USART_InitStructure.USART_BaudRate = 9600;
    27   USART_InitStructure.USART_WordLength = USART_WordLength_8b;
    28   USART_InitStructure.USART_StopBits = USART_StopBits_1;
    29   USART_InitStructure.USART_Parity = USART_Parity_No;
    30   USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    31   USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx;
    32   USART_Init(USART3, &USART_InitStructure); 
    33   USART_Cmd(USART3, ENABLE); 
    34 }
    35 void UART_PutChar(char Data)  
    36 {  
    37     USART_SendData(USART3,Data);  
    38     while(USART_GetFlagStatus(USART3,USART_FLAG_TC) == RESET){}  
    39 }  
    40 void UART_PutStr(char *str)    
    41 {    
    42     while (0 != *str)    
    43     {    
    44         USART3->SR;
    45         UART_PutChar(*str);    
    46         str++;    
    47     }    
    48 }   
    49 int main(void)
    50 {
    51     Configuration();
    52     UART_PutStr("play,0001,$"); 
    53 }
  • 相关阅读:
    The builder launch configuration could not be found
    桌面上的图标不见了
    outlook软件后台运行
    c盘突然少了容量
    win7台式机睡眠时间修改
    系统占用的内存
    详细讲解 java 中的synchronized 转自 http://www.cnblogs.com/devinzhang/archive/2011/12/14/2287675.html
    The US ASCII Character Set 对应码 可以解决 URL中的特殊符号的传输问题
    oracle基本操作 转载
    内存中的 栈与堆
  • 原文地址:https://www.cnblogs.com/penuel/p/11264276.html
Copyright © 2020-2023  润新知