资源简介
基于官方的例程,移植到STM32F103,采用查询方式,间隔500ms读一次,温度和湿度轮流读取,注意SDA连接IO口配置为OD开漏输出
代码片段和文件信息
#define _C_SHT20Drv
#include “stm32f1xx_hal.h“
#include “DataDef.h“
#include “SHT20Drv.h“
//==============================================================================
void I2c_StartCondition ()
//==============================================================================
{
/*
SDA=HIGH;
SCL=HIGH;
SDA=LOW;
DelayMicroSeconds(10); // hold time start condition (t_HD;STA)
SCL=LOW;
DelayMicroSeconds(10);
*/
SHT20_SDA(1);
SHT20_SCL(1);
SHT20_SDA(0);
DelayMicroSeconds(10);
SHT20_SCL(0);
DelayMicroSeconds(10);
}
//==============================================================================
void I2c_StopCondition ()
//==============================================================================
{
/*
SDA=LOW;
SCL=LOW;
SCL=HIGH;
DelayMicroSeconds(10); // set-up time stop condition (t_SU;STO)
SDA=HIGH;
DelayMicroSeconds(10);
*/
SHT20_SDA(0);
SHT20_SCL(0);
SHT20_SCL(1);
DelayMicroSeconds(10);
SHT20_SDA(1);
DelayMicroSeconds(10);
}
//==============================================================================
u8 I2c_WriteByte (u8 txByte)
//==============================================================================
{
u8 maskerror=0;
for (mask=0x80; mask>0; mask>>=1) //shift bit for masking (8 times)
{ if ((mask & txByte) == 0) SHT20_SDA(0);//SDA=LOW;//masking txByte write bit to SDA-Line
else SHT20_SDA(1);//SDA=HIGH;
DelayMicroSeconds(1); //data set-up time (t_SU;DAT)
SHT20_SCL(1);//SCL=HIGH; //generate clock pulse on SCL
DelayMicroSeconds(5); //SCL high time (t_HIGH)
SHT20_SCL(0);//SCL=LOW;
DelayMicroSeconds(1); //data hold time(t_HD;DAT)
}
SHT20_SDA(1);//SDA=HIGH; //release SDA-line
SHT20_SCL(1);//SCL=HIGH; //clk #9 for ack
DelayMicroSeconds(1); //data set-up time (t_SU;DAT)
//if(SDA_CONF==HIGH) error=ACK_ERROR; //check ack from i2c slave
if(SHT20_SDA_Read) error= ACK_ERROR;
SHT20_SCL(0);//SCL=LOW;
DelayMicroSeconds(20); //wait time to see byte package on scope
return error; //return error code
}
//==============================================================================
u8 I2c_ReadByte (etI2cAck ack)
//==============================================================================
{
u8 maskrxByte=0;
SHT20_SDA(1);//SDA=HIGH; //release SDA-line
for (mask=0x80; mask>0; mask>>=1) //shift bit for masking (8 times)
{ SHT20_SCL(1);//SCL=HIGH; //start clock on SCL-line
DelayMicroSeconds(1); //data set-up time (t_SU;DAT)
DelayMicroSeconds(3); //SCL high time (t_HIGH)
//if (SDA_CONF==1) rxByte=(rxByte | mask); //read bit
if (SHT20_SDA_Read) rxByte=(rxByte | mask);
SHT20_SCL(0);//SCL=LOW;
DelayM
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10445 2016-07-20 11:57 SHT20Drv.c
文件 2847 2016-07-20 12:31 SHT20Drv.h
相关资源
- stm32单片机IIC通讯采集sht20温湿度传感
- STM32-SHT20温湿度传感器驱动程序
- STM32F103 SHT20
- sht20 程序
- 基于stm32单片机多功能计步手环
- sht20 sht30 温湿度传感器 stm8-stm32
- SHT20 STM32F130ZET6 HAL 库例程
- 基于STM32,hal库,使用CubeMX进行开发的
- MSP430F149的无线温湿度环境实时监测系
- SHT20温湿度传感器程序gpio模拟I2C+中文
- SHT20温湿度传感器英文数据手册。内含
- SHT20温湿度传感器
- sht20驱动程序51
- SHT20测试程序
- SHT20温湿度传感器中文技术手册
- SHT21_SHT20温湿度传感器,STM32驱动
- SHT20原理图和封装
- SHT10 SHT20 SHT21温湿度单片机89C52 1602显
- STM32F030+SHT20温湿度模块电路图
评论
共有 条评论