Digital Humidity Sensor

Committer:
mcm
Date:
Mon Apr 26 11:22:46 2021 +0000
Revision:
3:42e11b9135b5
Parent:
2:870701ee67c4
The driver was completed and tested (NUCLEO-L152RE), it works as expected.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 1:c3590e18b517 1 /**
mcm 1:c3590e18b517 2 * @brief SHT3X.h
mcm 1:c3590e18b517 3 * @details Humidity and Temperature Sensor.
mcm 1:c3590e18b517 4 * Header file.
mcm 1:c3590e18b517 5 *
mcm 1:c3590e18b517 6 *
mcm 1:c3590e18b517 7 * @return N/A
mcm 1:c3590e18b517 8 *
mcm 1:c3590e18b517 9 * @author Manuel Caballero
mcm 1:c3590e18b517 10 * @date 25/March/2021
mcm 1:c3590e18b517 11 * @version 25/March/2021 The ORIGIN
mcm 1:c3590e18b517 12 * @pre N/A
mcm 1:c3590e18b517 13 * @warning N/A
mcm 1:c3590e18b517 14 * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ).
mcm 1:c3590e18b517 15 */
mcm 1:c3590e18b517 16 #ifndef SHT3X_H_
mcm 1:c3590e18b517 17 #define SHT3X_H_
mcm 1:c3590e18b517 18
mcm 1:c3590e18b517 19 #include "mbed.h"
mcm 1:c3590e18b517 20
mcm 1:c3590e18b517 21
mcm 1:c3590e18b517 22 /**
mcm 1:c3590e18b517 23 Example:
mcm 1:c3590e18b517 24
mcm 1:c3590e18b517 25 @code
mcm 3:42e11b9135b5 26 #include "mbed.h"
mcm 3:42e11b9135b5 27 #include "SHT3X.h"
mcm 1:c3590e18b517 28
mcm 3:42e11b9135b5 29 SHT3X mySHT3X ( I2C_SDA, I2C_SCL, SHT3X::SHT3X_ADDRESS_B, 400000 ); // I2C_SDA | I2C_SCL
mcm 3:42e11b9135b5 30 Serial pc ( USBTX, USBRX ); // tx, rx
mcm 3:42e11b9135b5 31
mcm 3:42e11b9135b5 32 DigitalOut myled ( LED1 );
mcm 3:42e11b9135b5 33 Ticker newAction;
mcm 3:42e11b9135b5 34
mcm 3:42e11b9135b5 35
mcm 3:42e11b9135b5 36 //@brief Constants.
mcm 3:42e11b9135b5 37
mcm 3:42e11b9135b5 38
mcm 3:42e11b9135b5 39 //@brief Variables.
mcm 3:42e11b9135b5 40 volatile uint32_t myState; // State that indicates when to perform a new sample
mcm 3:42e11b9135b5 41
mcm 3:42e11b9135b5 42
mcm 3:42e11b9135b5 43 //@brief FUNCTION PROTOTYPES
mcm 3:42e11b9135b5 44 void changeDATA ( void );
mcm 3:42e11b9135b5 45
mcm 3:42e11b9135b5 46
mcm 3:42e11b9135b5 47 //@brief FUNCTION FOR APPLICATION MAIN ENTRY.
mcm 3:42e11b9135b5 48 int main()
mcm 3:42e11b9135b5 49 {
mcm 3:42e11b9135b5 50 SHT3X::SHT3X_status_t aux;
mcm 3:42e11b9135b5 51 SHT3X::SHT3X_data_t mySHT3X_Data;
mcm 3:42e11b9135b5 52
mcm 3:42e11b9135b5 53 pc.baud ( 115200 );
mcm 3:42e11b9135b5 54
mcm 3:42e11b9135b5 55 myled = 1;
mcm 3:42e11b9135b5 56 wait(3);
mcm 3:42e11b9135b5 57 myled = 0;
mcm 3:42e11b9135b5 58
mcm 3:42e11b9135b5 59 // Set a software reset
mcm 3:42e11b9135b5 60 aux = mySHT3X.SHT3X_SetSoftReset ();
mcm 3:42e11b9135b5 61 wait_ms(2U);
mcm 3:42e11b9135b5 62
mcm 3:42e11b9135b5 63 // Clear the STATUS register
mcm 3:42e11b9135b5 64 aux = mySHT3X.SHT3X_ClearStatus ();
mcm 3:42e11b9135b5 65
mcm 3:42e11b9135b5 66 // Disable the Heater
mcm 3:42e11b9135b5 67 aux = mySHT3X.SHT3X_SetHeater ( SHT3X::SHT3X_HEATER_DISABLE );
mcm 3:42e11b9135b5 68
mcm 3:42e11b9135b5 69 // Do not perform periodic measurement
mcm 3:42e11b9135b5 70 aux = mySHT3X.SHT3X_SetBreakCommand ();
mcm 3:42e11b9135b5 71
mcm 3:42e11b9135b5 72 myState = 0UL; // Reset the variable
mcm 3:42e11b9135b5 73 newAction.attach( &changeDATA, 1U ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
mcm 3:42e11b9135b5 74
mcm 3:42e11b9135b5 75 // Let the callbacks take care of everything
mcm 3:42e11b9135b5 76 while(1) {
mcm 3:42e11b9135b5 77 sleep();
mcm 3:42e11b9135b5 78
mcm 3:42e11b9135b5 79 if ( myState == 1UL ) {
mcm 3:42e11b9135b5 80 myled = 1U;
mcm 3:42e11b9135b5 81
mcm 3:42e11b9135b5 82 // Trigger to get a new data set, no clock stretching and repeatibility high
mcm 3:42e11b9135b5 83 aux = mySHT3X.SHT3X_OneShotTriggerAllData ( SHT3X::SHT3X_CLOCK_STRETCHING_DISABLED_REPEATABILITY_HIGH );
mcm 3:42e11b9135b5 84 wait_ms(15U);
mcm 3:42e11b9135b5 85
mcm 3:42e11b9135b5 86 // Get all the data
mcm 3:42e11b9135b5 87 aux = mySHT3X.SHT3X_OneShotGetAllRawData ( &mySHT3X_Data.rawData );
mcm 3:42e11b9135b5 88
mcm 3:42e11b9135b5 89
mcm 3:42e11b9135b5 90 // Process all the data
mcm 3:42e11b9135b5 91 mySHT3X.SHT3X_ProccessData ( mySHT3X_Data.rawData, &mySHT3X_Data.data );
mcm 3:42e11b9135b5 92
mcm 3:42e11b9135b5 93 // Send data through the UART
mcm 3:42e11b9135b5 94 pc.printf ( "T: %0.2f C, RH: %0.2f %%\r\n", mySHT3X_Data.data.temperature, mySHT3X_Data.data.relativeHumidity );
mcm 3:42e11b9135b5 95
mcm 3:42e11b9135b5 96
mcm 3:42e11b9135b5 97 // Reset the variables
mcm 3:42e11b9135b5 98 myState = 0UL;
mcm 3:42e11b9135b5 99 myled = 0U;
mcm 3:42e11b9135b5 100 }
mcm 3:42e11b9135b5 101 }
mcm 3:42e11b9135b5 102 }
mcm 3:42e11b9135b5 103
mcm 3:42e11b9135b5 104
mcm 3:42e11b9135b5 105 // @brief changeDATA ( void )
mcm 3:42e11b9135b5 106 //
mcm 3:42e11b9135b5 107 // @details It changes myState variable
mcm 3:42e11b9135b5 108 //
mcm 3:42e11b9135b5 109 // @param[in] N/A
mcm 3:42e11b9135b5 110 //
mcm 3:42e11b9135b5 111 // @param[out] N/A.
mcm 3:42e11b9135b5 112 //
mcm 3:42e11b9135b5 113 // @return N/A.
mcm 3:42e11b9135b5 114 //
mcm 3:42e11b9135b5 115 // @author Manuel Caballero
mcm 3:42e11b9135b5 116 // @date 25/March/2021
mcm 3:42e11b9135b5 117 // @version 25/March/2021 The ORIGIN
mcm 3:42e11b9135b5 118 // @pre N/A
mcm 3:42e11b9135b5 119 // @warning N/A.
mcm 3:42e11b9135b5 120 void changeDATA ( void )
mcm 3:42e11b9135b5 121 {
mcm 3:42e11b9135b5 122 myState = 1UL;
mcm 3:42e11b9135b5 123 }
mcm 1:c3590e18b517 124 @endcode
mcm 1:c3590e18b517 125 */
mcm 1:c3590e18b517 126
mcm 1:c3590e18b517 127
mcm 1:c3590e18b517 128 /*!
mcm 1:c3590e18b517 129 Library for the SHT3X Humidity and Temperature Sensor.
mcm 1:c3590e18b517 130 */
mcm 1:c3590e18b517 131 class SHT3X
mcm 1:c3590e18b517 132 {
mcm 1:c3590e18b517 133 public:
mcm 1:c3590e18b517 134 /**
mcm 1:c3590e18b517 135 * @brief DEFAULT ADDRESSES
mcm 1:c3590e18b517 136 */
mcm 1:c3590e18b517 137 typedef enum {
mcm 1:c3590e18b517 138 SHT3X_ADDRESS_A = ( 0x44 << 1U ), /*!< SHT3X ADDR pin connected to logic low */
mcm 1:c3590e18b517 139 SHT3X_ADDRESS_B = ( 0x45 << 1U ) /*!< SHT3X ADDR pin connected to logic high */
mcm 1:c3590e18b517 140 } SHT3X_address_t;
mcm 1:c3590e18b517 141
mcm 1:c3590e18b517 142
mcm 1:c3590e18b517 143
mcm 1:c3590e18b517 144 /**
mcm 1:c3590e18b517 145 * @brief COMMAND REGISTERS
mcm 1:c3590e18b517 146 */
mcm 1:c3590e18b517 147 typedef enum {
mcm 1:c3590e18b517 148 SHT3X_CLOCK_STRETCHING_ENABLED_REPEATABILITY_HIGH = 0x2C06, /*!< High repeatability measurement with clock stretching enabled */
mcm 1:c3590e18b517 149 SHT3X_CLOCK_STRETCHING_ENABLED_REPEATABILITY_MEDIUM = 0x2C0D, /*!< Medium repeatability measurement with clock stretching enabled */
mcm 1:c3590e18b517 150 SHT3X_CLOCK_STRETCHING_ENABLED_REPEATABILITY_LOW = 0x2C10, /*!< Low repeatability measurement with clock stretching enabled */
mcm 1:c3590e18b517 151
mcm 1:c3590e18b517 152 SHT3X_CLOCK_STRETCHING_DISABLED_REPEATABILITY_HIGH = 0x2400, /*!< High repeatability measurement with clock stretching disabled */
mcm 1:c3590e18b517 153 SHT3X_CLOCK_STRETCHING_DISABLED_REPEATABILITY_MEDIUM = 0x240B, /*!< Medium repeatability measurement with clock stretching disabled */
mcm 1:c3590e18b517 154 SHT3X_CLOCK_STRETCHING_DISABLED_REPEATABILITY_LOW = 0x2416, /*!< Low repeatability measurement with clock stretching disabled */
mcm 1:c3590e18b517 155 } SHT3X_command_registers_single_shot_mode_t;
mcm 1:c3590e18b517 156
mcm 1:c3590e18b517 157
mcm 1:c3590e18b517 158 typedef enum {
mcm 1:c3590e18b517 159 SHT3X_HEATER_ENABLE = 0x306D, /*!< Heater enable command */
mcm 1:c3590e18b517 160 SHT3X_HEATER_DISABLE = 0x3066, /*!< Heater disable command */
mcm 1:c3590e18b517 161 } SHT3X_command_registers_heater_t;
mcm 1:c3590e18b517 162
mcm 1:c3590e18b517 163
mcm 1:c3590e18b517 164 typedef enum {
mcm 1:c3590e18b517 165 SHT3X_MPS_0_5_REPEATABILITY_HIGH = 0x2032, /*!< High repeatability 0.5 measurement per second */
mcm 1:c3590e18b517 166 SHT3X_MPS_0_5_REPEATABILITY_MEDIUM = 0x2024, /*!< Medium repeatability 0.5 measurement per second */
mcm 1:c3590e18b517 167 SHT3X_MPS_0_5_REPEATABILITY_LOW = 0x202F, /*!< Low repeatability 0.5 measurement per second */
mcm 1:c3590e18b517 168
mcm 1:c3590e18b517 169 SHT3X_MPS_1_REPEATABILITY_HIGH = 0x2130, /*!< High repeatability 1 measurement per second */
mcm 1:c3590e18b517 170 SHT3X_MPS_1_REPEATABILITY_MEDIUM = 0x2126, /*!< Medium repeatability 1 measurement per second */
mcm 1:c3590e18b517 171 SHT3X_MPS_1_REPEATABILITY_LOW = 0x212D, /*!< Low repeatability 1 measurement per second */
mcm 1:c3590e18b517 172
mcm 1:c3590e18b517 173 SHT3X_MPS_2_REPEATABILITY_HIGH = 0x2236, /*!< High repeatability 2 measurement per second */
mcm 1:c3590e18b517 174 SHT3X_MPS_2_REPEATABILITY_MEDIUM = 0x2220, /*!< Medium repeatability 2 measurement per second */
mcm 1:c3590e18b517 175 SHT3X_MPS_2_REPEATABILITY_LOW = 0x222B, /*!< Low repeatability 2 measurement per second */
mcm 1:c3590e18b517 176
mcm 1:c3590e18b517 177 SHT3X_MPS_4_REPEATABILITY_HIGH = 0x2334, /*!< High repeatability 4 measurement per second */
mcm 1:c3590e18b517 178 SHT3X_MPS_4_REPEATABILITY_MEDIUM = 0x2322, /*!< Medium repeatability 4 measurement per second */
mcm 1:c3590e18b517 179 SHT3X_MPS_4_REPEATABILITY_LOW = 0x2329, /*!< Low repeatability 4 measurement per second */
mcm 1:c3590e18b517 180
mcm 1:c3590e18b517 181 SHT3X_MPS_10_REPEATABILITY_HIGH = 0x2737, /*!< High repeatability 10 measurement per second */
mcm 1:c3590e18b517 182 SHT3X_MPS_10_REPEATABILITY_MEDIUM = 0x2721, /*!< Medium repeatability 10 measurement per second */
mcm 1:c3590e18b517 183 SHT3X_MPS_10_REPEATABILITY_LOW = 0x272A, /*!< Low repeatability 10 measurement per second */
mcm 1:c3590e18b517 184 } SHT3X_command_registers_periodic_data_mode_t;
mcm 1:c3590e18b517 185
mcm 1:c3590e18b517 186
mcm 1:c3590e18b517 187 typedef enum {
mcm 1:c3590e18b517 188 SHT3X_FETCH_DATA = 0xE000, /*!< Fetch data command */
mcm 1:c3590e18b517 189 SHT3X_PERIODIC_MESUREMENT_WITH_ART = 0x2B32, /*!< ART command */
mcm 1:c3590e18b517 190 SHT3X_BREAK = 0x3093, /*!< Break command */
mcm 1:c3590e18b517 191 SHT3X_SOFT_RESET = 0x30A2, /*!< Software reset command */
mcm 1:c3590e18b517 192 SHT3X_STATUS_REGISTER = 0xF32D, /*!< Status command */
mcm 1:c3590e18b517 193 SHT3X_CLEAR_STATUS_REGISTER = 0x3041 /*!< Clear Status register command */
mcm 1:c3590e18b517 194 } SHT3X_command_registers_t;
mcm 1:c3590e18b517 195
mcm 1:c3590e18b517 196
mcm 1:c3590e18b517 197
mcm 1:c3590e18b517 198 // GENERAL CALL
mcm 1:c3590e18b517 199 /**
mcm 1:c3590e18b517 200 * @brief RESET
mcm 1:c3590e18b517 201 */
mcm 1:c3590e18b517 202 typedef enum {
mcm 1:c3590e18b517 203 SHT3X_GENERAL_CALL_RESET_ADDRESS_BYTE = 0x00, /*!< Reset. Address byte */
mcm 1:c3590e18b517 204 SHT3X_GENERAL_CALL_RESET_SECOND_BYTE = 0x06 /*!< Reset. Second byte */
mcm 1:c3590e18b517 205 } SHT3X_general_call_t;
mcm 1:c3590e18b517 206
mcm 1:c3590e18b517 207
mcm 1:c3590e18b517 208
mcm 1:c3590e18b517 209 /**
mcm 1:c3590e18b517 210 * @brief STATUS REGISTER.
mcm 1:c3590e18b517 211 * NOTE: N/A.
mcm 1:c3590e18b517 212 */
mcm 1:c3590e18b517 213 /* ALERT_PENDING_STATUS <15>
mcm 1:c3590e18b517 214 * NOTE: N/A.
mcm 1:c3590e18b517 215 */
mcm 1:c3590e18b517 216 typedef enum {
mcm 1:c3590e18b517 217 STATUS_ALERT_PENDING_STATUS_MASK = ( 1U << 15U ), /*!< ALERT_PENDING_STATUS mask */
mcm 1:c3590e18b517 218 STATUS_ALERT_PENDING_STATUS_NO_PENDING_ALERTS = ( 0U << 15U ), /*!< No pending alerts */
mcm 1:c3590e18b517 219 STATUS_ALERT_PENDING_STATUS_AT_LEAST_ONE_PENDING_ALERT = ( 1U << 15U ) /*!< At least one pending alert [Default] */
mcm 1:c3590e18b517 220 } SHT3X_status_alert_pending_status_t;
mcm 1:c3590e18b517 221
mcm 1:c3590e18b517 222
mcm 1:c3590e18b517 223 /* HEATER_STATUS <13>
mcm 1:c3590e18b517 224 * NOTE: N/A.
mcm 1:c3590e18b517 225 */
mcm 1:c3590e18b517 226 typedef enum {
mcm 1:c3590e18b517 227 STATUS_HEATER_STATUS_MASK = ( 1U << 13U ), /*!< HEATER_STATUS mask */
mcm 1:c3590e18b517 228 STATUS_HEATER_OFF = ( 0U << 13U ), /*!< Heater off [Default] */
mcm 1:c3590e18b517 229 STATUS_HEATER_ON = ( 1U << 13U ) /*!< Heater on */
mcm 1:c3590e18b517 230 } SHT3X_status_heater_status_t;
mcm 1:c3590e18b517 231
mcm 1:c3590e18b517 232
mcm 1:c3590e18b517 233 /* RH_TRACKING_ALERT <11>
mcm 1:c3590e18b517 234 * NOTE: N/A.
mcm 1:c3590e18b517 235 */
mcm 1:c3590e18b517 236 typedef enum {
mcm 1:c3590e18b517 237 STATUS_RH_TRACKING_ALERT_MASK = ( 1U << 11U ), /*!< RH_TRACKING_ALERT mask */
mcm 1:c3590e18b517 238 STATUS_RH_TRACKING_ALERT_NO_ALERT = ( 0U << 11U ), /*!< No alert [Default] */
mcm 1:c3590e18b517 239 STATUS_RH_TRACKING_ALERT_ALERT = ( 1U << 11U ) /*!< Alert */
mcm 1:c3590e18b517 240 } SHT3X_status_rh_tracking_alert_t;
mcm 1:c3590e18b517 241
mcm 1:c3590e18b517 242
mcm 1:c3590e18b517 243 /* T_TRACKING_ALERT <10>
mcm 1:c3590e18b517 244 * NOTE: N/A.
mcm 1:c3590e18b517 245 */
mcm 1:c3590e18b517 246 typedef enum {
mcm 1:c3590e18b517 247 STATUS_T_TRACKING_ALERT_MASK = ( 1U << 10U ), /*!< T_TRACKING_ALERT mask */
mcm 1:c3590e18b517 248 STATUS_T_TRACKING_ALERT_NO_ALERT = ( 0U << 10U ), /*!< No alert [Default] */
mcm 1:c3590e18b517 249 STATUS_T_TRACKING_ALERT_ALERT = ( 1U << 10U ) /*!< Alert */
mcm 1:c3590e18b517 250 } SHT3X_status_t_tracking_alert_t;
mcm 1:c3590e18b517 251
mcm 1:c3590e18b517 252
mcm 1:c3590e18b517 253 /* SYSTEM_RESET_DETECTED <4>
mcm 1:c3590e18b517 254 * NOTE: N/A.
mcm 1:c3590e18b517 255 */
mcm 1:c3590e18b517 256 typedef enum {
mcm 1:c3590e18b517 257 STATUS_SYSTEM_RESET_DETECTED_MASK = ( 1U << 4U ), /*!< SYSTEM_RESET_DETECTED mask */
mcm 1:c3590e18b517 258 STATUS_SYSTEM_RESET_DETECTED_NO_RESET_DETECTED = ( 0U << 4U ), /*!< No reset detected since last 'clear status register' command */
mcm 1:c3590e18b517 259 STATUS_SYSTEM_RESET_DETECTED_RESET_DETECTED = ( 1U << 4U ) /*!< Reset detected (hard reset, soft reset command or supply fail)[Default] */
mcm 1:c3590e18b517 260 } SHT3X_status_system_reset_detected_t;
mcm 1:c3590e18b517 261
mcm 1:c3590e18b517 262
mcm 1:c3590e18b517 263 /* COMMAND_STATUS <1>
mcm 1:c3590e18b517 264 * NOTE: N/A.
mcm 1:c3590e18b517 265 */
mcm 1:c3590e18b517 266 typedef enum {
mcm 1:c3590e18b517 267 STATUS_COMMAND_STATUS_MASK = ( 1U << 10U ), /*!< COMMAND_STATUS mask */
mcm 1:c3590e18b517 268 STATUS_COMMAND_STATUS_COMMAND_EXECUTED_SUCCESSFULLY = ( 0U << 10U ), /*!< Last command executed successfully [Default] */
mcm 1:c3590e18b517 269 STATUS_COMMAND_STATUS_LAST_COMMAND_NOT_PROCESSED = ( 1U << 10U ) /*!< Last command not processed */
mcm 1:c3590e18b517 270 } SHT3X_status_command_status_t;
mcm 1:c3590e18b517 271
mcm 1:c3590e18b517 272
mcm 1:c3590e18b517 273 /* WRITE_DATA_CHECKSUM_STATUS <0>
mcm 1:c3590e18b517 274 * NOTE: N/A.
mcm 1:c3590e18b517 275 */
mcm 1:c3590e18b517 276 typedef enum {
mcm 1:c3590e18b517 277 STATUS_WRITE_DATA_CHECKSUM_STATUS_MASK = ( 1U << 0U ), /*!< COMMAND_STATUS mask */
mcm 1:c3590e18b517 278 STATUS_WRITE_DATA_CHECKSUM_STATUS_CHECKSUM_CORRECT = ( 0U << 0U ), /*!< Checksum of last write transfer was correct[Default] */
mcm 1:c3590e18b517 279 STATUS_WRITE_DATA_CHECKSUM_STATUS_CHECKSUM_FAILED = ( 1U << 0U ) /*!< Checksum of last write transfer failed */
mcm 1:c3590e18b517 280 } SHT3X_status_write_data_checksum_status_t;
mcm 1:c3590e18b517 281
mcm 1:c3590e18b517 282
mcm 1:c3590e18b517 283
mcm 1:c3590e18b517 284
mcm 1:c3590e18b517 285
mcm 1:c3590e18b517 286 #ifndef SHT3X_VECTOR_STRUCT_H
mcm 1:c3590e18b517 287 #define SHT3X_VECTOR_STRUCT_H
mcm 1:c3590e18b517 288 /* RAW DATA */
mcm 1:c3590e18b517 289 typedef struct {
mcm 1:c3590e18b517 290 uint16_t rawRelativeHumidity;
mcm 1:c3590e18b517 291 uint16_t rawTemperature;
mcm 1:c3590e18b517 292
mcm 1:c3590e18b517 293 uint8_t temperatureCRC;
mcm 1:c3590e18b517 294 uint8_t relativeHumidityCRC;
mcm 1:c3590e18b517 295 } SHT3X_raw_data_t;
mcm 1:c3590e18b517 296
mcm 1:c3590e18b517 297
mcm 1:c3590e18b517 298 /* DATA: Temperature and Relative Humidity */
mcm 1:c3590e18b517 299 typedef struct {
mcm 1:c3590e18b517 300 float relativeHumidity;
mcm 1:c3590e18b517 301 float temperature;
mcm 1:c3590e18b517 302
mcm 1:c3590e18b517 303 uint8_t temperatureCRC;
mcm 1:c3590e18b517 304 uint8_t relativeHumidityCRC;
mcm 1:c3590e18b517 305 } SHT3X_final_data_t;
mcm 1:c3590e18b517 306
mcm 1:c3590e18b517 307
mcm 1:c3590e18b517 308 /* STATUS REGISTER */
mcm 1:c3590e18b517 309 typedef struct {
mcm 1:c3590e18b517 310 uint16_t status;
mcm 1:c3590e18b517 311 uint8_t statusCRC;
mcm 1:c3590e18b517 312 } SHT3X_status_data_t;
mcm 1:c3590e18b517 313
mcm 1:c3590e18b517 314
mcm 1:c3590e18b517 315
mcm 1:c3590e18b517 316 /* USER: User's variables */
mcm 1:c3590e18b517 317 typedef struct {
mcm 1:c3590e18b517 318 /* Output data */
mcm 1:c3590e18b517 319 SHT3X_raw_data_t rawData;
mcm 1:c3590e18b517 320 SHT3X_final_data_t data;
mcm 1:c3590e18b517 321
mcm 1:c3590e18b517 322 /* Status register */
mcm 1:c3590e18b517 323 SHT3X_status_data_t status;
mcm 1:c3590e18b517 324 } SHT3X_data_t;
mcm 1:c3590e18b517 325 #endif
mcm 1:c3590e18b517 326
mcm 1:c3590e18b517 327
mcm 1:c3590e18b517 328
mcm 1:c3590e18b517 329
mcm 1:c3590e18b517 330
mcm 1:c3590e18b517 331 /**
mcm 1:c3590e18b517 332 * @brief INTERNAL CONSTANTS
mcm 1:c3590e18b517 333 */
mcm 1:c3590e18b517 334 typedef enum {
mcm 1:c3590e18b517 335 SHT3X_SUCCESS = 0,
mcm 1:c3590e18b517 336 SHT3X_FAILURE = 1,
mcm 2:870701ee67c4 337 I2C_SUCCESS = 0
mcm 1:c3590e18b517 338 } SHT3X_status_t;
mcm 1:c3590e18b517 339
mcm 1:c3590e18b517 340
mcm 1:c3590e18b517 341
mcm 1:c3590e18b517 342 /**
mcm 1:c3590e18b517 343 * @brief FUNCTION PROTOTYPES
mcm 1:c3590e18b517 344 */
mcm 2:870701ee67c4 345 /** Create an SHT3X object connected to the specified I2C pins.
mcm 2:870701ee67c4 346 *
mcm 2:870701ee67c4 347 * @param sda I2C data pin
mcm 2:870701ee67c4 348 * @param scl I2C clock pin
mcm 2:870701ee67c4 349 * @param addr I2C slave address
mcm 2:870701ee67c4 350 * @param freq I2C frequency in Hz.
mcm 1:c3590e18b517 351 */
mcm 2:870701ee67c4 352 SHT3X ( PinName sda, PinName scl, uint32_t addr, uint32_t freq );
mcm 2:870701ee67c4 353
mcm 2:870701ee67c4 354 /** Delete SHT3X object.
mcm 2:870701ee67c4 355 */
mcm 2:870701ee67c4 356 ~SHT3X();
mcm 1:c3590e18b517 357
mcm 1:c3590e18b517 358 /** It triggers all the raw data in single shot mode.
mcm 1:c3590e18b517 359 */
mcm 1:c3590e18b517 360 SHT3X_status_t SHT3X_OneShotTriggerAllData ( SHT3X_command_registers_single_shot_mode_t mode );
mcm 1:c3590e18b517 361
mcm 1:c3590e18b517 362 /** It gets all the raw data in single shot mode.
mcm 1:c3590e18b517 363 */
mcm 1:c3590e18b517 364 SHT3X_status_t SHT3X_OneShotGetAllRawData ( SHT3X_raw_data_t* rawData );
mcm 1:c3590e18b517 365
mcm 1:c3590e18b517 366 /** It sets periodic measurement with ART (accelerated response time).
mcm 1:c3590e18b517 367 */
mcm 1:c3590e18b517 368 SHT3X_status_t SHT3X_SetPeriodicMeasurementART ( void );
mcm 1:c3590e18b517 369
mcm 1:c3590e18b517 370 /** It sets the break command (stop periodic data acquisition mode).
mcm 1:c3590e18b517 371 */
mcm 1:c3590e18b517 372 SHT3X_status_t SHT3X_SetBreakCommand ( void );
mcm 1:c3590e18b517 373
mcm 1:c3590e18b517 374 /** It perfoms a software reset.
mcm 1:c3590e18b517 375 */
mcm 1:c3590e18b517 376 SHT3X_status_t SHT3X_SetSoftReset ( void );
mcm 1:c3590e18b517 377
mcm 1:c3590e18b517 378 /** It perfoms a reset through a general call address.
mcm 1:c3590e18b517 379 */
mcm 1:c3590e18b517 380 SHT3X_status_t SHT3X_SetGeneralCallReset ( void );
mcm 1:c3590e18b517 381
mcm 1:c3590e18b517 382 /** It sets the heater.
mcm 1:c3590e18b517 383 */
mcm 1:c3590e18b517 384 SHT3X_status_t SHT3X_SetHeater ( SHT3X_command_registers_heater_t heater );
mcm 1:c3590e18b517 385
mcm 1:c3590e18b517 386 /** It gets the status register.
mcm 1:c3590e18b517 387 */
mcm 1:c3590e18b517 388 SHT3X_status_t SHT3X_GetStatus ( SHT3X_status_data_t* status );
mcm 1:c3590e18b517 389
mcm 1:c3590e18b517 390 /** It clears the status register.
mcm 1:c3590e18b517 391 */
mcm 1:c3590e18b517 392 SHT3X_status_t SHT3X_ClearStatus ( void );
mcm 1:c3590e18b517 393
mcm 1:c3590e18b517 394 /** It sets the periodic data aquisition mode.
mcm 1:c3590e18b517 395 */
mcm 1:c3590e18b517 396 SHT3X_status_t SHT3X_SetPeriodicAquisitionMode ( SHT3X_command_registers_periodic_data_mode_t mo );
mcm 1:c3590e18b517 397
mcm 1:c3590e18b517 398 /** It gets the all raw data (in periodic aquisition mode).
mcm 1:c3590e18b517 399 */
mcm 1:c3590e18b517 400 SHT3X_status_t SHT3X_GetAllRawDataFetchData ( SHT3X_raw_data_t* rawData );
mcm 1:c3590e18b517 401
mcm 1:c3590e18b517 402 /** It processes all data: Temperature and Relative Humidity.
mcm 1:c3590e18b517 403 */
mcm 1:c3590e18b517 404 void SHT3X_ProccessData ( SHT3X_raw_data_t rawData, SHT3X_final_data_t* data );
mcm 1:c3590e18b517 405
mcm 1:c3590e18b517 406 private:
mcm 1:c3590e18b517 407 I2C _i2c;
mcm 1:c3590e18b517 408 uint32_t _SHT3X_Addr;
mcm 1:c3590e18b517 409 };
mcm 1:c3590e18b517 410
mcm 1:c3590e18b517 411 #endif /* SHT3X_H */