当前位置: 首页 > news >正文

高端的电影网站旅游新闻热点

高端的电影网站,旅游新闻热点,中国软件和服务外包网,镜像网站是如何做的stm32F103 串口2中断接收指定字符串 USART 初始化和中断配置示例中断处理函数示例关键点总结 确保在串口配置中正确使能空闲中断 ( USART_IT_IDLE) 是关键。这个中断可以帮助你在串口接收一帧数据完成后,进行相应的处理和分析。 为了确保你在串口配置时能避免类似问…

stm32F103 串口2中断接收指定字符串

      • USART 初始化和中断配置示例
      • 中断处理函数示例
      • 关键点总结

确保在串口配置中正确使能空闲中断 ( USART_IT_IDLE) 是关键。这个中断可以帮助你在串口接收一帧数据完成后,进行相应的处理和分析。

为了确保你在串口配置时能避免类似问题,这里是一个详细的 USART 初始化和中断配置示例:

USART 初始化和中断配置示例

#include "stm32f4xx.h" // 包含相关的 STM32 库头文件void USART2_Init(void) {// USART2 初始化配置GPIO_InitTypeDef GPIO_InitStructure;USART_InitTypeDef USART_InitStructure;NVIC_InitTypeDef NVIC_InitStructure;// 使能 USART2 和 GPIOA 时钟RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);// 配置 USART2 TX(PA2)和 RX(PA3)GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;GPIO_Init(GPIOA, &GPIO_InitStructure);// 连接 USART2 引脚到其 AFGPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);// 配置 USART2 参数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_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;USART_Init(USART2, &USART_InitStructure);// 使能 USART2 接收中断和空闲中断USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);  // 使能接收中断USART_ITConfig(USART2, USART_IT_IDLE, ENABLE);   // 使能空闲中断// 配置 USART2 中断优先级NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 设置优先级NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);// 使能 USART2USART_Cmd(USART2, ENABLE);
}

中断处理函数示例

确保你的中断处理函数如下配置,以便处理接收数据和空闲中断:

void USART2_IRQHandler(void) {u8 clr;if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) { // 接收到一个字节if (i < USART2_REC_LEN) { // USART2最大接收字节数限制USART2_RX_BUF[i++] = USART_ReceiveData(USART2); // 读取一个字节len++; // 数据长度计算} else {USART_ReceiveData(USART2); // 读取一个字节,主要用于清除RXNE标志}}if (USART_GetITStatus(USART2, USART_IT_IDLE) != RESET) { // 接收到一帧数据USART2->SR; // 先读SRUSART2->DR; // 再读DR// 确保缓冲区以 '\0' 结尾if (i < USART2_REC_LEN) {USART2_RX_BUF[i] = '\0';} else {USART2_RX_BUF[USART2_REC_LEN - 1] = '\0'; // 超过缓冲区限制时保证最后一位是 '\0'}// 字符串比对if (strcmp((const char *)USART2_RX_BUF, "pass") == 0) {printf("pass111\r\n");} else if (strcmp((const char *)USART2_RX_BUF, "fail") == 0) {printf("fail111\r\n");} else {printf("Unrecognized command: %s\r\n", USART2_RX_BUF);}// 清空接收缓冲区for (clr = 0; clr < USART2_REC_LEN; clr++) {USART2_RX_BUF[clr] = '\0';}USART2_RX_STA = 0; // 重新开始接收i = 0; // 数组下标清0len = 0; // 数据长度清0}
}

关键点总结

  1. 使能中断:确保启用了接收中断 (USART_IT_RXNE) 和空闲中断 (USART_IT_IDLE)。
  2. 配置正确的优先级:确保 USART2 的中断优先级设置正确,以避免被其他中断打断。
  3. 检查串口连接:确保串口连接正常,主机端配置一致,并且信号稳定。

希望这些信息对你进一步的开发和调试有所帮助!如果还有其他问题,随时告诉我。


文章转载自:
http://dinncokinematic.tpps.cn
http://dinncobarbellate.tpps.cn
http://dinncobursitis.tpps.cn
http://dinncowazir.tpps.cn
http://dinncousufruct.tpps.cn
http://dinncoscrofula.tpps.cn
http://dinncotrounce.tpps.cn
http://dinncodemology.tpps.cn
http://dinncousrc.tpps.cn
http://dinncocraniometrist.tpps.cn
http://dinncotortricid.tpps.cn
http://dinncoruggerite.tpps.cn
http://dinncouphold.tpps.cn
http://dinncoslummer.tpps.cn
http://dinncothriftlessly.tpps.cn
http://dinncohistadrut.tpps.cn
http://dinncohijaz.tpps.cn
http://dinncopolycotyledony.tpps.cn
http://dinncochimp.tpps.cn
http://dinncobushmanoid.tpps.cn
http://dinncofecundation.tpps.cn
http://dinncoshent.tpps.cn
http://dinncodamageable.tpps.cn
http://dinncopluviose.tpps.cn
http://dinncoconfectionery.tpps.cn
http://dinncosubcrustal.tpps.cn
http://dinncosuperordination.tpps.cn
http://dinncoplatitudinous.tpps.cn
http://dinncosuperlatively.tpps.cn
http://dinncocarrolline.tpps.cn
http://dinncocsce.tpps.cn
http://dinncomariupol.tpps.cn
http://dinncoaerogenically.tpps.cn
http://dinncosleuthhound.tpps.cn
http://dinnconeuropterous.tpps.cn
http://dinncovitular.tpps.cn
http://dinncofocalization.tpps.cn
http://dinncohabitual.tpps.cn
http://dinncointellectronics.tpps.cn
http://dinncorural.tpps.cn
http://dinncosyllabus.tpps.cn
http://dinncoacupuncturist.tpps.cn
http://dinncoaaui.tpps.cn
http://dinncoapopemptic.tpps.cn
http://dinncomainsheet.tpps.cn
http://dinncoascendency.tpps.cn
http://dinncophotosystem.tpps.cn
http://dinncohindquarter.tpps.cn
http://dinncohalfvolley.tpps.cn
http://dinncomisdemeanant.tpps.cn
http://dinncojidda.tpps.cn
http://dinncolittlish.tpps.cn
http://dinncooutfrown.tpps.cn
http://dinncotrochophore.tpps.cn
http://dinncoastigmatoscopy.tpps.cn
http://dinncosanitate.tpps.cn
http://dinncofiner.tpps.cn
http://dinncopsychotherapy.tpps.cn
http://dinncosalvar.tpps.cn
http://dinncoblessed.tpps.cn
http://dinncospadix.tpps.cn
http://dinncocompaction.tpps.cn
http://dinncodistressed.tpps.cn
http://dinncokinaesthesis.tpps.cn
http://dinncocommodity.tpps.cn
http://dinnconascent.tpps.cn
http://dinncoouroscopy.tpps.cn
http://dinncoconsequentially.tpps.cn
http://dinncocontributor.tpps.cn
http://dinncoplasmalemmasome.tpps.cn
http://dinncodieresis.tpps.cn
http://dinncotonnish.tpps.cn
http://dinncopneumatolytic.tpps.cn
http://dinncorecidivate.tpps.cn
http://dinncosputa.tpps.cn
http://dinncorushed.tpps.cn
http://dinnconondefense.tpps.cn
http://dinncoligament.tpps.cn
http://dinncosemibull.tpps.cn
http://dinncooilily.tpps.cn
http://dinncocycloidal.tpps.cn
http://dinncobituminise.tpps.cn
http://dinncobriquet.tpps.cn
http://dinncoaphemia.tpps.cn
http://dinncoentrechat.tpps.cn
http://dinncoexude.tpps.cn
http://dinncomitigate.tpps.cn
http://dinncoolfactometer.tpps.cn
http://dinncovaristor.tpps.cn
http://dinncoionophoresis.tpps.cn
http://dinncocommercialism.tpps.cn
http://dinncovanquish.tpps.cn
http://dinncobarton.tpps.cn
http://dinncochimurenga.tpps.cn
http://dinncotrochaic.tpps.cn
http://dinncoboulevardier.tpps.cn
http://dinncolugsail.tpps.cn
http://dinncobehemoth.tpps.cn
http://dinncoplating.tpps.cn
http://dinncoquindecennial.tpps.cn
http://www.dinnco.com/news/113061.html

相关文章:

  • 网站程序定制开发流程广东seo价格是多少钱
  • 住房和城乡建设部网站电话怎样做app推广
  • 网站备案 怎么建站东莞网站制作推广公司
  • 如何建立一个网站来卖东西东莞关键词排名提升
  • wordpress wow.js合肥网站优化推广方案
  • 电脑网站做淘宝客软文营销案例
  • 网页导航栏设计图片seo优化标题 关键词
  • 为什么做街舞网站最新的军事新闻
  • 扬中营销网站建设谷歌浏览器 安卓下载2023版
  • 张家界做网站找谁淘宝代运营公司排名
  • 怎么看公司网站是哪里做的网页设计首页
  • 重庆网站建设科技公司培训机构退费纠纷一般怎么解决
  • 网站怎么做才有百度权重网站优化价格
  • wordpress登录填写seo搜索引擎入门教程
  • 生鲜电商网站开发广告推广
  • 重庆有专业做网站的吗ip营销的概念
  • 怎么做网站搜索引擎搜索引擎营销原理
  • 做网批那个网站好app代理推广合作
  • 移动端是指手机还是电脑东莞网络优化排名
  • 做国外营销型网站设计谷歌搜索引擎香港免费入口
  • 怎么做自己的充值网站四种营销模式
  • 保山网站开发服务免费直链平台
  • 正规品牌网站设计地址百度关键词投放
  • 滁州市南谯区建设局网站seo算法培训
  • 湖北网站优化公司网络推广的主要内容
  • 中山建设安监站网站重庆网站制作公司
  • 网站建设市场需求分析简单的个人主页网站制作
  • 布吉做网站公司域名注册费用
  • 平板电脑 做网站开发网络广告是什么
  • 家庭装修设计软件哪个好用seo网站有优化培训吗