zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    12.SolrCloud原理
    11.SolrCloud集群环境搭建
    10.Solr4.10.3数据导入(DIH全量增量同步Mysql数据)
    9.Solr4.10.3数据导入(post.jar方式和curl方式)
    Java程序设计之最大公约数和最小公倍数
    Java程序设计之正则表达式
    Java程序设计之整数分解
    Java程序设计之裴波拉切那数列(兔子一年的数量)
    Java并发编程实例(synchronized)
    Java程序设计之合租房synchronized(二)
  • 原文地址:https://www.cnblogs.com/penuel/p/11264276.html
Copyright © 2011-2022 走看看