資源簡(jiǎn)介
項(xiàng)目中用到的程序,穩(wěn)定可靠,由官方源碼改寫(xiě),模擬I2C,改好IO口直接就能驅(qū)動(dòng)。初始化的時(shí)候調(diào)用 SHT3X_Init(0x44);(地址看自己硬件0x44或45)即可。官方源碼的各種模式都保留了,省事的話直接用SHT3X_getHumidityTemperature函數(shù)就是最簡(jiǎn)單的獲取溫濕度到&temperature, &humidity。

代碼片段和文件信息
//=============================================================================
//????S?E?N?S?I?R?I?O?N???AG??Laubisruetistr.?50?CH-8712?Staefa?Switzerland
//=============================================================================
//?Project???:??SHT3x?Sample?Code?(V1.1)
//?File??????:??sht3x.c?(V1.1)
//?Author????:??RFU
//?Date??????:??6-Mai-2015
//?Controller:??STM32F100RB
//?IDE???????:??礦ision?V5.12.0.0
//?Compiler??:??Armcc
//?Brief?????:??Sensor?layer:?Implementation?of?functions?for?sensor?access.
//=============================================================================
//--?Includes?-----------------------------------------------------------------
#include?“sht3x.h“
#include?“gpio.h“
extern?float?tem_temp_displayftem_humi_displayf;
//--?Defines?------------------------------------------------------------------
//?Generator?polynomial?for?CRC
//--?Defines?------------------------------------------------------------------
//?Generator?polynomial?for?CRC
#define?POLYNOMIAL??0x131?//?P(x)?=?x^8?+?x^5?+?x^4?+?1?=?100110001
//=============================================================================
//?IO-Pins????????????????????????????/*?--?adapt?the?defines?for?your?uC?--?*/
//-----------------------------------------------------------------------------
//?Reset?on?port?B?bit?12
#define?RESET_LOW()??LED_GREEN_ON//?set?Reset?to?low
#define?RESET_HIGH()?LED_GREEN_OFF?//?set?Reset?to?high
//?Alert?on?port?B?bit?10
#define?ALERT_READ????????//?read?Alert
//=============================================================================
//--?Global?variables?---------------------------------------------------------
static?u8t?_i2cAddress;?//?I2C?Address
//--?Static?function?prototypes?-----------------------------------------------
static?etError?SHT3X_WriteAlertLimitData(ft?humidity?ft?temperature);
static?etError?SHT3X_ReadAlertLimitData(ft*?humidity?ft*?temperature);
static?etError?SHT3X_StartWriteAccess(void);
static?etError?SHT3X_StartReadAccess(void);
static?void?SHT3X_StopAccess(void);
static?etError?SHT3X_WriteCommand(etCommands?command);
static?etError?SHT3X_Read2BytesAndCrc(u16t*?data?etI2cAck?finaleAckNack
??????????????????????????????????????u8t?timeout);
static?etError?SHT3X_Write2BytesAndCrc(u16t?data);
static?u8t?SHT3X_CalcCrc(u8t?data[]?u8t?nbrOfBytes);
static?etError?SHT3X_CheckCrc(u8t?data[]?u8t?nbrOfBytes?u8t?checksum);
static?ft?SHT3X_CalcTemperature(u16t?rawValue);
static?ft?SHT3X_CalcHumidity(u16t?rawValue);
static?u16t?SHT3X_CalcRawTemperature(ft?temperature);
static?u16t?SHT3X_CalcRawHumidity(ft?humidity);
//=============================================================================
//?IO-Pins????????????????????????????/*?--?adapt?the?defines?for?your?uC?--?*/
//-----------------------------------------------------------------------------
//?Reset?on?port?B?bit?12
//#define?RESET_LOW()??(GPIOB->BSRR?=?0x10000000)?//?set?Reset?to?
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件???????32725??2020-01-15?14:23??sht3x\sht3x.c
?????文件???????16793??2020-01-15?14:24??sht3x\sht3x.h
?????目錄???????????0??2020-01-15?14:29??sht3x\
評(píng)論
共有 條評(píng)論