資源簡介
STM32工程中可直接調用USART1-UART5,封裝好串口中斷,接收指針,數據傳輸穩定可靠無誤。
代碼片段和文件信息
#include?“A_UART.h“?
#include?“includes.h“?
#if?USART1_Enable
COM_TypeDef?COM1;
#endif
#if?USART2_Enable
COM_TypeDef?COM2;
#endif
#if?USART3_Enable
COM_TypeDef?COM3;
#endif
#if?UART4_Enable
COM_TypeDef?COM4;
#endif
#if?UART5_Enable
COM_TypeDef?COM5;
#endif
void?Memery_Copy1(uint8_t?*Destinationuint8_t?*Sourceuint16_t?Len)
{
uint8_t?i;
uint8_t?*ptr;
ptr?=?Source;
for(i=0;i {
*Destination?=?*ptr;
?Destination++;
?ptr++;
}
}
//管腳配置
void?GPIO_USARTx_Pin_Config(USART_TypeDef*uart)
{
NVIC_InitTypeDef?NVIC_InitStructure;
GPIO_InitTypeDef?GPIO_InitStructure;
#if?USART1_Enable
if(uart==USART1) //USART1(PB6PB7)
{
RCC_APB2PeriphClockCmd(USART1_RCC?ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1??ENABLE);
NVIC_InitStructure.NVIC_IRQChannel?=?USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?5;
NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_InitStructure.GPIO_Pin?=?USART1_T_Pin; ???
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode?=GPIO_Mode_AF_PP;
GPIO_Init(USART1_Port?&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin?=?USART1_R_Pin;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IN_FLOATING;
GPIO_Init(USART1_Port?&GPIO_InitStructure);
GPIO_PinRemapConfig(GPIO_Remap_USART1ENABLE);
}
#endif
#if?USART2_Enable
if(uart==USART2) //USART2(PA2PA3)
{
RCC_APB2PeriphClockCmd(USART2_RCC?ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2??ENABLE);
NVIC_InitStructure.NVIC_IRQChannel?=?USART2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?5;
NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_InitStructure.GPIO_Pin?=?USART2_T_Pin; ???
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode?=GPIO_Mode_AF_PP;
GPIO_Init(GPIOA?&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin?=?USART2_R_Pin;
GPIO_InitStructure.GPIO_Mode?=?GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA?&GPIO_InitStructure);
}
#endif
#if?USART3_Enable
if(uart==USART3) //USART3(PB10PB11)
{
RCC_APB2PeriphClockCmd(USART3_RCC?ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3??ENABLE);
NVIC_InitStructure.NVIC_IRQChannel?=?USART3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority?=?0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority?=?5;
NVIC_InitStructure.NVIC_IRQChannelCmd?=?ENABLE;
NVIC_Init(&NVIC_InitStructure);
GPIO_InitStructure.GPIO_Pin?=?USART3_T_Pin;
GPIO_InitStructure.GPIO_Speed?=?GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode?=GPIO_Mode_AF_PP;
GPIO_Init(USART3_Port?&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin?=
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2481??2018-11-28?15:45??A_UART.h
?????文件??????12587??2018-11-28?15:45??A_UART.c
-----------?---------??----------?-----??----
????????????????15068????????????????????2
評論
共有 條評論