当前位置:网站首页>Stm32mp1 cortex M4 Development Part 9: expansion board air temperature and humidity sensor control
Stm32mp1 cortex M4 Development Part 9: expansion board air temperature and humidity sensor control
2022-06-21 09:13:00 【Huaqing vision it open laboratory】
Write it at the front :
This article is 《ARM Cortex-M4 Bare metal development 》 One in a series ,, The total of the series 14 piece . The development platform used by the author is Huaqing vision FS-MP1A Development board (STM32MP157 Development board ),Cortex-M4 In addition to talking about bare metal development M4 Outside bare metal development , Will also explain through M4 Control various sensor actuator modules on the resource expansion board ( Including air temperature and humidity sensor 、LED The lamp 、 Nixie tube 、 Buzzer 、 Vibration motor 、 Key interrupt 、 Fans, etc ), This is M4 An article in the control resource expansion board .
The resource expansion board is FS-MP1A Expansion module of development board , Mainly consists of 10 More than one kind of auxiliary mainstream sensor 、 Executive device 、 Bus control device , Very convenient for project expansion . It can expand and develop smart families 、 Intelligent medical treatment 、 Intelligent security 、 Industrial control 、 Image recognition 、 Environmental detection, etc 10 About comprehensive projects , Huaqing vision development board will also provide supporting documentation for all projects 、 Experiment source code 、 Applications and other information .
in the light of FS-MP1A Development board , except Cortex-M4 Bare metal development , There are also many other series of tutorials , Include Cortex-A7 Development of article 、FreeRTOS piece 、Linux Foundation and application development 、Linux System transplantation 、Linux Driving development 、 Hardware design 、 Artificial intelligence machine vision 、Qt Application programming 、Qt Comprehensive project practice, etc . Welcome to your attention , more stm32mp157 Develop tutorials and videos , Technical exchange can be added Q Group 459754978, Thank you for attention .
FS-MP1A Development board details : TaoBao - Amoy ! I like
Catalog
1. Introduction to resource expansion board
1.2 Resource expansion board developable project
2. Expansion board air temperature and humidity sensor control
1. Introduction to resource expansion board
1.1 Hardware introduction

1.2 Resource expansion board developable project

2. Expansion board air temperature and humidity sensor control
2.1 Experimental principle
Open the schematic diagram of the expansion board. By comparing the expansion board, you can see that the expansion board has 1 A temperature and humidity sensor SI7006, Here's the picture :

It can be seen from the above figure that I2C Bus and SI7006 signal communication .

Comparison diagram of interface between expansion board and backplane
Check the schematic diagram to see the data line I2C1_SDA、I2C1_SCL and I2C_INT1 The corresponding relationship of pins is as follows :

see SI7006 The chip manual confirms that the seven bit slave address of the device is :0x40

2.2 The experiment purpose
Understand the working principle of temperature and humidity sensor
Study I2C How to use the protocol , Master how to use STM32MP157A Chip control SI7006 Temperature and humidity sensor
2.3 Experimental environment
FS-MP1A Development platform
ST-Link Emulator
STM32CubeIDE Development software
PC machine XP、Window7/10 (32/64bit)
2.4 The experimental steps
open STM32CubeIDE, To configure CubeMX.
First, configure the system clock and serial port printing according to the previous chapters , Then on PF14、PF15 The pins are respectively configured as I2C1_SCL And I2C1_SDA, Switch to I2C1 label , Check to “M4”, Choose “I2C”, As shown in the figure below .


The above is the configuration process of new projects , May refer to 12.3.2 Chapter to import the existing project , Project storage path 【 Huaqing vision -FS-MP1A Development of information \02- Program source code \ARM Architecture and interface technology \Cortex-M4\8_EX_I2C_TEM】
Code implementation
Due to the use of hardware I2C, You don't need to write your own program to realize I2C sequential , All we need to do is call HAL Hardware provided I2C Operation function . among , call “HAL_I2C_Master_Transmit” Function to send data , call “HAL_I2C_Master_Receive” Function to receive data , establish driver_si_7006.c The document realizes the control of the sensor . The code is as follows
uint8_t SI7006_Init(void)
{
HAL_I2C_Init(&hi2c1);
SI7006_WriteByte(SI7006CMD_RESET);
HAL_Delay(50);
return 0;
}
void SI7006_ReadDataTest(void)
{
uint16_t hum = 0, tem = 0,tem_1 = 0,tem_2 = 0;
hum = SI7006_Read_Data(SI7006CMD_RH_HOLD);
tem = SI7006_Read_Data(SI7006CMD_TEMP_HOLD);
tem = ((17572*tem)/65536 - 4685);
hum = (125*hum/65536 - 6);
tem_1 = tem/100;
tem_2 = tem%100;
printf("\r hum = %d%% \n", hum);
printf("\r tem = %d.%d\n", tem_1,tem_2);
}
uint8_t SI7006_WriteByte(uint8_t reg)
{
uint8_t write_data = reg;
if(HAL_I2C_Master_Transmit(&hi2c1, SI7006_ADDR | SI7006_W , (uint8_t*)&write_data, 1, 300) != HAL_OK)
{
Error_Handler();
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY);
return 0;
}
uint16_t SI7006_ReadWord(uint8_t reg)
{
uint16_t read_data = 0;
if(HAL_I2C_Master_Transmit(&hi2c1, SI7006_ADDR | SI7006_W , (uint8_t*)®, 1, 300) != HAL_OK) // dispatch orders
{
Error_Handler();
}
while (HAL_I2C_GetState(&hi2c1) != HAL_I2C_STATE_READY);
if(HAL_I2C_Master_Receive(&hi2c1, SI7006_ADDR | SI7006_R , (uint8_t*)&read_data, 2, 300) != HAL_OK) // receive word data
{
Error_Handler();
}
return read_data;
}
uint16_t SI7006_Read_Data(uint16_t cmd)
{
uint16_t data = 0,data_low = 0,data_high = 0;
data = SI7006_ReadWord(cmd); // Collection temperature and humidity
data_low = (data & 0xff); // High and low byte conversion
data_high = (data >> 8) & 0xff;
data = (data_low << 8) + data_high;
return data;
}
among , Use “HAL_I2C_Master_Receive” receive 16 Bit data time , Due to the high byte data received first , Then low byte data , therefore , It is necessary to exchange high and low bytes when using data .
In the main function , Initialize separately first I2C And SI7006, Call again “SI7006_ReadDataTest” Function can collect the value of temperature and humidity sensor .
Hardware platform : Huaqing vision FS-MP1A Development board (STM32MP157)
Download some development tutorials : Add QQ Group 459754978, There are in the group file .
Watch some video courses : Personal space of Huaqing vision R & D Center _ Bili, Bili _Bilibili
Taobao purchase link : Huaqing vision stm32mp157 linux Development board stm32 Single chip microcomputer arm Develop embedded learning board
Mobile Taobao sharing code : Copy the text of this line and open hand Amoy ₤T4FPXn3YYJ2₤
边栏推荐
- The spring recruitment is also terrible. Ali asked at the beginning of the interview: how to design a high concurrency system? I just split
- adb使用技巧和usb通信原理
- [early knowledge of activities] list of recent activities of livevideostack
- The most authoritative Lei niukesi in history --- embedded Ai Road line [yyds]
- 微信小程序
- Nodejs post request JSON type and form type
- Merge sort of sorting
- Detailed analysis of ThreadPoolExecutor source code of thread pool
- Source insight shortcut key cross reference
- The R language plot function visualizes multiple lines in the same plot, and uses the BMP function to save the visualization image to the BMP format file in the specified directory
猜你喜欢

【活动早知道】LiveVideoStack近期活动一览

优化食品生产行业库存管理的6种方法

How to connect the Internet - FTTH

微信小程序

Detailed analysis of ThreadPoolExecutor source code of thread pool

Lei niukesi --- basis of embedded AI
![[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface](/img/04/a7455760caa4fc0480a034de1e24b8.png)
[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface

STL tutorial 3- type conversion static_ cast、dynamic_ cast、const_ cast、reinterpret_ Cast method

PingCAP 入选 2022 Gartner 云数据库“客户之声”,获评“卓越表现者”最高分

Storage of floating point numbers in C language in memory
随机推荐
如何使用 adb shell 查询进程流量情况
High precision calculation
Summary of problems and errors encountered in tidb4.0.0 (tiup deployment)
SQL to check the disk usage of the database / table, kill the process and terminate the connection in tidb
It is said that this year gold three silver four has become gold one silver two.
PingCAP 入选 2022 Gartner 云数据库“客户之声”,获评“卓越表现者”最高分
优化食品生产行业库存管理的6种方法
【JUC系列】Executor框架之CompletionService
Leetcode: print the common part of two ordered linked lists
Unity写多线程注意事项
[vs], [usage problem], [solution] when VS2010 is opened, it stays in the startup interface
《网络是怎么样连接的》读书笔记 - FTTH
Gql+nodejs+mysql database
Unity中.Meta文件作用详解
微信小程序
R language sets na Rm=true parameter, deleting missing values in calculation and analysis to obtain valid calculation results (excluding missing values from analyses)
应用配置管理,基础原理分析
Unity write multithreading considerations
【实战】STM32MP157开发教程之FreeRTOS系统篇3:FreeRTOS 计数型信号量
leetcode:19. 删除链表的倒数第 N 个结点