日本a√视频在线,久久青青亚洲国产,亚洲一区欧美二区,免费g片在线观看网站

        <style id="k3y6c"><u id="k3y6c"></u></style>
        <s id="k3y6c"></s>
        <mark id="k3y6c"></mark>
          
          

          <mark id="k3y6c"></mark>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > STM32筆記之八:來跟PC打個招呼,基本串口通訊

          STM32筆記之八:來跟PC打個招呼,基本串口通訊

          作者: 時間:2016-11-26 來源:網(wǎng)絡(luò) 收藏
          a)目的:在基礎(chǔ)實驗成功的基礎(chǔ)上,對串口的調(diào)試方法進行實踐。硬件代碼順利完成之后,對日后調(diào)試需要用到的printf重定義進行調(diào)試,固定在自己的庫函數(shù)中。

          b)初始化函數(shù)定義:

          本文引用地址:http://yuyingmama.com.cn/article/201611/322074.htm

          void USART_Configuration(void);//定義串口初始化函數(shù)

          c)初始化函數(shù)調(diào)用:

          void UART_Configuration(void);//串口初始化函數(shù)調(diào)用

          初始化代碼:

          void USART_Configuration(void)//串口初始化函數(shù)

          {

          //串口參數(shù)初始化

          USART_InitTypeDef USART_InitStructure;//串口設(shè)置恢復(fù)默認參數(shù)

          //初始化參數(shù)設(shè)置

          USART_InitStructure.USART_BaudRate=9600;//波特率9600

          USART_InitStructure.USART_WordLength = USART_WordLength_8b;//字長8位

          USART_InitStructure.USART_StopBits = USART_StopBits_1;//1位停止字節(jié)

          USART_InitStructure.USART_Parity = USART_Parity_No;//無奇偶校驗

          USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//無流控制

          USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;//打開Rx接收和Tx發(fā)送功能

          USART_Init(USART1, &USART_InitStructure);//初始化

          USART_Cmd(USART1, ENABLE);//啟動串口

          }

          RCC中打開相應(yīng)串口

          RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE);

          GPIO里面設(shè)定相應(yīng)串口管腳模式

          //串口1的管腳初始化

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;//管腳9

          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;//復(fù)用推挽輸出

          GPIO_Init(GPIOA, &GPIO_InitStructure);//TX初始化

          GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;//管腳10

          GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空輸入

          GPIO_Init(GPIOA, &GPIO_InitStructure);//RX初始化

          d)簡單應(yīng)用:

          發(fā)送一位字符

          USART_SendData(USART1,數(shù)據(jù));//發(fā)送一位數(shù)據(jù)

          while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){}//等待發(fā)送完畢

          接收一位字符

          while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET){}//等待接收完畢

          變量= (USART_ReceiveData(USART1));//接受一個字節(jié)

          發(fā)送一個字符串

          先定義字符串:char rx_data[250];

          然后在需要發(fā)送的地方添加如下代碼

          int i;//定義循環(huán)變量

          while(rx_data!=