/**
* @file SHT3X_ATY.h
*
* @param Project DEVICE_GENERAL_ATY_LIB
*
* @author ATY
*
* @copyright
* - Copyright 2017 - 2023 MZ-ATY
* - This code follows:
* - MZ-ATY Various Contents Joint Statement -
*
* https://mengze.top/MZ-ATY_VCJS
* - CC 4.0 BY-NC-SA -
*
* https://creativecommons.org/licenses/by-nc-sa/4.0/
* - Your use will be deemed to have accepted the terms of this statement.
*
* @brief Familiar functions of SHT3X tem&hum transistor for all devices
*
* @version
* - 1_01_200318 > ATY
* -# Preliminary version, first Release
* - 1_02_231229 > ATY
* -# add multy addr and channel
********************************************************************************
*/
#ifndef __SHT3X_ATY_H
#define __SHT3X_ATY_H
#include "INCLUDE_ATY.h"
#include "HW_TIMER_ATY.h"
#include "HW_I2C_ATY.h"
/******************************* For user *************************************/
#define SHT3X_P_ADDR 0
#define SHT3X_ADDR (0x44 | SHT3X_P_ADDR)
// #define __DEBUG_SHT3X_ATY
// #define SHT3X_I2C I2C_C1
extern uint8_t Temperature[5];
extern uint8_t Humidity[5];
extern uint8_t TemperatureStr[5];
extern uint8_t HumidityStr[5];
extern uint8_t temperatureHexI; // integer
extern uint8_t temperatureHexD; // decimal
extern uint8_t humidityHexI;
extern uint8_t humidityHexD;
/******************************************************************************/
// Generator polynomial for CRC
#define POLYNOMIAL 0x131 // P(x) = x^8 + x^5 + x^4 + 1 = 100110001
// Sensor Commands
typedef enum{
CMD_READ_SERIALNBR = 0x3780, // read serial number
CMD_READ_STATUS = 0xF32D, // read status register
CMD_CLEAR_STATUS = 0x3041, // clear status register
CMD_HEATER_ENABLE = 0x306D, // enabled heater
CMD_HEATER_DISABLE = 0x3066, // disable heater
CMD_SOFT_RESET = 0x30A2, // soft reset
CMD_MEAS_CLOCKSTR_H = 0x2C06, // measurement: clock stretching, high repeatability
CMD_MEAS_CLOCKSTR_M = 0x2C0D, // measurement: clock stretching, medium repeatability
CMD_MEAS_CLOCKSTR_L = 0x2C10, // measurement: clock stretching, low repeatability
CMD_MEAS_POLLING_H = 0x2400, // measurement: polling, high repeatability
CMD_MEAS_POLLING_M = 0x240B, // measurement: polling, medium repeatability
CMD_MEAS_POLLING_L = 0x2416, // measurement: polling, low repeatability
CMD_MEAS_PERI_05_H = 0x2032, // measurement: periodic 0.5 mps, high repeatability
CMD_MEAS_PERI_05_M = 0x2024, // measurement: periodic 0.5 mps, medium repeatability
CMD_MEAS_PERI_05_L = 0x202F, // measurement: periodic 0.5 mps, low repeatability
CMD_MEAS_PERI_1_H = 0x2130, // measurement: periodic 1 mps, high repeatability
CMD_MEAS_PERI_1_M = 0x2126, // measurement: periodic 1 mps, medium repeatability
CMD_MEAS_PERI_1_L = 0x212D, // measurement: periodic 1 mps, low repeatability
CMD_MEAS_PERI_2_H = 0x2236, // measurement: periodic 2 mps, high repeatability
CMD_MEAS_PERI_2_M = 0x2220, // measurement: periodic 2 mps, medium repeatability
CMD_MEAS_PERI_2_L = 0x222B, // measurement: periodic 2 mps, low repeatability
CMD_MEAS_PERI_4_H = 0x2334, // measurement: periodic 4 mps, high repeatability
CMD_MEAS_PERI_4_M = 0x2322, // measurement: periodic 4 mps, medium repeatability
CMD_MEAS_PERI_4_L = 0x2329, // measurement: periodic 4 mps, low repeatability
CMD_MEAS_PERI_10_H = 0x2737, // measurement: periodic 10 mps, high repeatability
CMD_MEAS_PERI_10_M = 0x2721, // measurement: periodic 10 mps, medium repeatability
CMD_MEAS_PERI_10_L = 0x272A, // measurement: periodic 10 mps, low repeatability
CMD_FETCH_DATA = 0xE000, // readout measurements for periodic mode
CMD_R_AL_LIM_LS = 0xE102, // read alert limits, low set
CMD_R_AL_LIM_LC = 0xE109, // read alert limits, low clear
CMD_R_AL_LIM_HS = 0xE11F, // read alert limits, high set
CMD_R_AL_LIM_HC = 0xE114, // read alert limits, high clear
CMD_W_AL_LIM_HS = 0x611D, // write alert limits, high set
CMD_W_AL_LIM_HC = 0x6116, // write alert limits, high clear
CMD_W_AL_LIM_LC = 0x610B, // write alert limits, low clear
CMD_W_AL_LIM_LS = 0x6100, // write alert limits, low set
CMD_NO_SLEEP = 0x303E,
}sht3xCommands;
// Measurement Repeatability
typedef enum{
REPEATAB_HIGH, // high repeatability
REPEATAB_MEDIUM, // medium repeatability
REPEATAB_LOW, // low repeatability
}sht3xRepeatability;
// Measurement Mode
typedef enum{
MODE_CLKSTRETCH, // clock stretching
MODE_POLLING, // polling
}sht3xMode;
typedef enum{
FREQUENCY_HZ5, // 0.5 measurements per seconds
FREQUENCY_1HZ, // 1.0 measurements per seconds
FREQUENCY_2HZ, // 2.0 measurements per seconds
FREQUENCY_4HZ, // 4.0 measurements per seconds
FREQUENCY_10HZ, // 10.0 measurements per seconds
}sht3xFrequency;
void SHT3X_InitBegin(uint8_t addr, uint8_t channel);
void SHT3X_ReadMeasurementBuffer(uint8_t addr, uint8_t channel);
#endif /* __SHT3X_ATY_H */
/******************************** End Of File *********************************/