Cascoda SDK
Cascoda SDK for building software to run with CA-821x transceivers
hvac_click.h
Go to the documentation of this file.
1 
5 /*
6  * Copyright (c) 2022, Cascoda Ltd.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holder nor the
17  * names of its contributors may be used to endorse or promote products
18  * derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*
33  * Example click interface driver
34 */
35 
36 #ifndef HVAC_CLICK_H
37 #define HVAC_CLICK_H
38 
39 #include <stdint.h>
40 
41 /* operational modes */
42 #define HVAC_MODE_PERIODIC 0 /* periodic mode. wakeup interval has to be >= 5 seconds (data sampling period) */
43 #define HVAC_MODE_PERIODIC_LP \
44  1 /* low-power periodic mode. wakeup interval has to be >= 30 seconds (data sampling period) */
45 #define HVAC_MODE_SINGLE_WAIT 2 /* single-shot mode. 5 seconds wait time for data aquisition */
46 #define HVAC_MODE_SINGLE_WAIT_SLEEP 3 /* single-shot mode with sleep. 5 seconds wait time for data aquisition */
47 #define HVAC_MODE_SINGLE_NEXT 4 /* single shot, read data on next wake-up */
48 
49 #define HVAC_MODE HVAC_MODE_PERIODIC
50 
51 /* perform factory reset on initialisation (power-up) when 1 */
52 #define HVAC_FACTORY_RESET 0
53 
54 /* all scd41 maximum data length */
55 #define SCD41_MAXDLEN 9
56 /* I2C scd41 slave address + memory address (command) */
57 #define SCD41_ADDLEN 3
58 
59 /* timing parameters [ms] */
60 #define SCD41_T_STOP 500 /* scd41 500 ms after stop periodic measurement */
61 #define SCD41_T_CAL 400 /* scd41 400 ms for forced calibration */
62 #define SCD41_T_SELF_TEST 10000 /* scd41 10 seconds for self test */
63 #define SCD41_T_FACTORY_RESET 1200 /* scd41 1200 ms factory reset */
64 #define SCD41_T_REINIT 20 /* scd41 20 ms reinitialisation */
65 #define SCD41_T_MEAS_SINGLE 5000 /* scd41 5 seconds measure single shot */
66 #define SCD41_T_MEAS_SINGLE_RHT 50 /* scd41 50 ms measure single shot for rh and t only */
67 #define SCD41_T_WAKEUP 20 /* scd41 20 ms wakeup time */
68 #define SCD41_T_TIMEOUT 10000 /* scd41 10 seconds timeout waiting for data */
69 #define SCD41_T_WAITPOLL 100 /* scd41 100 ms interval for wait polls */
70 
71 /* data ready status */
72 #define HVAC_SCD41_NEW_DATA_NOT_READY 0x00
73 #define HVAC_SCD41_NEW_DATA_IS_READY 0x01
74 
75 /* target CO2 concentration for forced calibration */
76 #define SCD41_CO2_TARGET 400
77 
78 /* scd41 command set (updated to datasheet version 1.3 - september 2022 */
79 #define SCD41_CMD_START_PERIODIC_MEASUREMENT 0x21B1
80 #define SCD41_CMD_READ_MEASUREMENT 0xEC05
81 #define SCD41_CMD_STOP_PERIODIC_MEASUREMENT 0x3F86
82 #define SCD41_CMD_SET_TEMPERATURE_OFFSET 0x241D
83 #define SCD41_CMD_GET_TEMPERATURE_OFFSET 0x2318
84 #define SCD41_CMD_SET_SENSOR_ALTITUDE 0x2427
85 #define SCD41_CMD_GET_SENSOR_ALTITUDE 0x2322
86 #define SCD41_CMD_SET_AMBIENT_PRESSURE 0xE000
87 #define SCD41_CMD_PERFORM_FORCED_RECALIBRATION 0x362F
88 #define SCD41_CMD_SET_AUTOMATIC_SELF_CALIBRATION_ENABLED 0x2416
89 #define SCD41_CMD_GET_AUTOMATIC_SELF_CALIBRATION_ENABLED 0x2313
90 #define SCD41_CMD_START_LOW_POWER_PERIODIC_MEASUREMENT 0x21AC
91 #define SCD41_CMD_GET_DATA_READY_STATUS 0xE4B8
92 #define SCD41_CMD_PERSIST_SETTINGS 0x3615
93 #define SCD41_CMD_GET_SERIAL_NUMBER 0x3682
94 #define SCD41_CMD_PERFORM_SELF_TEST 0x3639
95 #define SCD41_CMD_PERFORM_FACTORY_RESET 0x3632
96 #define SCD41_CMD_REINIT 0x3646
97 #define SCD41_CMD_MEASURE_SINGLE_SHOT 0x219D
98 #define SCD41_CMD_MEASURE_SINGLE_SHOT_RHT_ONLY 0x2196
99 #define SCD41_CMD_POWER_DOWN 0x36E0
100 #define SCD41_CMD_WAKE_UP 0x36F6
101 /* below commands are not in datasheet but are declared in original code */
102 #define SCD41_CMD_START_ULTRA_LOW_POWER_PERIODIC_MEASUREMENT 0x21A7
103 #define SCD41_CMD_GET_FEATURE_SET_VERSION 0x202F
104 #define SCD41_CMD_GET_AUTOMATIC_SELF_CALIBRATION_INITIAL_PERIOD 0x2340
105 #define SCD41_CMD_SET_AUTOMATIC_SELF_CALIBRATION_INITIAL_PERIOD 0x2445
106 #define SCD41_CMD_GET_AUTOMATIC_SELF_CALIBRATION_STANDARD_PERIOD 0x234B
107 #define SCD41_CMD_SET_AUTOMATIC_SELF_CALIBRATION_STANDARD_PERIOD 0x244E
108 
109 /* data acquisition status */
111 {
112  HVAC_ST_OK = 0, /* read values ok */
113  HVAC_ST_WAITING = 1, /* waiting for data */
114  HVAC_ST_FAIL = 2 /* acquisition failed */
115 };
116 
117 /* new functions */
120 uint8_t MIKROSDK_HVAC_scd41_read_measurement(uint16_t *co2content, int16_t *temperature, int16_t *humitidity);
122 uint8_t MIKROSDK_HVAC_scd41_get_data_ready_status(uint8_t *ready);
123 uint8_t MIKROSDK_HVAC_scd41_set_temperature_offset(int16_t temp_offset);
124 uint8_t MIKROSDK_HVAC_scd41_get_temperature_offset(int16_t *temp_offset);
125 uint8_t MIKROSDK_HVAC_scd41_set_sensor_altitude(uint16_t altitude);
126 uint8_t MIKROSDK_HVAC_scd41_get_sensor_altitude(uint16_t *altitude);
127 uint8_t MIKROSDK_HVAC_scd41_set_ambient_pressure(uint16_t pressure);
132 uint8_t MIKROSDK_HVAC_scd41_get_serial_number(uint16_t *serial_number);
135 uint8_t MIKROSDK_HVAC_scd41_reinit(void);
138 uint8_t MIKROSDK_HVAC_scd41_power_down(void);
139 uint8_t MIKROSDK_HVAC_scd41_wake_up(void);
140 uint8_t MIKROSDK_HVAC_Initialise(void);
141 uint8_t MIKROSDK_HVAC_Reinitialise(void);
142 uint8_t MIKROSDK_HVAC_Acquire(uint16_t *co2content, int16_t *humidity, int16_t *temperature);
143 
144 #endif // HVAC_CLICK_H
uint8_t MIKROSDK_HVAC_scd41_perform_factory_reset(void)
Definition: hvac.c:411
uint8_t MIKROSDK_HVAC_scd41_measure_single_shot(void)
Definition: hvac.c:435
uint8_t MIKROSDK_HVAC_scd41_get_serial_number(uint16_t *serial_number)
Definition: hvac.c:377
uint8_t MIKROSDK_HVAC_scd41_measure_single_shot_rht_only(void)
Definition: hvac.c:447
uint8_t MIKROSDK_HVAC_scd41_get_data_ready_status(uint8_t *ready)
Definition: hvac.c:206
uint8_t MIKROSDK_HVAC_scd41_persist_settings(void)
Definition: hvac.c:367
uint8_t MIKROSDK_HVAC_scd41_start_periodic_measurement(void)
Definition: hvac.c:162
uint8_t MIKROSDK_HVAC_scd41_read_measurement(uint16_t *co2content, int16_t *temperature, int16_t *humitidity)
Definition: hvac.c:180
uint8_t MIKROSDK_HVAC_scd41_set_ambient_pressure(uint16_t pressure)
Definition: hvac.c:290
uint8_t MIKROSDK_HVAC_Reinitialise(void)
Definition: hvac.c:513
uint8_t MIKROSDK_HVAC_scd41_start_low_power_periodic_measurement(void)
Definition: hvac.c:171
uint8_t MIKROSDK_HVAC_Initialise(void)
Definition: hvac.c:482
uint8_t MIKROSDK_HVAC_scd41_get_sensor_altitude(uint16_t *altitude)
Definition: hvac.c:276
uint8_t MIKROSDK_HVAC_scd41_power_down(void)
Definition: hvac.c:460
uint8_t MIKROSDK_HVAC_scd41_reinit(void)
Definition: hvac.c:422
uint8_t MIKROSDK_HVAC_Acquire(uint16_t *co2content, int16_t *humidity, int16_t *temperature)
Definition: hvac.c:524
uint8_t MIKROSDK_HVAC_scd41_get_temperature_offset(int16_t *temp_offset)
Definition: hvac.c:243
uint8_t MIKROSDK_HVAC_scd41_get_automatic_self_calibration_enabled(uint8_t *enabled)
Definition: hvac.c:354
hvac_status
Definition: hvac_click.h:111
@ HVAC_ST_FAIL
Definition: hvac_click.h:114
@ HVAC_ST_WAITING
Definition: hvac_click.h:113
@ HVAC_ST_OK
Definition: hvac_click.h:112
uint8_t MIKROSDK_HVAC_scd41_wake_up(void)
Definition: hvac.c:470
uint8_t MIKROSDK_HVAC_scd41_set_temperature_offset(int16_t temp_offset)
Definition: hvac.c:223
uint8_t MIKROSDK_HVAC_scd41_set_sensor_altitude(uint16_t altitude)
Definition: hvac.c:260
uint8_t MIKROSDK_HVAC_scd41_stop_periodic_measurement(void)
Definition: hvac.c:195
uint8_t MIKROSDK_HVAC_scd41_perform_self_test(void)
Definition: hvac.c:392
uint8_t MIKROSDK_HVAC_scd41_set_automatic_self_calibration_enabled(uint8_t enable)
Definition: hvac.c:335
uint8_t MIKROSDK_HVAC_scd41_perform_forced_calibration(void)
Definition: hvac.c:306