资源简介
简介: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格式
相关资源
- STM32F429 485实验源码(hal库)
- STM32F407ZGT6实现HAL库SPI扩展FLASH功能M
- STM32L4/L4+ HAL库英文完整版
- STM32F1 HAL库手册原版
- 基于HAL库驱动ov7670.rar
- STM32l0XX
- STM32Cube HAL库操作系统+串口+DMA收发配
- 基于STM32,hal库,使用CubeMX进行开发的
- 基于HAL库STM32+RC522读写卡程序 调试完
- HAL库W5500代码SPI版本
- STM32F1xx_HAL库_V1.4.0_及例程
- STM32CubeMX中文使用手册和STM32_f1的hal库
- stm32L051 IAP程序升级,希望大家有用
- STM32 L053串口中断接收不定长数据DMA发
- STM32 HAL库 硬件I2C对MPU6050的使用
- STM32L0中文参考手册
- stm32f407 ili9341屏幕驱动 HAL库 带FreeR
- STM32F4xx HAL驱动说明书
- STM32cubeMx配置PWM输出,捕获输入,AD
- STM32L0系列数据手册中文版
- LL库使用手册 stm32L4xx 手册
- STM32_HAL+串口+DMA发送和不定长度数据接
- stm32 hal库的例程
- STM32F0实战 基于HAL库开发 高显生著
- STM32L151C8T6 UCSOII 代码 串口中断接收
- STM32F4 HAL库函数手册(英文版)
- STM32测量甲醛HAl库
- STM32L073实现DMA方式获取ADC多通道值,
- STM32L4使用SPI发送数据
- 基于HAL库的ADC+DMA程序——STM32F429
评论
共有 条评论