STM32HAL 移植 cJSON开源库 (裸机开发神器)

2023-11-09

目录

 

概述

一、使用方法

二、STM32CubeMx配置

三、Examples

四、运行结果

五、总结


 

概述


        本篇文章介绍如何使用STM32引用 cJSON开源库,JSON格式在互联网数据交互时常用的一个格式,现嵌入式物联网方向,经常使用到,如:MQTT协议,LwM2M协议等等,只要是把数据上传到后台,方便格式查阅与统一处理,终端设备有必要使用JSON格式来封装数据。

GitHub:https://github.com/DaveGamble/cJSON

硬件:STM32F103CBT6最小系统板
软件:Keil 5.29  + STM32CubeMX6.01

 

一、使用方法

详细步骤请移步到官网介绍,不过也没有关系,按照下面的步骤来也行。

二、STM32CubeMx配置

三、Examples

打开STM32CubeMx生成的keil工程,新建cJSON文件夹,把代码仓库cJSON下载下来的代码,添加cJSON.c、cJSON_Utils.c、test.c 3个文件即可,test.c文件是开源库,编写的json格式字符的测试示例。

在keil添加上图的文件即可。

添加包含头文件路径

添加完后,编译项目。

打开test.c文件,修改以下地方

再次编译

 

 

修改堆栈大小
方式1

方式2

生成代码后,startup_stm32f103xb.s汇编文件就会修改,跟方式1 一个样。

1、test.c文件

/*
  Copyright (c) 2009-2017 Dave Gamble and cJSON contributors

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"


/* We don't do anything about it */
#define exit(a)  	\
			if(#a == "1")	\
				;					\
			else				\
				;					\
			
			
/* Used by some code below as an example datatype. */
struct record
{
    const char *precision;
    double lat;
    double lon;
    const char *address;
    const char *city;
    const char *state;
    const char *zip;
    const char *country;
};


/* Create a bunch of objects as demonstration. */
static int print_preallocated(cJSON *root)
{
    /* declarations */
    char *out = NULL;
    char *buf = NULL;
    char *buf_fail = NULL;
    size_t len = 0;
    size_t len_fail = 0;

    /* formatted print */
    out = cJSON_Print(root);

    /* create buffer to succeed */
    /* the extra 5 bytes are because of inaccuracies when reserving memory */
    len = strlen(out) + 5;
    buf = (char*)malloc(len);
    if (buf == NULL)
    {
        printf("Failed to allocate memory.\n");
        exit(1);
    }

    /* create buffer to fail */
    len_fail = strlen(out);
    buf_fail = (char*)malloc(len_fail);
    if (buf_fail == NULL)
    {
        printf("Failed to allocate memory.\n");
        exit(1);
    }

    /* Print to buffer */
    if (!cJSON_PrintPreallocated(root, buf, (int)len, 1)) {
        printf("cJSON_PrintPreallocated failed!\n");
        if (strcmp(out, buf) != 0) {
            printf("cJSON_PrintPreallocated not the same as cJSON_Print!\n");
            printf("cJSON_Print result:\n%s\n", out);
            printf("cJSON_PrintPreallocated result:\n%s\n", buf);
        }
        free(out);
        free(buf_fail);
        free(buf);
        return -1;
    }

    /* success */
    printf("%s\n", buf);

    /* force it to fail */
    if (cJSON_PrintPreallocated(root, buf_fail, (int)len_fail, 1)) {
        printf("cJSON_PrintPreallocated failed to show error with insufficient memory!\n");
        printf("cJSON_Print result:\n%s\n", out);
        printf("cJSON_PrintPreallocated result:\n%s\n", buf_fail);
        free(out);
        free(buf_fail);
        free(buf);
        return -1;
    }

    free(out);
    free(buf_fail);
    free(buf);
    return 0;
}

/* Create a bunch of objects as demonstration. */
static void create_objects(void)
{
    /* declare a few. */
    cJSON *root = NULL;
    cJSON *fmt = NULL;
    cJSON *img = NULL;
    cJSON *thm = NULL;
    cJSON *fld = NULL;
    int i = 0;

    /* Our "days of the week" array: */
    const char *strings[7] =
    {
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday"
    };
    /* Our matrix: */
    int numbers[3][3] =
    {
        {0, -1, 0},
        {1, 0, 0},
        {0 ,0, 1}
    };
    /* Our "gallery" item: */
    int ids[4] = { 116, 943, 234, 38793 };
    /* Our array of "records": */
    struct record fields[2] =
    {
        {
            "zip",
            37.7668,
            -1.223959e+2,
            "",
            "SAN FRANCISCO",
            "CA",
            "94107",
            "US"
        },
        {
            "zip",
            37.371991,
            -1.22026e+2,
            "",
            "SUNNYVALE",
            "CA",
            "94085",
            "US"
        }
    };
    volatile double zero = 0.0;

    /* Here we construct some JSON standards, from the JSON site. */

    /* Our "Video" datatype: */
    root = cJSON_CreateObject();
    cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble"));
    cJSON_AddItemToObject(root, "format", fmt = cJSON_CreateObject());
    cJSON_AddStringToObject(fmt, "type", "rect");
    cJSON_AddNumberToObject(fmt, "width", 1920);
    cJSON_AddNumberToObject(fmt, "height", 1080);
    cJSON_AddFalseToObject (fmt, "interlace");
    cJSON_AddNumberToObject(fmt, "frame rate", 24);

    /* Print to text */
    if (print_preallocated(root) != 0) {
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    cJSON_Delete(root);

    /* Our "days of the week" array: */
    root = cJSON_CreateStringArray(strings, 7);

    if (print_preallocated(root) != 0) {
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    cJSON_Delete(root);

    /* Our matrix: */
    root = cJSON_CreateArray();
    for (i = 0; i < 3; i++)
    {
        cJSON_AddItemToArray(root, cJSON_CreateIntArray(numbers[i], 3));
    }

    /* cJSON_ReplaceItemInArray(root, 1, cJSON_CreateString("Replacement")); */

    if (print_preallocated(root) != 0) {
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    cJSON_Delete(root);

    /* Our "gallery" item: */
    root = cJSON_CreateObject();
    cJSON_AddItemToObject(root, "Image", img = cJSON_CreateObject());
    cJSON_AddNumberToObject(img, "Width", 800);
    cJSON_AddNumberToObject(img, "Height", 600);
    cJSON_AddStringToObject(img, "Title", "View from 15th Floor");
    cJSON_AddItemToObject(img, "Thumbnail", thm = cJSON_CreateObject());
    cJSON_AddStringToObject(thm, "Url", "http:/*www.example.com/image/481989943");
    cJSON_AddNumberToObject(thm, "Height", 125);
    cJSON_AddStringToObject(thm, "Width", "100");
    cJSON_AddItemToObject(img, "IDs", cJSON_CreateIntArray(ids, 4));

    if (print_preallocated(root) != 0) {
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    cJSON_Delete(root);

    /* Our array of "records": */
    root = cJSON_CreateArray();
    for (i = 0; i < 2; i++)
    {
        cJSON_AddItemToArray(root, fld = cJSON_CreateObject());
        cJSON_AddStringToObject(fld, "precision", fields[i].precision);
        cJSON_AddNumberToObject(fld, "Latitude", fields[i].lat);
        cJSON_AddNumberToObject(fld, "Longitude", fields[i].lon);
        cJSON_AddStringToObject(fld, "Address", fields[i].address);
        cJSON_AddStringToObject(fld, "City", fields[i].city);
        cJSON_AddStringToObject(fld, "State", fields[i].state);
        cJSON_AddStringToObject(fld, "Zip", fields[i].zip);
        cJSON_AddStringToObject(fld, "Country", fields[i].country);
    }

    /* cJSON_ReplaceItemInObject(cJSON_GetArrayItem(root, 1), "City", cJSON_CreateIntArray(ids, 4)); */

    if (print_preallocated(root) != 0) {
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    cJSON_Delete(root);

    root = cJSON_CreateObject();
    cJSON_AddNumberToObject(root, "number", 1.0 / zero);

    if (print_preallocated(root) != 0) {
        cJSON_Delete(root);
        exit(EXIT_FAILURE);
    }
    cJSON_Delete(root);
}

int CJSON_CDECL cJSON_main(void)
{
    /* print the version */
    printf("Version: %s\n", cJSON_Version());

    /* Now some samplecode for building objects concisely: */
    create_objects();

    return 0;
}

2、main.c文件

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
  * All rights reserved.</center></h2>
  *
  * This software component is licensed by ST under BSD 3-Clause license,
  * the "License"; You may not use this file except in compliance with the
  * License. You may obtain a copy of the License at:
  *                        opensource.org/licenses/BSD-3-Clause
  *
  ******************************************************************************
  */
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "usart.h"
#include "gpio.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "stdio.h"
#include "cJSON.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
extern int CJSON_CDECL cJSON_main(void);
/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/

/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */

//__use_no_semihosting was requested, but _ttywrch was 
//void _ttywrch(int ch)
//{
//	ch = ch;
//}

#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */
  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
 
  return ch;
}
 
int fgetc(FILE * f)
{
  uint8_t ch = 0;
  HAL_UART_Receive(&huart1, (uint8_t *)&ch, 1, 0xffff);
  return ch;
}

//PM2.5接口 https://www.nowapi.com/api/weather.pm25
//使用天气预报接口测试程序  http://api.k780.com/?app=weather.pm25&weaid=1&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json
//json 格式预览网址 https://www.sojson.com/
int cJSON_Parse_Test(void) 
{

		const char *line = "{	\"success\": \"1\",													\
													\"result\": {																\
													\"weaid\": \"1\",														\
													\"cityno\": \"beijing\",										\
													\"citynm\": \"北京\",												\
													\"cityid\": \"101010100\",									\
													\"aqi\": \"96\",														\
													\"aqi_scope\": \"50-100\",									\
													\"aqi_levid\": 2,												    \
													\"aqi_levnm\": \"良\",											\
													\"aqi_remark\": \"可以正常进行室外活动\"		\
													}																						\
												}";
 
    cJSON *json;
    //char *out;
 
    json = cJSON_Parse( line );			//
 
    if(json == NULL)
    	printf("json fmt error:%s\r\n.", cJSON_GetErrorPtr());
    else
		{
    	cJSON *object = cJSON_GetObjectItem(json, "result");
 
    	cJSON *item = cJSON_GetObjectItem(object, "citynm");
    	printf("result->citynm: %s\r\n", item->valuestring);
 
    	item = cJSON_GetObjectItem(object, "cityid");
    	printf("result->cityid: %s\r\n", item->valuestring);
			
			item = cJSON_GetObjectItem(object, "aqi_levid");
    	printf("result->aqi_levid: %d\r\n", item->valueint);
			
			item = cJSON_GetObjectItem(object, "aqi_remark");
    	printf("result->aqi_remark: %s\r\n", item->valuestring);
      
    	cJSON_Delete(json);	
		}
	
	return 0;
}

/*	生成字符串	*/
void cJSON_Creat(void)
{
		cJSON* cjson_test = NULL;
    cJSON* cityInfo = NULL;
    cJSON* cjson_week = NULL;
    char* str = NULL;
 
    /* 创建一个JSON数据对象(链表头结点) */
    cjson_test = cJSON_CreateObject();
 
    /* 添加一条字符串类型的JSON数据(添加一个链表节点) */
    cJSON_AddStringToObject(cjson_test, "time", "2021-04-16 12:37:21"); //系统更新时间
 
    /* 添加一条整数类型的JSON数据(添加一个链表节点) */
    cJSON_AddNumberToObject(cjson_test, "date", 20210416);					//当前天气的当天日期
 
    /* 添加一条浮点类型的JSON数据(添加一个链表节点) */
    cJSON_AddNumberToObject(cjson_test, "pm25", 15.0);							//pm2.5
	
		/* 添加一条字符串类型的JSON数据(添加一个链表节点) */
    cJSON_AddStringToObject(cjson_test, "quality", "优"); 					//空气质量
 
    /* 添加一个嵌套的JSON数据(添加一个链表节点) */
    cityInfo = cJSON_CreateObject();
    cJSON_AddStringToObject(cityInfo, "country", "China");
    cJSON_AddStringToObject(cityInfo, "city", "Shenzhen");
		cJSON_AddNumberToObject(cityInfo, "cityid", 440303);
		cJSON_AddStringToObject(cityInfo, "updateTime", "12:32");
    cJSON_AddItemToObject(cjson_test, "cityInfo", cityInfo);
 
    /* 添加一个数组类型的JSON数据(添加一个链表节点) */
    cjson_week = cJSON_CreateArray();
		cJSON_AddItemToArray(cjson_week, cJSON_CreateString( "星期日" ));
    cJSON_AddItemToArray(cjson_week, cJSON_CreateString( "星期一" ));
    cJSON_AddItemToArray(cjson_week, cJSON_CreateString( "星期二" ));
    cJSON_AddItemToArray(cjson_week, cJSON_CreateString( "星期三" ));
		cJSON_AddItemToArray(cjson_week, cJSON_CreateString( "星期四" ));
    cJSON_AddItemToArray(cjson_week, cJSON_CreateString( "星期五" ));
    cJSON_AddItemToArray(cjson_week, cJSON_CreateString( "星期六" ));
    cJSON_AddItemToObject(cjson_test, "week", cjson_week);
 
    /* 添加一个值为 False 的布尔类型的JSON数据(添加一个链表节点) */
    cJSON_AddFalseToObject(cjson_test, "message");
 
    /* 打印JSON对象(整条链表)的所有数据 */
    str = cJSON_Print(cjson_test);
    printf("%s\n", str);

}

/* USER CODE END 0 */

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
	cJSON_main();
	printf("\r\n");
	cJSON_Parse_Test();
	printf("\r\n");
	cJSON_Creat();
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
		HAL_Delay(1000);
		HAL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }
  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

/* USER CODE END 4 */

/**
  * @brief  This function is executed in case of error occurrence.
  * @retval None
  */
void Error_Handler(void)
{
  /* USER CODE BEGIN Error_Handler_Debug */
  /* User can add his own implementation to report the HAL error return state */
  __disable_irq();
  while (1)
  {
  }
  /* USER CODE END Error_Handler_Debug */
}

#ifdef  USE_FULL_ASSERT
/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t *file, uint32_t line)
{
  /* USER CODE BEGIN 6 */
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  /* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

在线解析JSON格式数据工具

https://www.bejson.com/
https://www.sojson.com/
 

 

四、运行结果

参考文章:

1、https://blog.csdn.net/weixin_45488643/article/details/107148438?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_v2~rank_aggregation-9-107148438.pc_agg_rank_aggregation&utm_term=CJSON%E5%BA%93%E7%A7%BB%E6%A4%8D&spm=1000.2123.3001.4430

2、https://blog.csdn.net/penglijiang/article/details/52831080?utm_medium=distribute.pc_aggpage_search_result.none-task-blog-2~aggregatepage~first_rank_v2~rank_aggregation-4-52831080.pc_agg_rank_aggregation&utm_term=cjson+stm32%E7%A7%BB%E6%A4%8D&spm=1000.2123.3001.4430

拓展文章:

1、https://blog.csdn.net/zhengnianli/article/details/101178024?utm_medium=distribute.pc_relevant_download.none-task-blog-2~default~blogcommendfrombaidu~default-2.nonecase&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-2~default~blogcommendfrombaidu~default-2.nonecas

2、https://blog.csdn.net/qq_42263055/article/details/114852446?utm_medium=distribute.pc_relevant.none-task-blog-baidujs_baidulandingword-9&spm=1001.2101.3001.4242

 

传送门->代码

五、总结

      好了,就介绍到此,有了这个神器,解决JSON格式的数据就变得简单很多了,特别适合物联网终端设备开发引用,上报数据到后台非常方便。

 

 

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

STM32HAL 移植 cJSON开源库 (裸机开发神器) 的相关文章

  • 基于STM32HAL库编写状态机模式

    概述 本篇文章介绍如何使用STM32HAL库 以马达转动的状态示例 来说明 项目中使用的状态模式 参考该文章链接 比较懒 基本都是照搬框架 这种写法确实在项目后续新增功能时 方便不少 还是值得学习 这样的思路 加油 技术同仁们 硬件 STM
  • STM32H7串口查询方式接收串口接收溢出导致死机问题

    串口溢出后 因为接收移位寄存器不会把接收到的数据放到接收寄存器中 则RXNE RXFNE不会再置位 不能再接收 表现为串口死机 STATIC INLINE uint32 t LL USART IsActiveFlag RXNE RXFNE
  • STM32读写内部Flash(介绍+附代码)

    概述 内部Flash读写详解 一 介绍 首先我们需要了解一个内存映射 stm32的flash地址起始于0x0800 0000 结束地址是0x0800 0000加上芯片实际的flash大小 不同的芯片flash大小不同 RAM起始地址是0x2
  • STM32HAL库-移植Unity针对微控制器编写测试框架

    概述 本篇文章介绍如何使用STM32HAL库 移植Unity 是一个为C语言构建的单元测试框架 侧重于使用嵌入式工具链 GitHub https github com ThrowTheSwitch Unity 硬件 STM32F103CBT
  • STM32 基于Keil IDE 开发引用 Astyle 第三方工具格式化插件

    目录 概述 一 使用方法 二 STM32CubeMx配置 三 Examples 四 运行结果 五 总结 概述 本篇文章介绍如何使用Keil IDE 引用Astyle 第三方工具格式化代码 官网 http astyle sourceforge
  • STM32学习之温湿度检测——DHT11

    一准备材料 1 参考资料 STM32不完全手册 库函数版本 STM32F103xCDE DS CH V5 pdf STM32中文参考手册 V10 pdf DHT11 DHT11 下载链接 https pdf1 alldatasheetcn
  • STM32-TIM4-定时器中断

    include project h include timer h TIM4 Init 2000 72 定时2ms 定时器中断的定时时间设定 定时器只需要配置时钟 TIM和NVIC即可 void TIM4 Init u16 period u
  • STM32L4-RS485+DMA中断通信实验+字节丢失处理[寄存器版]

    基本设置 MCU采用 STM32L431RCT6 485芯片采用 ADM3485 采用串口经由RS485 使用DMA向串口调试助手传送数据 相关配置与前文基本相同 STM32L4 双路RS485自收发通信实验 寄存器版 staypt的博客
  • 理解stm32当中旋转编码器左转或者右转的联系和区别

    在这里判断左转右转的代码为 判断左转时 K2下降沿 如果这个时候K3为0 那么就可以判断是左转 所以代码为 接下来是中断的中断函数 void EXTI0 IRQHandler void 检查一下中断标志位 if EXTI GetITStat
  • OLED显示小数

    OLED显示小数并不是很难的 在通用的OLED库中是没有显示小数的 需要自己去写 写的方法大致是这样的 写出0到9的ACSLL值 只需要将小数点后面的位数 一位一位的写数字对应的ACSLL值即可 其中小数点 也是写同样对应的ACSLL值 只
  • STM32HAL库-移植mbedtls开源库示例(二)

    概述 本篇文章介绍如何使用STM32HAL库 这篇文章只要是讲如何使用mbedtls开源库 实现 1 base64编码 2 AES加解密示例 怎么样移植mbedtls开源库 请阅读我写的一篇文章 STM32HAL库 移植mbedtls开源库
  • STM32-定时器系列(一)基本定时器

    相信学过51单片机的小伙伴们使用过定时刷新数码管吧 那也一定想过 我们在STM32中也想要实现定时刷新数码管 这该怎么实现呢 下面小编就带大家走进STM32的定时器模块吧 一 什么是定时器 定时器是一种计时的工具 它具有延时 频率测量 PW
  • 【STM32】

    失败了也挺可爱 成功了就超帅 文章目录 前言 1 JTAG SWD引脚 2 禁用JTAG功能 2 1 标准库 2 2 HAL库 3 禁用SWD JTAG功能 3 1 标准库 3 2 HAL库 总结 前言 最近在画板子耍 我LED灯选用的 P
  • MCU学习笔记_PWR电源管理系统

    MCU学习笔记 电源管理系统 1 STM32电源监控器概述 2 STM32电源 3 HAL库配置PVD实例 1 STM32电源监控器概述 原因 保持系统正常运行 实现特定条件下的低功耗模式 上电复位 POR 掉电复位 PDR 上电复位是指上
  • STM32的PWM相关函数TIM_SetCompare1的一定理解

    void TIM SetCompare1 TIM TypeDef TIMx uint16 t Compare1 Check the parameters assert param IS TIM LIST8 PERIPH TIMx Set t
  • #STM32 GPIO编程详解

    硬件环境 stm32f407zet6 软件环境 mdk5 1 GPIO概述 GPIO 翻译为通用输入输出 也就是软件可编程引脚 也就是MCU通过控制GPIO来完成一系列的功能 GPIO属于引脚 但引脚还包含电源 晶振 下载 boot 复位等
  • STM32 ADC 多通道16路电压采集

    下面介绍一种利用STM32单片机制作的16路多通道ADC采集电路图和源程序 采用USB接口与电脑连接 实则USB转串口方式 所以上位机可以用串口作为接口 电路图中利用LM324作为电压跟随器 起到保护单片机引脚的作用 直接在电脑USB取点
  • 复用推挽输出与推挽输出区别

    GPIO InitStructure GPIO Mode GPIO Mode AF PP 复用推挽输出 GPIO SetBits GPIOE GPIO Pin 5 如果LED1是上拉的话 这时候它被点亮了 GPIO Mode AF PP g
  • USART串口协议和USART串口外设(USART串口发送&串口发送和接收)

    1 通信接口 A 基本概念 通信的目的 将一个设备的数据传送到另一个设备 扩展硬件系统 通信协议 制定通信的规则 通信双方按照协议规则进行数据收发 异步 需要双方约定一个频率 B 数据通信方式 按数据通信方式分类 可分为串行通信和并行通信两
  • STM32HAL 移植MultiButton小巧简单事件驱动型按键驱动框架(裸机版本)

    目录 概述 一 使用方法 特性 按键事件 Examples 二 STM32CubeMx配置 三 Examples 四 运行结果 五 总结 概述 本篇文章介绍如何使用STM32移植 MultiButton开源框架 引用官网简述如下 Multi

随机推荐

  • Pandas基础操作

    Pandas基础 文章目录 Pandas基础 一 Series 二 DataFrame 三 索引值 四 索引和选取 loc和iloc函数讲解 五 行和列的操作 map apply applymap函数讲解 Pandas的函数应用 层级索引
  • 数据结构与算法之快速排序

    package com yg sort author GeQiLin date 2020 2 26 21 00 import java util Arrays public class QuickSort private static in
  • [SWPUCTF 2021 新生赛]easyupload2.0

    打开以后是一个文件上传的界面 然后用burp抓包看一下 传入一个php文件 发现php是不行滴 然后想到用phtml改一下后缀 看是否可以略过 然后发现掠过了 爆出来了路径 上传成功 直接用蚁建 lianjie 链接成功 然后目录寻找fla
  • pthread_mutex_t 和 pthread_cond_t 配合使用的简要分析

    pthread mutex t 和 pthread cond t 配合使用的简要分析 1 原理 假设有两个线程同时访问一个全局变量 n 这个全局变量的初始值等于0 Int n 0 消费者线程 A 进入临界区 访问 n A 必须等到 n 大于
  • idea~不定时更新

    idea 不定时更新 类结构图 全局搜索和替换 修改鼠标停留 并显示api描述 开启idea下方边框 https www jetbrains com help idea 2019 2 using code editor html utm s
  • python运算符讲解

    作者 小刘在这里 每天分享云计算网络运维课堂笔记 疫情之下 你我素未谋面 但你一定要平平安安 一 起努力 共赴美好人生 夕阳下 是最美的 绽放 愿所有的美好 再疫情结束后如约而至 目录 运算符 python运算符 一 运算符类型 二 实际应
  • 【超详细】gitee+picgo个人图床搭建+插件安装bug处理

    超详细 gitee picgo个人图床搭建 各种插件安装bug处理 你好我是久远 最近在搭个人静态网页 到了最后一步了 传了几篇文章上去 结果文章传上去 了 图片全都失效了 没有办法 用现成的图床吧 担心哪天网站不稳定 图片全炸掉 所以最后
  • Android10.0 Binder通信原理(九)-AIDL Binder示例

    Android取经之路 的源码都基于Android Q 10 0 进行分析 Android取经之路 系列文章 系统启动篇 Android系统架构Android是怎么启动的Android 10 0系统启动之init进程Android10 0系
  • 【文献调研】慢病患者就医行为预测:就医选择行为有哪些?预测什么?如何预测?慢病患者?

    文章目录 0 吾日三问 1 基于医保数据的就医行为预测及推荐模型的研究 1 1 摘要 1 2 基于张量CP分解的就医行为分组预测模型 1 3 总结 2 居民就医行为主要影响因素的调查研究 2 1 摘要 2 2 相关内容 3 分级诊疗背景下多
  • 2020-11-22

    实验三 XSS和SQL注入 实验目的 了解什么是XSS 了解XSS攻击实施 理解防御XSS攻击的方法 了解SQL注入的基本原理 掌握PHP脚本访问MySQL数据库的基本方法 掌握程序设计中避免出现SQL注入漏洞的基本方法 掌握网站配置 系统
  • Windows批处理(cmd/bat)常用命令小结

    一 前言 批处理文件 batch file 包含一系列 DOS命令 通常用于自动执行重复性任务 用户只需双击批处理文件便可执行任务 而无需重复输入相同指令 编写批处理文件非常简单 但难点在于确保一切按顺序执行 编写严谨的批处理文件可以极大程
  • Josephus问题,数组和链表(C++实现)

    文章目录 问题 需求分析 ADT定义 关键思路 问题 设有n个人围坐在圆桌周围 现从第s个人开始报数 数到第m的人出列 然后从出列的下一个人重新开始报数 数到第m的人又出列 如此反复直到所有的人全部出列为止 需求分析 n个人坐满一张圆桌 为
  • verilog赋多位值_Verilog重点解析(2)(赋值)

    源自 微信公众号 数字芯片实验室 1 连续赋值和过程赋值之间有什么区别 2 initial和always中的赋值有什么区别 initial和always中的赋值都是过程赋值 3 阻塞和非阻塞赋值之间有什么区别 阻塞和非阻塞赋值都是过程赋值
  • Zabbix监控Windows客户端设置

    Zabbix监控Windows客户端设置 一 Windows被控端安装 1 Windows代理下载 2 安装代理 二 检查被控端状态 1 查看端口 2 检查代理服务 3 服务端查看获取被控信息 三 Web端添加被控主机 1 添加主机信息 2
  • [1078]Win10配置Java环境变量

    文章目录 1 下载安装JDK 2 配置环境变量 2 1 找到jdk的安装目录 2 2 添加环境变量 2 3 测试 1 下载安装JDK 下载地址 安装就不赘述了 2 配置环境变量 2 1 找到jdk的安装目录 win e打开资源管理器 找到j
  • 手势控制arduino-wifi小车(含代码)

    手势控制器 小车完成图 贴代码 手势控制器代码 include
  • 使用VHDL语言控制相机

    将CMOS相机与ZYNQ 7000系列FPGA SoC连接 并将实时视频输入输出到VGA屏幕 硬件 软件 概述 在这个项目中 我们将从头开始构建一个FPGA映像平台 目的是将VGA分辨率CMOS相机与MiniZed Development板
  • 计算机超频的好处与坏处,CPU超频有什么坏处,到底会不会有副作用?

    超频是指提高计算机某一部件工作频率而使之工作在非标准频率下的行为及相关行动都应该称之为超频 其中包括CPU超频 主板超频 内存超频 显示卡超频和硬盘超频等等很多部分 一方面 超频可以使系统性能提升 并且提升产品的实用价值 但是对于大多数人仍
  • 图文详解微信小程序如何实现微信授权登录(Java后台)上

    详解微信小程序如何实现微信授权登录 Java后台 springboot框架 附关键源码 jar包依赖
  • STM32HAL 移植 cJSON开源库 (裸机开发神器)

    目录 概述 一 使用方法 二 STM32CubeMx配置 三 Examples 四 运行结果 五 总结 概述 本篇文章介绍如何使用STM32引用 cJSON开源库 JSON格式在互联网数据交互时常用的一个格式 现嵌入式物联网方向 经常使用到