#include <compiler.h>
#include <cfg/os.h>
#include <sys/heap.h>
#include <sys/timer.h>
#include <sys/event.h>
#include <dev/twif.h>
#include <cfg/sht21.h>
#include <dev/sht21.h>
Defines | |
#define | SHT_READ_COUNT 3 |
#define | POLYNOMIAL 0x131 |
#define | T1x100 -4685L |
#define | T2x100 17572L |
#define | H1x100 -600L |
#define | H2x100 12500L |
#define | SHT_POLL_TOUT 90 |
#define | SHT_POLL_CYCLE 5 |
#define | SHT21_PRECISION SHT_RES_12_14 |
Functions | |
int | ShtCrc (uint8_t *Data, uint8_t Size) |
Calculate 8-Bit checksum with given polynomial. | |
int | ShtCommand (uint8_t cmd, uint16_t *data) |
Read data from sensor device. | |
int | ShtRead (uint8_t cmd, int16_t *val) |
Return real sensor value. | |
int | ShtInit (void) |
Register and initialize SHT2x sensor device. | |
Variables | |
HANDLE | sht_mutex |
#define SHT_READ_COUNT 3 |
Referenced by ShtCommand().
#define POLYNOMIAL 0x131 |
Referenced by ShtCrc().
#define T1x100 -4685L |
Referenced by ShtRead().
#define T2x100 17572L |
Referenced by ShtRead().
#define H1x100 -600L |
Referenced by ShtRead().
#define H2x100 12500L |
Referenced by ShtRead().
#define SHT_POLL_TOUT 90 |
Referenced by ShtCommand().
#define SHT_POLL_CYCLE 5 |
Referenced by ShtCommand().
#define SHT21_PRECISION SHT_RES_12_14 |
Referenced by ShtInit().
Calculate 8-Bit checksum with given polynomial.
This function calculates the checksum of a sensirion device returned data and validates it against the last byte transmitted. P(x) = x^8 + x^5 + x^4 + 1 = 100110001
Data Pointer to data to be checked. Size Size of data.
References POLYNOMIAL.
Referenced by ShtCommand().
Read data from sensor device.
This function reads the raw value of a SHT2x sensor device. To get the real sensor value, the formulas given by the datasheet have to be applied to this raw value.
cmd | can be SHT_GET_HUM or SHT_GET_TMP. |
data | Pointer to data value. |
References I2C_SLA_SHT21, NULL, NutEventPost(), NutEventWait(), NutSleep(), rc, SHT_GET_HUM, SHT_GET_TEMP, SHT_GET_USER, sht_mutex, SHT_POLL_CYCLE, SHT_POLL_TOUT, SHT_READ_COUNT, SHT_SET_USER, SHT_SOFT_RESET, ShtCrc(), TwMasterRegRead, and TwMasterTransact.
Referenced by ShtInit(), and ShtRead().
Return real sensor value.
This function returns either the temperature or the humidity value to a supplied int16_t pointer. The value is decimal with 2 decimal digits: val=2604 -> 26.04°C val=2335 -> 23.35rH
cmd | Either SHT_GET_TEMP or SHT_GET_HUM. |
val | Pointer to store the value to. |
References H1x100, H2x100, rc, SHT_GET_HUM, SHT_GET_TEMP, ShtCommand(), T1x100, and T2x100.
int ShtInit | ( | void | ) |
Register and initialize SHT2x sensor device.
This function initializes the structures and I2C bus for use with SHT2x sensor device. It checks communication too.
References NutEventPost(), rc, SHT21_PRECISION, SHT_GET_USER, sht_mutex, SHT_RES_MASK, SHT_SET_USER, SHT_SOFT_RESET, and ShtCommand().
Referenced by ShtCommand(), and ShtInit().