STM32 temperature and humidity sensor drive HTU21D

https://blog.csdn.net/wwt18811707971/article/details/80034047
1. Introduction

French Humirel new generation HTU21D temperature and humidity sensor to establish a new standard size and intelligence: Embedded in a double Flat No leads adapted DFN package reflow, 3x3mm bottom surface, the height of 1.1mm. Calibrated, digital signals, a standard I2C formats .

Write pictures described here

HTU21D temperature and humidity sensors provide an accurate and reliable measurement of temperature and humidity data for OEM applications. Through a micro-controller
interface and the Modular is connected to a temperature and humidity digital output. HTU21D resolution may be performed by changing the input command (8 / 12bit 12 / 14bit for the RH / T), the sensor can detect the low battery, and a checksum helps to improve reliability of communication.


2. Specifications

Write pictures described here

25 degrees Celsius, the electrical characteristics of the power supply 3.3V follows:

Write pictures described here

Download the data sheet are as follows:

Temperature and humidity sensitive sensor chip HTU21D

Note printed board design:

If the SCL and SDA signal parallel and in close proximity, it may result in cross talk and loss of communication. The solution is placed between two VDD or the GND signal lines, the signal lines are separated, or shielded. In addition, reducing the frequency of SCL may improve the integrity of signal transmission. Be added a 100nF decoupling capacitor between the power supply pin (VDD, GND), for filtering. This should be close to the sensor capacitance.

Write pictures described here

Pin definition:

Write pictures described here

This experiment is finished HTU21D module is directly connected to the STM32 boards.

Pin Explanation
Power supply pin (VDD, GND) HTU21 power range 1.8VDC - 3.6VDC, recommended voltage of 3.0V. A decoupling capacitor to be connected 0.1uF between power (VDD) and ground (VSS), and the capacitance of the sensor position as close as possible.
Serial clock input (SCK) SCK is used to synchronize the communication between the microprocessor and HTU21. Since the interface consists of fully static logic, SCK minimum frequency which is not present.
串行数据 (DATA) DATA 引脚为三态结构,用于读取传感器数据。当向传感器发送命令时, DATA 在 SCK 上升沿有效且在 SCK 高电平时必须保持稳定。 DATA 在 SCK 下降沿之后改变。当从传感器读取数据时, DATA 在 SCK 变低以后有效,且维持到下一个 SCK 的下降沿。为避免信号冲突,微处理器应驱动 DATA 在低电平。需要一个外部的上拉电阻(例如: 10kΩ)将信号提拉至高电平。上拉电阻通常已包含在微处理器的 I/O 电路中。

3.通讯过程

Htu21d遵循标准的 IIC 进行通信,关于 IIC 的介绍请看—>IIC专题(一)——基础知识准备。本文设计也多参考此篇文章–>STM32F10x_模拟I2C读写EEPROM

3.1 IIC启动信号

启动传输,发送一位数据时,包括 DATA 线在 SCK 线高电平期间一个向低电平的跳变。
Write pictures described here

Write pictures described here

3.2 IIC停止信号

终止传输,停止发送数据时,包括 DATA 线在 SCK 线高电平期间一个向高电平的跳变。

Write pictures described here

Write pictures described here

3.2 IIC数据传输

SCL时钟电平为低, 可以改换SDA数据线的电平,在SCL上升沿的过程将SDA数据发送出去。SCL为高电平时,SDA上的数据保持稳定。

Write pictures described here

I2C 是以字节(8位)的方式进行传输,总线上每传输完1字节之后会有一个应答信号,应答信号总是由接收方来产生。通信过程的时钟由主器件(主机)提供。

IIC 写一字节:

Write pictures described here

Write pictures described here

数据发送结束,进行应答操作。
0:表示从机应答,可以继续下一步操作;
1:表示从机非应答,不能进行下一步操作。

IIC读一字节:

IIC读取操作类似于发送,只是传输数据方向相反。

Write pictures described here

Write pictures described here

3.3 IIC应答信号处理

等待应答:

Write pictures described here

产生应答:

Write pictures described here

产生非应答:

Write pictures described here


4.HTU21D数据测量

测量命令如下表:

Write pictures described here

In this paper, non-retentive host:
// non-host mode

#define HTU_TEMP    0xf3
#define HTU_HUMI    0Xf5
  
  
  • 1
  • 2

In the master mode, MCU needs to query the status of the sensor. This procedure by sending a transmission timing to start, immediately followed by the first byte shown in FIG I2C (1000'0001) to complete. If the internal processing is completed, the microcontroller queries acknowledgment signal from a sensor, data can be read by the MCU. If the measurement processing is not completed, the sensor no acknowledgment (ACK) bit output, and the transmission timing must be sent again started.

Write pictures described here

Sensor Initialization:

Write pictures described here

Read sensor data and conversion:

Default resolution for the sensor is arranged inside the relative humidity and a temperature of 12 14 . Output data SDA is converted to two byte packet, the high byte MSB first (left-justified). Each byte is followed by an acknowledge bit. The two status bits, before performing the two physical computing i.e. after the LSB must be set to '0'.

FIG conversion is calculated as follows:

Write pictures described here

Source code to achieve:

Write pictures described here

Display method:

In this study, a serial printer and TFTLCD display, serial printer helps debugging.

Write pictures described here

For the measured value of how to display float directly to the LCD, the code briefly describes two ways:
the LCD Display 1: sprintf function to print the test results array, converted to a character string display (LCD_ShowString).
LCD Display Mode 2: The value obtained is directly split into integer and fractional liquid crystal display (LCD_ShowxNum).
Direct liquid crystal display driving reference punctual atoms.


Source code download, go to -> I2C_Software_Htu21d

Inadequate please share with everyone.


reference:

1. STM32F10x_ simulation I2C read the EEPROM
2. punctual atoms library function

Guess you like

Origin blog.csdn.net/baidu_37503452/article/details/88980209