SHT2x系列数字温湿度传感器
SHT2x系列数字温湿度传感器
SHT2x系列数字温湿度传感器
SHT2x系列和SHT1x系列相比电压范围缩小了(2.1~3.6V),同时功率明显比之前的系列要小。其它参数基本差不多。最大的区别就是传输模式了。比之前的要完善很多,支持标准的I2C了,调试起来更加顺手了。
<此处有待补充>
本着能不动手就少动手的原则,我在调试的时候用的是一个现成的程序,它是用IO口模拟I2C的。 代码如下:
前一个是头文件,后一个是函数实现。
1 #ifndef I2C_HAL_H 2 #define I2C_HAL_H 3 //============================================================================== 4 // S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland 5 //============================================================================== 6 // Project : SHT2x Sample Code (V1.0) 7 // File : I2C_HAL.h 8 // Author : MST 9 // Controller: NEC V850/SG3 (uPD70F3740) 10 // Compiler : IAR compiler for V850 (3.50A) 11 // Brief : I2C Hardware abstraction layer 12 //============================================================================== 13 14 //---------- Includes ---------------------------------------------------------- 15 #include "system.h" 16 17 //---------- Defines ----------------------------------------------------------- 18 //I2C ports 19 //The communication on SDA and SCL is done by switching pad direction 20 //For a low level on SCL or SDA, direction is set to output. For a high level on 21 //SCL or SDA, direction is set to input. (pull up resistor active) 22 #define SDA PM3H_bit.no0 //SDA on I/O P38 defines direction (input=1/output=0) 23 #define SDA_CONF P3H_bit.no0 //SDA level on output direction 24 #define SCL PM3H_bit.no1 //SCL on I/O P39 defines direction (input=1/output=0) 25 #define SCL_CONF P3H_bit.no1 //SCL level on output direction 26 27 //---------- Enumerations ------------------------------------------------------ 28 // I2C level 29 typedef enum{ 30 LOW = 0, 31 HIGH = 1, 32 }etI2cLevel; 33 34 // I2C acknowledge 35 typedef enum{ 36 ACK = 0, 37 NO_ACK = 1, 38 }etI2cAck; 39 40 //============================================================================== 41 void I2c_Init (); 42 //============================================================================== 43 //Initializes the ports for I2C interface 44 45 //============================================================================== 46 void I2c_StartCondition (); 47 //============================================================================== 48 // writes a start condition on I2C-bus 49 // input : - 50 // output: - 51 // return: - 52 // note : timings (delay) may have to be changed for different microcontroller 53 // _____ 54 // SDA: |_____ 55 // _______ 56 // SCL : |___ 57 58 //============================================================================== 59 void I2c_StopCondition (); 60 //============================================================================== 61 // writes a stop condition on I2C-bus 62 // input : - 63 // output: - 64 // return: - 65 // note : timings (delay) may have to be changed for different microcontroller 66 // _____ 67 // SDA: _____| 68 // _______ 69 // SCL : ___| 70 71 //=========================================================================== 72 u8t I2c_WriteByte (u8t txByte); 73 //=========================================================================== 74 // writes a byte to I2C-bus and checks acknowledge 75 // input: txByte transmit byte 76 // output: - 77 // return: error 78 // note: timings (delay) may have to be changed for different microcontroller 79 80 //=========================================================================== 81 u8t I2c_ReadByte (etI2cAck ack); 82 //=========================================================================== 83 // reads a byte on I2C-bus 84 // input: rxByte receive byte 85 // output: rxByte 86 // note: timings (delay) may have to be changed for different microcontroller 87 88 #endif
1 //============================================================================== 2 // S E N S I R I O N AG, Laubisruetistr. 50, CH-8712 Staefa, Switzerland 3 //============================================================================== 4 // Project : SHT2x Sample Code (V1.0) 5 // File : I2C_HAL.c 6 // Author : MST 7 // Controller: NEC V850/SG3 (uPD70F3740) 8 // Compiler : IAR compiler for V850 (3.50A) 9 // Brief : I2C Hardware abstraction layer 10 //============================================================================== 11 12 //---------- Includes ---------------------------------------------------------- 13 #include "I2C_HAL.h" 14 15 //============================================================================== 16 void I2c_Init () 17 //============================================================================== 18 { 19 SDA=LOW; // Set port as output for configuration 20 SCL=LOW; // Set port as output for configuration 21 22 SDA_CONF=LOW; // Set SDA level as low for output mode 23 SCL_CONF=LOW; // Set SCL level as low for output mode 24 25 SDA=HIGH; // I2C-bus idle mode SDA released (input) 26 SCL=HIGH; // I2C-bus idle mode SCL released (input) 27 } 28 29 //============================================================================== 30 void I2c_StartCondition () 31 //============================================================================== 32 { 33 SDA=HIGH; 34 SCL=HIGH; 35 36 SDA=LOW; 37 DelayMicroSeconds(10); // hold time start condition (t_HD;STA) 38 SCL=LOW; 39 DelayMicroSeconds(10); 40 } 41 42 //============================================================================== 43 void I2c_StopCondition () 44 //============================================================================== 45 { 46 SDA=LOW; 47 SCL=LOW; 48 SCL=HIGH; 49 DelayMicroSeconds(10); // set-up time stop condition (t_SU;STO) 50 SDA=HIGH; 51 DelayMicroSeconds(10); 52 } 53 54 //============================================================================== 55 u8t I2c_WriteByte (u8t txByte) 56 //============================================================================== 57 { 58 u8t mask,error=0; 59 for (mask=0x80; mask>0; mask>>=1) //shift bit for masking (8 times) 60 { if ((mask & txByte) == 0) SDA=LOW;//masking txByte, write bit to SDA-Line 61 else SDA=HIGH; 62 DelayMicroSeconds(1); //data set-up time (t_SU;DAT) 63 SCL=HIGH; //generate clock pulse on SCL 64 DelayMicroSeconds(5); //SCL high time (t_HIGH) 65 SCL=LOW; 66 DelayMicroSeconds(1); //data hold time(t_HD;DAT) 67 } 68 SDA=HIGH; //release SDA-line 69 SCL=HIGH; //clk #9 for ack 70 DelayMicroSeconds(1); //data set-up time (t_SU;DAT) 71 if(SDA_CONF==HIGH) error=ACK_ERROR; //check ack from i2c slave 72 SCL=LOW; 73 DelayMicroSeconds(20); //wait time to see byte package on scope 74 return error; //return error code 75 } 76 77 //============================================================================== 78 u8t I2c_ReadByte (etI2cAck ack) 79 //============================================================================== 80 { 81 u8t mask,rxByte=0; 82 SDA=HIGH; //release SDA-line 83 for (mask=0x80; mask>0; mask>>=1) //shift bit for masking (8 times) 84 { SCL=HIGH; //start clock on SCL-line 85 DelayMicroSeconds(1); //data set-up time (t_SU;DAT) 86 DelayMicroSeconds(3); //SCL high time (t_HIGH) 87 if (SDA_CONF==1) rxByte=(rxByte | mask); //read bit 88 SCL=LOW; 89 DelayMicroSeconds(1); //data hold time(t_HD;DAT) 90 } 91 SDA=ack; //send acknowledge if necessary 92 DelayMicroSeconds(1); //data set-up time (t_SU;DAT) 93 SCL=HIGH; //clk #9 for ack 94 DelayMicroSeconds(5); //SCL high time (t_HIGH) 95 SCL=LOW; 96 SDA=HIGH; //release SDA-line 97 DelayMicroSeconds(20); //wait time to see byte package on scope 98 return rxByte; //return error code 99 }
转载于:https://www.cnblogs.com/shouchengcheng/p/3502188.html
SHT2x系列数字温湿度传感器相关推荐
- DFRobot高精度低功耗数字温湿度传感器SHT40
SHT40数字温湿度传感器介绍: SHT4X是业内知名的Sensirion公司推出的第四代数字温湿度传感器系列.继承自Sensirion温湿度传感器在业界有口皆和质量,SHT40 可在测量范围内提供始 ...
- 小白学数字温湿度传感器DHT11模块
[本系列文章还将陆续介绍其他的传感器模块,欢迎订阅我的博客] 温度和湿度对我们的生活有极大的影响,对它的测量也是很有必要的. DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器, ...
- 数字温湿度传感器DHT11
相对湿度和温度测量 全部校准,数字输出 卓越的长期稳定性 无需额外部件 超长的信号传输距离 超低能耗 4引脚安装 DHT11产品概述 DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合 ...
- STM32应用(八)数字温度传感器DS18B20、数字温湿度传感器DHT11(软件模拟I2C)
文章目录 1.DS18B20 数字温度传感器实验 1.1 DS18B20简介 1.2 硬件与IO口配置 1.3 实物图与接线 1.4 工程配置 1.5 驱动和检测代码编写 1.5.1 ds18b20. ...
- 【正点原子STM32连载】第四十章 DHT11数字温湿度传感器 摘自【正点原子】MiniPro STM32H750 开发指南_V1.1
1)实验平台:正点原子MiniPro H750开发板 2)平台购买地址:https://detail.tmall.com/item.htm?id=677017430560 3)全套实验源码+手册+视频 ...
- 【正点原子MP157连载】第二十七章 DHT11数字温湿度传感器实验-摘自【正点原子】STM32MP1 M4裸机CubeIDE开发指南
1)实验平台:正点原子STM32MP157开发板 2)购买链接:https://item.taobao.com/item.htm?&id=629270721801 3)全套实验源码+手册+视频 ...
- 数字温湿度传感器(DHT11)
一.简介 DHT11概述(官方描述) DHT11数字温湿度传感器是一款含有已校准数字信号输出的温湿度复合传感器.它应用专用的数字模块采集技术和温湿度传感技术,确保产品具有极高的可靠性与卓越的长期稳定性 ...
- Arduino之读取DHT11数字温湿度传感器并串口显示
温度是表示物体冷热程度的物理量,微观上来讲是物体分子热运动的剧烈程度.温度只能通过物体随温度变化的某些特性来间接测量,而用来量度物体温度数值的标尺叫温标.它规定了温度的读数起点(零点)和测量温度的基本 ...
- 有关温湿度传感器DHT11的C语言编程,数字温湿度传感器DHT11 操作C语言源代码
1.数字温湿度传感器DHT11 操作C语言源代码 2.带校验 3.带读操作超时处理 //IO定义 #defineP_DataIN_DHT11PB0_IN #defineP_DataOUT_DHT11P ...
最新文章
- Apache ab压力测试工具
- 深入剖析js命名空间函数namespace
- RoboGuice入门
- numpy基础(part13)--排序
- C语言 1A gt $20,C语言输出 1到20 的阶乘之和
- python gettext_python gettext使用
- Tomcat性能优化总结
- 二开版彩虹易支付全开源10套模板带风控实名系统源码
- java 服务端重复提交_java 服务器端验证重复提交
- PHP mysql_connect() 函数
- 所有文件夹都变成1KB文件夹快捷方式病毒的解决方法
- 如何查看wifi信息并对其进行管理?这些app帮你一键掌控你的wifi信息
- CreatePipe、CreateProcess函数
- 找不到服务器或应用项目,word中文档时提示“找不到服务器应用程序、源文件或项目”有...-office软件找不到word文档,officewo...
- 【统计信号处理检测理论:二维CFAR】
- 第6次课程作业—张欣
- ctfshow-萌赛
- PHP判断中文字符串的长度和字节长度
- H5打开支付宝小程序
- html不同域名显示不同内容,前端基础面试题(HTML+CSS部分)
热门文章
- 后渗透之关闭防火墙、杀毒软件并开启远程桌面
- 【研究生】横扫13项中文NLP任务:香侬科技提出汉语字形表征向量Glyce+田字格CNN...
- 优漫动游:带你了解UI图片比例技巧
- python websocket实时消息推送
- 操作系统中文件存储空间的管理
- Vue中使用Font Awesome
- Vue.js 使用cordova camera插件调取相机
- 怎样用excel剔除异常数据_excel如何去除异常值?(excel表格数据异常丢失)
- FDMS86252 实现低导通电阻 高效率的N沟道屏蔽栅极MOSFET管 150V 16A 51mΩ
- 新一轮涨价潮来袭!英飞凌、安森美、ST、安世等交期长达52周