Nut/OS  5.0.5
API Reference
sht21.c File Reference
#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>
Include dependency graph for sht21.c:

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 Documentation

#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().


Function Documentation

int ShtCrc ( uint8_t Data,
uint8_t  Size 
)

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.

Returns:
-1 if CRC failed else 0

References POLYNOMIAL.

Referenced by ShtCommand().

int ShtCommand ( uint8_t  cmd,
uint16_t data 
)

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.

Parameters:
cmdcan be SHT_GET_HUM or SHT_GET_TMP.
dataPointer to data value.
Returns:
-1 read failed else 0.

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().

Here is the call graph for this function:

int ShtRead ( uint8_t  cmd,
int16_t val 
)

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

Parameters:
cmdEither SHT_GET_TEMP or SHT_GET_HUM.
valPointer to store the value to.
Returns:
-1 if failed else 0.

References H1x100, H2x100, rc, SHT_GET_HUM, SHT_GET_TEMP, ShtCommand(), T1x100, and T2x100.

Here is the call graph for this function:

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.

Returns:
-1 if init failed else 0.

References NutEventPost(), rc, SHT21_PRECISION, SHT_GET_USER, sht_mutex, SHT_RES_MASK, SHT_SET_USER, SHT_SOFT_RESET, and ShtCommand().

Here is the call graph for this function:


Variable Documentation

Referenced by ShtCommand(), and ShtInit().