当前位置:网站首页>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.1 Hardware introduction

1.2 Resource expansion board developable project

2. Expansion board air temperature and humidity sensor control

2.1 Experimental principle

2.2 The experiment purpose

2.3 Experimental environment

2.4 The experimental steps


1. Introduction to resource expansion board


1.1 Hardware introduction

 Insert picture description here

 


1.2 Resource expansion board developable project

 Insert picture description here

 

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*)&reg, 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₤

原网站

版权声明
本文为[Huaqing vision it open laboratory]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206210908576910.html