在线看毛片网站电影-亚洲国产欧美日韩精品一区二区三区,国产欧美乱夫不卡无乱码,国产精品欧美久久久天天影视,精品一区二区三区视频在线观看,亚洲国产精品人成乱码天天看,日韩久久久一区,91精品国产91免费

<menu id="6qfwx"><li id="6qfwx"></li></menu>
    1. <menu id="6qfwx"><dl id="6qfwx"></dl></menu>

      <label id="6qfwx"><ol id="6qfwx"></ol></label><menu id="6qfwx"></menu><object id="6qfwx"><strike id="6qfwx"><noscript id="6qfwx"></noscript></strike></object>
        1. <center id="6qfwx"><dl id="6qfwx"></dl></center>

            新聞中心

            STM32下串口的使用

            作者: 時間:2016-11-19 來源:網(wǎng)絡(luò) 收藏

            STM32下關(guān)于串口的固件庫寫得相當(dāng)好了,以下只是本文對串口庫的一點點封裝

            本文引用地址:http://www.biyoush.com/article/201611/318197.htm

            /*HKY_uart.h*/#ifndef _HKY_UART_H_#define _HKY_UART_H_#include "stm32f10x_lib.h"http://#include "platform_config.h"#define  GPIO_RTSPin              GPIO_Pin_1#define  GPIO_CTSPin              GPIO_Pin_0#define  GPIO_TxPin               GPIO_Pin_2#define  GPIO_RxPin               GPIO_Pin_3void USART2_Configuration(void);int USART_sendBuf(USART_TypeDef* USARTx, u8 *buf, u32 len);int USART_recvBuf(USART_TypeDef* USARTx, u8 *buf, u32 len);#endif //_HKY_UART_H_

            /*HKY_uart.c*/#include "HKY_uart.h"/* --------------------------------------------------------------------------*// * @Brief:  USART2_Configuration *//* --------------------------------------------------------------------------*/void USART2_Configuration(void){USART_InitTypeDef USART_InitStructure;GPIO_InitTypeDef GPIO_InitStructure;//IO port----------------------------------------------------------------------/* Configure USART2 RTS and USART2 Tx as alternate function push-pull */GPIO_InitStructure.GPIO_Pin = GPIO_TxPin;//GPIO_RTSPin | GPIO_TxPin;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;GPIO_Init(GPIOA, &GPIO_InitStructure);/* Configure USART2 CTS and USART2 Rx as input floating */GPIO_InitStructure.GPIO_Pin = GPIO_RxPin;//GPIO_CTSPin | GPIO_RxPin;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;GPIO_Init(GPIOA, &GPIO_InitStructure);/* USART2 configuration ------------------------------------------------------*//* USART2 configured as follow:- BaudRate = 115200 baud  - Word Length = 8 Bits- One Stop Bit- No parity- Hardware flow control enabled (RTS and CTS signals)- Receive and transmit enabled*/USART_InitStructure.USART_BaudRate = 115200;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_HardwareFlowControl_RTS_CTS;USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;USART_Init(USART2, &USART_InitStructure);/* Enable the USART2 */USART_Cmd(USART2, ENABLE);USART_ClearFlag(USART2, USART_FLAG_TC); // clear flag}/* --------------------------------------------------------------------------*// * @Brief:  USART_sendBuf * * @Param: USARTx, which uart port* @Param: buf, send buffer* @Param: len, buffer length* * @Returns:   send bytes count*//* --------------------------------------------------------------------------*/int USART_sendBuf(USART_TypeDef* USARTx, u8 *buf, u32 len){u32 busy_cnt = 0;u32 i = 0;while (i < len){USART_SendData(USARTx, buf[i++]);busy_cnt = 0;while(USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET){busy_cnt++; if (busy_cnt > 0xffff)return i; //send error, return sended bytes count}}return len; }/* --------------------------------------------------------------------------*// * @Brief:  USART_recvBuf * * @Param: USARTx, which uart port* @Param: buf, receive buffer* @Param: len, buffer length* * @Returns:  received bytes count*//* --------------------------------------------------------------------------*/int USART_recvBuf(USART_TypeDef* USARTx, u8 *buf, u32 len){u32 busy_cnt = 0;u32 i = 0;while (i < len){if(USART_GetFlagStatus(USARTx, USART_FLAG_RXNE) != RESET){buf[i] = USART_ReceiveData(USARTx) & 0xff;i++;}else{busy_cnt++;}if (busy_cnt > 0xffff)return i; //receive error, return received bytes count}return len;}


            關(guān)鍵詞: STM32串

            評論


            技術(shù)專區(qū)

            關(guān)閉