• 大小: 2.25MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-09
  • 语言: 其他
  • 标签: stm32  串口接收  

资源简介

STM32串口接收不定长数据程序,并进行处理,非常方便而且注释明确

资源截图

代码片段和文件信息

#include “uart.h“



void USART1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;// 定义一个GPIO_InitTypeDef类型的变量
USART_InitTypeDef USART_InitStructure;// 定义一个USART_InitTypeDef类型的变量
NVIC_InitTypeDef NVIC_InitStructure; 

/* 允许GPIOA和USART1的时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA ENABLE);

/* 配置USART1 */
/* 配置PA9(TXD) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; // 选择PIN9
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // 复用推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 50MHz速度
GPIO_Init(GPIOA &GPIO_InitStructure);// 把参数带进函数配置

/* 配置PA10(RXD) */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;// 选择PIN10
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;// 选择浮空输入
GPIO_Init(GPIOA &GPIO_InitStructure); // 把参数带进函数配置

/* 配置串口USART1的模式 */
USART_InitStructure.USART_BaudRate = 115200; // 波特率9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b;// 8个数据位
USART_InitStructure.USART_StopBits = USART_StopBits_1; // 1个停止位
USART_InitStructure.USART_Parity = USART_Parity_No ; // 无奇偶校验
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;// 无硬件流控制
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1 &USART_InitStructure); //把上面配置的参数带进函数里面初始化串口

/* 打开空闲中断 */
USART_ITConfig(USART1 USART_IT_IDLE ENABLE);
/* 打开接收中断 */
USART_ITConfig(USART1 USART_IT_RXNE ENABLE);

/* 配置NVIC优先级组 */  
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

/* 允许UART1中断 */
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;  
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);

USART_ClearFlag(USART1USART_FLAG_TC);

USART_Cmd(USART1 ENABLE);// 打开串口1
}


// 发送一个字节
void USART1_Send_byte(uint8_t val)
{
USART_SendData(USART1 val);
while (USART_GetFlagStatus(USART1 USART_FLAG_TC) == RESET); //等待发送完成
}

// 接收一个字节
uint8_t USART1_Recv_byte(void)
{
while (USART_GetFlagStatus(USART1 USART_FLAG_RXNE) == RESET);
return USART_ReceiveData(USART1);
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\CFG\
     文件        2348  2015-10-24 20:03  STM32串口接收不定长数据程序\CFG\uart.c
     文件         179  2015-03-05 15:34  STM32串口接收不定长数据程序\CFG\uart.h
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\CMSIS\
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\CoreSupport\
     文件       17273  2010-06-07 10:25  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\CoreSupport\core_cm3.c
     文件       85714  2011-02-09 14:59  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\CoreSupport\core_cm3.h
     目录           0  2015-10-23 19:45  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\
     目录           0  2015-10-23 19:45  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\
     文件       26297  2011-03-14 12:31  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\Release_Notes.html
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\
     文件       15766  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_cl.s
     文件       15503  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_hd.s
     文件       15692  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_hd_vl.s
     文件       12376  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_ld.s
     文件       13656  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_ld_vl.s
     文件       12765  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_md.s
     文件       14073  2011-03-10 10:51  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_md_vl.s
     文件       15955  2011-03-10 10:51  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\arm\startup_stm32f10x_xl.s
     目录           0  2015-10-24 21:39  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7\
     文件       13072  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7\startup_stm32f10x_cl.s
     文件       13160  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7\startup_stm32f10x_hd.s
     文件       12482  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7\startup_stm32f10x_hd_vl.s
     文件        9814  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7\startup_stm32f10x_ld.s
     文件       10562  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7\startup_stm32f10x_ld_vl.s
     文件       10269  2011-03-10 10:52  STM32串口接收不定长数据程序\Libraries\CMSIS\CM3\DeviceSupport\ST\STM32F10x\startup\gcc_ride7\startup_stm32f10x_md.s
............此处省略128个文件信息

评论

共有 条评论