• 大小: 3KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: 其他
  • 标签: STM32  稳定  

资源简介

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


评论

共有 条评论