资源简介
简介:STM32与上位机之间用通信协议(自己定义)进行串口通信。怎么判断上位机发过来的指令是正确的,而不是一串乱码?怎么从正确的指令中提取出想要的命令代号,从而实现想要的功能?
方法:读取上位机发来的命令,逐位判断命令的包头和包尾,如果能对应上,则这串指令是正确的,然后从指令中提取想要的数据和命令等。举个栗子:通信协议是自己定义的,不是modbus协议等。。如F0 5A 15 15 25 16 09 02 12 14 FF A5 F0(都是16进制),F0 5A是包头,A5 F0是包尾,黑色15是命令代号,中间蓝色是我想发的数据,橙色FF是校验位。只要包头包尾校验正确,基本这串指令不会有问题。

代码片段和文件信息
/**
******************************************************************************
* @file system_stm32l0xx.c
* @author MCD Application Team
* @version V1.7.1
* @date 25-November-2016
* @brief CMSIS Cortex-M0+ Device Peripheral Access layer System Source File.
*
* This file provides two functions and one global variable to be called from
* user application:
* - SystemInit(): This function is called at startup just after reset and
* before branch to main program. This call is made inside
* the “startup_stm32l0xx.s“ file.
*
* - SystemCoreClock variable: Contains the core clock (HCLK) it can be used
* by the user application to setup the SysTick
* timer or configure other parameters.
*
* - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
* be called whenever the core clock is changed
* during program execution.
*
*
******************************************************************************
* @attention
*
* © COPYRIGHT(c) 2016 STMicroelectronics
*
* Redistribution and use in source and binary forms with or without modification
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS“
* AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT INDIRECT INCIDENTAL SPECIAL EXEMPLARY OR CONSEQUENTIAL
* DAMAGES (INCLUDING BUT NOT LIMITED TO PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT STRICT LIABILITY
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/** @addto
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4640 2018-06-15 21:20 Receive_it\.mxproject
文件 490933 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l011xx.h
文件 502148 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l021xx.h
文件 503392 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l031xx.h
文件 514607 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l041xx.h
文件 518739 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l051xx.h
文件 616127 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l052xx.h
文件 629289 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l053xx.h
文件 529954 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l061xx.h
文件 627342 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l062xx.h
文件 640504 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l063xx.h
文件 539799 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l071xx.h
文件 646331 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l072xx.h
文件 659701 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l073xx.h
文件 551014 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l081xx.h
文件 657546 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l082xx.h
文件 670916 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l083xx.h
文件 8393 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\stm32l0xx.h
文件 3922 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Include\system_stm32l0xx.h
文件 10891 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l011xx.s
文件 11166 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l021xx.s
文件 10431 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l031xx.s
文件 10681 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l041xx.s
文件 11017 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l051xx.s
文件 11204 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l052xx.s
文件 11278 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l053xx.s
文件 11029 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l061xx.s
文件 11215 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l062xx.s
文件 11273 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l063xx.s
文件 11325 2017-08-05 09:48 Receive_it\Drivers\CMSIS\Device\ST\STM32L0xx\Source\Templates\arm\startup_stm32l071xx.s
............此处省略626个文件信息
- 上一篇:Linux下的BT软件源码,包含详细讲解100多页
- 下一篇:青岛市地图shp格式
相关资源
- SCI串口中断接收发送例程
- stm32l0系列HAL库
- HAL库下的OLED移植
- HAL库的OLED 移植
- Keil.STM32L0xx_DFP.2.0.0.pack
- USART基于hal库stm32f407串口通讯.rar
- STM32F4基于HAL库的LCD显示实验
- stm32f103c8t6移植uC/OS-III基于HAL库的工程
- 基于STM32备份寄存器BKP实验
- STM32F1基本定时器
- HAL库函数说明
- STM32使用串口中断接收字符串.zip
- STM32F429DISCOVERY外接SD卡使用SDIO4BIT方式
- HAL库函数手册
- STM32F030使用HAL库做低功耗
- 基于STM32 HAL库的定时任务调度器例程
- stm32智能寻迹避障小车代码
- STM32L051C8T6_USART1.zip
- STM32 HAL库版本 4线1602A程序
- stm32f407 ili9341屏幕驱动 HAL库 带FreeR
- STM32使用cubemx和HAL库驱动ICM20602
- STM32F103 Hal库 EV1527 433M解码
- MPU6050 DMP+ADXL345+NRF24L01+HAL库+STM32F103C
- hal库定时器触发adc dma采集
- STM32串口中断接收发送数据
- STM32Cube HAL库操作系统+CAN收发配置
- BH1750FVI STM32F103 HAL库 硬件IIC例程
- stm32 cubemx hal库 串口收发 中断接收 项
- STM32L0中文参考手册新版
- STM32L0XX 低功耗程序源码
评论
共有 条评论