LibDriver SCD4X
Loading...
Searching...
No Matches
driver_scd4x.c
Go to the documentation of this file.
1
36
37#include "driver_scd4x.h"
38
42#define CHIP_NAME "Sensirion SCD4X"
43#define MANUFACTURER_NAME "Sensirion"
44#define SUPPLY_VOLTAGE_MIN 2.40f
45#define SUPPLY_VOLTAGE_MAX 5.50f
46#define MAX_CURRENT 205.0f
47#define TEMPERATURE_MIN -10.0f
48#define TEMPERATURE_MAX 60.0f
49#define DRIVER_VERSION 1000
50
54#define SCD4X_ADDRESS (0x62 << 1)
55
59#define SCD4X_COMMAND_START_PERIODIC 0x21B1U
60#define SCD4X_COMMAND_READ 0xEC05U
61#define SCD4X_COMMAND_STOP_PERIODIC 0x3F86U
62#define SCD4X_COMMAND_SET_TEMPERATURE_OFFSET 0x241DU
63#define SCD4X_COMMAND_GET_TEMPERATURE_OFFSET 0x2318U
64#define SCD4X_COMMAND_SET_SENSOR_ALTITUDE 0x2427U
65#define SCD4X_COMMAND_GET_SENSOR_ALTITUDE 0x2322U
66#define SCD4X_COMMAND_SET_AMBIENT_PRESSURE 0xE000U
67#define SCD4X_COMMAND_GET_AMBIENT_PRESSURE 0xE000U
68#define SCD4X_COMMAND_PERFORM_FORCED_RECALIBRATION 0x362FU
69#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION 0x2416U
70#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION 0x2313U
71#define SCD4X_COMMAND_START_LOW_POWER_PERIODIC 0x21ACU
72#define SCD4X_COMMAND_GET_DATA_READY_STATUS 0xE4B8U
73#define SCD4X_COMMAND_PERSIST_SETTINGS 0x3615U
74#define SCD4X_COMMAND_GET_SERIAL_NUMBER 0x3682U
75#define SCD4X_COMMAND_PERFORM_SELF_TEST 0x3639U
76#define SCD4X_COMMAND_PERFORM_FACTORY_RESET 0x3632U
77#define SCD4X_COMMAND_REINIT 0x3646U
78#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT 0x219DU
79#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY 0x2196U
80#define SCD4X_COMMAND_POWER_DOWN 0x36E0U
81#define SCD4X_COMMAND_WAKE_UP 0x36F6U
82#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_INIT_PERIOD 0x2445U
83#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_INIT_PERIOD 0x2340U
84#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD 0x244EU
85#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD 0x234BU
86
90#define SCD4X_CRC8_POLYNOMIAL 0x31
91#define SCD4X_CRC8_INIT 0xFF
92
107static uint8_t a_scd4x_iic_read_with_param(scd4x_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len,
108 uint16_t delay_ms, uint8_t *output, uint16_t output_len)
109{
110 uint8_t buf[16];
111 uint16_t i;
112
113 if ((len + 2) > 16) /* check length */
114 {
115 return 1; /* return error */
116 }
117 memset(buf, 0, sizeof(uint8_t) * 16); /* clear the buffer */
118 buf[0] = (uint8_t)((reg >> 8) & 0xFF); /* set MSB of reg */
119 buf[1] = (uint8_t)(reg & 0xFF); /* set LSB of reg */
120 for (i = 0; i < len; i++)
121 {
122 buf[2 + i] = data[i]; /* copy write data */
123 }
124
125 if (handle->iic_write_cmd(SCD4X_ADDRESS, (uint8_t *)buf, len + 2) != 0) /* write iic command */
126 {
127 return 1; /* write command */
128 }
129 handle->delay_ms(delay_ms); /* delay ms */
130 if (handle->iic_read_cmd(SCD4X_ADDRESS, output, output_len) != 0) /* read data */
131 {
132 return 1; /* write command */
133 }
134 else
135 {
136 return 0; /* success return 0 */
137 }
138}
139
152static uint8_t a_scd4x_iic_read(scd4x_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len, uint16_t delay_ms)
153{
154 uint8_t buf[2];
155
156 memset(buf, 0, sizeof(uint8_t) * 2); /* clear the buffer */
157 buf[0] = (uint8_t)((reg >> 8) & 0xFF); /* set reg MSB */
158 buf[1] = (uint8_t)(reg & 0xFF); /* set reg LSB */
159 if (handle->iic_write_cmd(SCD4X_ADDRESS, (uint8_t *)buf, 2) != 0) /* write command */
160 {
161 return 1; /* return error */
162 }
163 handle->delay_ms(delay_ms); /* delay ms */
164 if (handle->iic_read_cmd(SCD4X_ADDRESS, data, len) != 0) /* read data */
165 {
166 return 1; /* write command */
167 }
168 else
169 {
170 return 0; /* success return 0 */
171 }
172}
173
185static uint8_t a_scd4x_iic_write(scd4x_handle_t *handle, uint16_t reg, uint8_t *data, uint16_t len)
186{
187 uint8_t buf[16];
188 uint16_t i;
189
190 if ((len + 2) > 16) /* check length */
191 {
192 return 1; /* return error */
193 }
194 memset(buf, 0, sizeof(uint8_t) * 16); /* clear the buffer */
195 buf[0] = (uint8_t)((reg >> 8) & 0xFF); /* set MSB of reg */
196 buf[1] = (uint8_t)(reg & 0xFF); /* set LSB of reg */
197 for (i = 0; i < len; i++)
198 {
199 buf[2 + i] = data[i]; /* copy write data */
200 }
201
202 if (handle->iic_write_cmd(SCD4X_ADDRESS, (uint8_t *)buf, len + 2) != 0) /* write iic command */
203 {
204 return 1; /* write command */
205 }
206 else
207 {
208 return 0; /* success return 0 */
209 }
210}
211
219static uint8_t a_scd4x_generate_crc(uint8_t* data, uint8_t count)
220{
221 uint8_t current_byte;
222 uint8_t crc = SCD4X_CRC8_INIT;
223 uint8_t crc_bit;
224
225 for (current_byte = 0; current_byte < count; ++current_byte) /* calculate crc */
226 {
227 crc ^= (data[current_byte]); /* xor data */
228 for (crc_bit = 8; crc_bit > 0; --crc_bit) /* 8 bit */
229 {
230 if ((crc & 0x80) != 0) /* if 7th bit is 1 */
231 {
232 crc = (crc << 1) ^ SCD4X_CRC8_POLYNOMIAL; /* xor */
233 }
234 else
235 {
236 crc = crc << 1; /* left shift 1 */
237 }
238 }
239 }
240
241 return crc; /* return crc */
242}
243
254{
255 if (handle == NULL) /* check handle */
256 {
257 return 2; /* return error */
258 }
259
260 handle->type = type; /* set type */
261
262 return 0; /* success return 0 */
263}
264
274uint8_t scd4x_get_type(scd4x_handle_t *handle, scd4x_t *type)
275{
276 if (handle == NULL) /* check handle */
277 {
278 return 2; /* return error */
279 }
280
281 *type = (scd4x_t)(handle->type); /* get type */
282
283 return 0; /* success return 0 */
284}
285
297{
298 uint8_t res;
299
300 if (handle == NULL) /* check handle */
301 {
302 return 2; /* return error */
303 }
304 if (handle->inited != 1) /* check handle initialization */
305 {
306 return 3; /* return error */
307 }
308
309 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_START_PERIODIC, NULL, 0); /* write config */
310 if (res != 0) /* check result */
311 {
312 handle->debug_print("scd4x: start periodic measurement failed.\n"); /* start periodic measurement failed */
313
314 return 1; /* return error */
315 }
316
317 return 0; /* success return 0 */
318}
319
338uint8_t scd4x_read(scd4x_handle_t *handle, uint16_t *co2_raw, uint16_t *co2_ppm,
339 uint16_t *temperature_raw, float *temperature_s,
340 uint16_t *humidity_raw, float *humidity_s)
341{
342 uint8_t res;
343 uint8_t buf[9];
344 uint16_t prev;
345
346 if (handle == NULL) /* check handle */
347 {
348 return 2; /* return error */
349 }
350 if (handle->inited != 1) /* check handle initialization */
351 {
352 return 3; /* return error */
353 }
354
355 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_DATA_READY_STATUS, buf, 3, 1); /* read config */
356 if (res != 0) /* check result */
357 {
358 handle->debug_print("scd4x: get data ready status failed.\n"); /* get data ready status failed */
359
360 return 1; /* return error */
361 }
362 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
363 {
364 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
365
366 return 4; /* return error */
367 }
368 prev = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set prev */
369 if ((prev & 0x0FFF) == 0) /* check data */
370 {
371 handle->debug_print("scd4x: data is not ready.\n"); /* data is not ready */
372
373 return 5; /* return error */
374 }
375
376 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_READ, buf, 9, 1); /* read data */
377 if (res != 0) /* check result */
378 {
379 handle->debug_print("scd4x: read failed.\n"); /* read failed */
380
381 return 1; /* return error */
382 }
383
384 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
385 {
386 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
387
388 return 4; /* return error */
389 }
390 if (buf[5] != a_scd4x_generate_crc(&buf[3], 2)) /* check crc */
391 {
392 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
393
394 return 4; /* return error */
395 }
396 if (buf[8] != a_scd4x_generate_crc(&buf[6], 2)) /* check crc */
397 {
398 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
399
400 return 4; /* return error */
401 }
402
403 *co2_raw = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set co2 raw */
404 *temperature_raw = (uint16_t)(((uint16_t)buf[3]) << 8) | buf[4]; /* set temperature raw */
405 *humidity_raw = (uint16_t)(((uint16_t)buf[6]) << 8) | buf[7]; /* set humidity raw */
406 *co2_ppm = *co2_raw; /* set co2 ppm */
407 *temperature_s = -45.0f + 175.0f * (float)(*temperature_raw) / 65535.0f; /* set temperature */
408 *humidity_s = 100.0f * (float)(*humidity_raw) / 65535.0f; /* set humidity */
409
410 return 0; /* success return 0 */
411}
412
424{
425 uint8_t res;
426
427 if (handle == NULL) /* check handle */
428 {
429 return 2; /* return error */
430 }
431 if (handle->inited != 1) /* check handle initialization */
432 {
433 return 3; /* return error */
434 }
435
436 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_STOP_PERIODIC, NULL, 0); /* write config */
437 if (res != 0) /* check result */
438 {
439 handle->debug_print("scd4x: stop periodic measurement failed.\n"); /* stop periodic measurement failed */
440
441 return 1; /* return error */
442 }
443 handle->delay_ms(500); /* delay 500ms */
444
445 return 0; /* success return 0 */
446}
447
459uint8_t scd4x_set_temperature_offset(scd4x_handle_t *handle, uint16_t offset)
460{
461 uint8_t res;
462 uint8_t buf[3];
463
464 if (handle == NULL) /* check handle */
465 {
466 return 2; /* return error */
467 }
468 if (handle->inited != 1) /* check handle initialization */
469 {
470 return 3; /* return error */
471 }
472
473 buf[0] = (offset >> 8) & 0xFF; /* msb */
474 buf[1] = (offset >> 0) & 0xFF; /* lsb */
475 buf[2] = a_scd4x_generate_crc(&buf[0], 2); /* set crc */
476 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_SET_TEMPERATURE_OFFSET, buf, 3); /* write config */
477 if (res != 0) /* check result */
478 {
479 handle->debug_print("scd4x: set temperature offset failed.\n"); /* set temperature offset failed */
480
481 return 1; /* return error */
482 }
483 handle->delay_ms(1); /* delay 1ms */
484
485 return 0; /* success return 0 */
486}
487
500uint8_t scd4x_get_temperature_offset(scd4x_handle_t *handle, uint16_t *offset)
501{
502 uint8_t res;
503 uint8_t buf[3];
504
505 if (handle == NULL) /* check handle */
506 {
507 return 2; /* return error */
508 }
509 if (handle->inited != 1) /* check handle initialization */
510 {
511 return 3; /* return error */
512 }
513
514 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_TEMPERATURE_OFFSET, buf, 3, 1); /* read config */
515 if (res != 0) /* check result */
516 {
517 handle->debug_print("scd4x: get temperature offset failed.\n"); /* get temperature offset failed */
518
519 return 1; /* return error */
520 }
521 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
522 {
523 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
524
525 return 4; /* return error */
526 }
527 *offset = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set offset */
528
529 return 0; /* success return 0 */
530}
531
543uint8_t scd4x_temperature_offset_convert_to_register(scd4x_handle_t *handle, float degrees, uint16_t *reg)
544{
545 if (handle == NULL) /* check handle */
546 {
547 return 2; /* return error */
548 }
549 if (handle->inited != 1) /* check handle initialization */
550 {
551 return 3; /* return error */
552 }
553
554 *reg = (uint16_t)(degrees * (65535.0f / 175.0f)); /* convert real data to register data */
555
556 return 0; /* success return 0 */
557}
558
570uint8_t scd4x_temperature_offset_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *degrees)
571{
572 if (handle == NULL) /* check handle */
573 {
574 return 2; /* return error */
575 }
576 if (handle->inited != 1) /* check handle initialization */
577 {
578 return 3; /* return error */
579 }
580
581 *degrees = (float)(reg) * 175.0f / 65535.0f; /* convert raw data to real data */
582
583 return 0; /* success return 0 */
584}
585
597uint8_t scd4x_set_sensor_altitude(scd4x_handle_t *handle, uint16_t altitude)
598{
599 uint8_t res;
600 uint8_t buf[3];
601
602 if (handle == NULL) /* check handle */
603 {
604 return 2; /* return error */
605 }
606 if (handle->inited != 1) /* check handle initialization */
607 {
608 return 3; /* return error */
609 }
610
611 buf[0] = (altitude >> 8) & 0xFF; /* msb */
612 buf[1] = (altitude >> 0) & 0xFF; /* lsb */
613 buf[2] = a_scd4x_generate_crc(&buf[0], 2); /* set crc */
614 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_SET_SENSOR_ALTITUDE , buf, 3); /* write config */
615 if (res != 0) /* check result */
616 {
617 handle->debug_print("scd4x: set sensor altitude failed.\n"); /* set sensor altitude failed */
618
619 return 1; /* return error */
620 }
621 handle->delay_ms(1); /* delay 1ms */
622
623 return 0; /* success return 0 */
624}
625
638uint8_t scd4x_get_sensor_altitude(scd4x_handle_t *handle, uint16_t *altitude)
639{
640 uint8_t res;
641 uint8_t buf[3];
642
643 if (handle == NULL) /* check handle */
644 {
645 return 2; /* return error */
646 }
647 if (handle->inited != 1) /* check handle initialization */
648 {
649 return 3; /* return error */
650 }
651
652 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_SENSOR_ALTITUDE, buf, 3, 1); /* read config */
653 if (res != 0) /* check result */
654 {
655 handle->debug_print("scd4x: get sensor altitude failed.\n"); /* get sensor altitude failed */
656
657 return 1; /* return error */
658 }
659 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
660 {
661 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
662
663 return 4; /* return error */
664 }
665 *altitude = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set offset */
666
667 return 0; /* success return 0 */
668}
669
681uint8_t scd4x_sensor_altitude_convert_to_register(scd4x_handle_t *handle, float m, uint16_t *reg)
682{
683 if (handle == NULL) /* check handle */
684 {
685 return 2; /* return error */
686 }
687 if (handle->inited != 1) /* check handle initialization */
688 {
689 return 3; /* return error */
690 }
691
692 *reg = (uint16_t)(m); /* convert real data to register data */
693
694 return 0; /* success return 0 */
695}
696
708uint8_t scd4x_sensor_altitude_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *m)
709{
710 if (handle == NULL) /* check handle */
711 {
712 return 2; /* return error */
713 }
714 if (handle->inited != 1) /* check handle initialization */
715 {
716 return 3; /* return error */
717 }
718
719 *m = (float)(reg); /* convert raw data to real data */
720
721 return 0; /* success return 0 */
722}
723
735uint8_t scd4x_set_ambient_pressure(scd4x_handle_t *handle, uint16_t pressure)
736{
737 uint8_t res;
738 uint8_t buf[3];
739
740 if (handle == NULL) /* check handle */
741 {
742 return 2; /* return error */
743 }
744 if (handle->inited != 1) /* check handle initialization */
745 {
746 return 3; /* return error */
747 }
748
749 buf[0] = (pressure >> 8) & 0xFF; /* msb */
750 buf[1] = (pressure >> 0) & 0xFF; /* lsb */
751 buf[2] = a_scd4x_generate_crc(&buf[0], 2); /* set crc */
752 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_SET_AMBIENT_PRESSURE , buf, 3); /* write config */
753 if (res != 0) /* check result */
754 {
755 handle->debug_print("scd4x: set ambient pressure failed.\n"); /* set ambient pressure failed */
756
757 return 1; /* return error */
758 }
759 handle->delay_ms(1); /* delay 1ms */
760
761 return 0; /* success return 0 */
762}
763
776uint8_t scd4x_get_ambient_pressure(scd4x_handle_t *handle, uint16_t *pressure)
777{
778 uint8_t res;
779 uint8_t buf[3];
780
781 if (handle == NULL) /* check handle */
782 {
783 return 2; /* return error */
784 }
785 if (handle->inited != 1) /* check handle initialization */
786 {
787 return 3; /* return error */
788 }
789
790 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_AMBIENT_PRESSURE, buf, 3, 1); /* read config */
791 if (res != 0) /* check result */
792 {
793 handle->debug_print("scd4x: get ambient pressure failed.\n"); /* get ambient pressure failed */
794
795 return 1; /* return error */
796 }
797 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
798 {
799 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
800
801 return 4; /* return error */
802 }
803 *pressure = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set offset */
804
805 return 0; /* success return 0 */
806}
807
819uint8_t scd4x_ambient_pressure_convert_to_register(scd4x_handle_t *handle, float pa, uint16_t *reg)
820{
821 if (handle == NULL) /* check handle */
822 {
823 return 2; /* return error */
824 }
825 if (handle->inited != 1) /* check handle initialization */
826 {
827 return 3; /* return error */
828 }
829
830 *reg = (uint16_t)(pa / 100.0f); /* convert real data to register data */
831
832 return 0; /* success return 0 */
833}
834
846uint8_t scd4x_ambient_pressure_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *pa)
847{
848 if (handle == NULL) /* check handle */
849 {
850 return 2; /* return error */
851 }
852 if (handle->inited != 1) /* check handle initialization */
853 {
854 return 3; /* return error */
855 }
856
857 *pa = (float)(reg * 100.0f); /* convert raw data to real data */
858
859 return 0; /* success return 0 */
860}
861
875uint8_t scd4x_perform_forced_recalibration(scd4x_handle_t *handle, uint16_t co2_raw, uint16_t *frc)
876{
877 uint8_t res;
878 uint8_t in_buf[3];
879 uint8_t out_buf[3];
880
881 if (handle == NULL) /* check handle */
882 {
883 return 2; /* return error */
884 }
885 if (handle->inited != 1) /* check handle initialization */
886 {
887 return 3; /* return error */
888 }
889
890 in_buf[0] = (co2_raw >> 8) & 0xFF; /* set msb */
891 in_buf[1] = (co2_raw >> 0) & 0xFF; /* set lsb */
892 in_buf[2] = a_scd4x_generate_crc(&in_buf[0], 2); /* set crc */
893 res = a_scd4x_iic_read_with_param(handle, SCD4X_COMMAND_PERFORM_FORCED_RECALIBRATION,
894 in_buf, 3, 400, out_buf, 3); /* read config */
895 if (res != 0) /* check result */
896 {
897 handle->debug_print("scd4x: perform forced recalibration failed.\n"); /* perform forced recalibration failed */
898
899 return 1; /* return error */
900 }
901 if (out_buf[2] != a_scd4x_generate_crc(&out_buf[0], 2)) /* check crc */
902 {
903 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
904
905 return 4; /* return error */
906 }
907 *frc = (uint16_t)(((uint16_t)out_buf[0]) << 8) | out_buf[1]; /* set frc */
908
909 return 0; /* success return 0 */
910}
911
923uint8_t scd4x_co2_convert_to_register(scd4x_handle_t *handle, float ppm, uint16_t *reg)
924{
925 if (handle == NULL) /* check handle */
926 {
927 return 2; /* return error */
928 }
929 if (handle->inited != 1) /* check handle initialization */
930 {
931 return 3; /* return error */
932 }
933
934 *reg = (uint16_t)(ppm); /* convert real data to register data */
935
936 return 0; /* success return 0 */
937}
938
950uint8_t scd4x_co2_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *ppm)
951{
952 if (handle == NULL) /* check handle */
953 {
954 return 2; /* return error */
955 }
956 if (handle->inited != 1) /* check handle initialization */
957 {
958 return 3; /* return error */
959 }
960
961 *ppm = (float)(reg); /* convert raw data to real data */
962
963 return 0; /* success return 0 */
964}
965
978{
979 uint8_t res;
980 uint8_t buf[3];
981 uint16_t prev;
982
983 if (handle == NULL) /* check handle */
984 {
985 return 2; /* return error */
986 }
987 if (handle->inited != 1) /* check handle initialization */
988 {
989 return 3; /* return error */
990 }
991
992 prev = enable; /* set bool */
993 buf[0] = (prev >> 8) & 0xFF; /* msb */
994 buf[1] = (prev >> 0) & 0xFF; /* lsb */
995 buf[2] = a_scd4x_generate_crc(&buf[0], 2); /* set crc */
996 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION , buf, 3); /* write config */
997 if (res != 0) /* check result */
998 {
999 handle->debug_print("scd4x: set automatic self calibration failed.\n"); /* set automatic self calibration failed */
1000
1001 return 1; /* return error */
1002 }
1003 handle->delay_ms(1); /* delay 1ms */
1004
1005 return 0; /* success return 0 */
1006}
1007
1021{
1022 uint8_t res;
1023 uint8_t buf[3];
1024 uint16_t prev;
1025
1026 if (handle == NULL) /* check handle */
1027 {
1028 return 2; /* return error */
1029 }
1030 if (handle->inited != 1) /* check handle initialization */
1031 {
1032 return 3; /* return error */
1033 }
1034
1035 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION, buf, 3, 1); /* read config */
1036 if (res != 0) /* check result */
1037 {
1038 handle->debug_print("scd4x: get automatic self calibration failed.\n"); /* get automatic self calibration failed */
1039
1040 return 1; /* return error */
1041 }
1042 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
1043 {
1044 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1045
1046 return 4; /* return error */
1047 }
1048 prev = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set prev */
1049 *enable = (scd4x_bool_t)((prev >> 0) & 0x01); /* get bool */
1050
1051 return 0; /* success return 0 */
1052}
1053
1065{
1066 uint8_t res;
1067
1068 if (handle == NULL) /* check handle */
1069 {
1070 return 2; /* return error */
1071 }
1072 if (handle->inited != 1) /* check handle initialization */
1073 {
1074 return 3; /* return error */
1075 }
1076
1077 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_START_LOW_POWER_PERIODIC, NULL, 0); /* write config */
1078 if (res != 0) /* check result */
1079 {
1080 handle->debug_print("scd4x: start low power periodic measurement failed.\n"); /* start low power periodic measurement failed */
1081
1082 return 1; /* return error */
1083 }
1084
1085 return 0; /* success return 0 */
1086}
1087
1101{
1102 uint8_t res;
1103 uint8_t buf[3];
1104 uint16_t prev;
1105
1106 if (handle == NULL) /* check handle */
1107 {
1108 return 2; /* return error */
1109 }
1110 if (handle->inited != 1) /* check handle initialization */
1111 {
1112 return 3; /* return error */
1113 }
1114
1115 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_DATA_READY_STATUS, buf, 3, 1); /* read config */
1116 if (res != 0) /* check result */
1117 {
1118 handle->debug_print("scd4x: get data ready status failed.\n"); /* get data ready status failed */
1119
1120 return 1; /* return error */
1121 }
1122 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
1123 {
1124 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1125
1126 return 4; /* return error */
1127 }
1128 prev = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set prev */
1129 if ((prev & 0x0FFF) != 0) /* check data */
1130 {
1131 *enable = SCD4X_BOOL_TRUE; /* ready */
1132 }
1133 else
1134 {
1135 *enable = SCD4X_BOOL_FALSE; /* not ready */
1136 }
1137
1138 return 0; /* success return 0 */
1139}
1140
1152{
1153 uint8_t res;
1154
1155 if (handle == NULL) /* check handle */
1156 {
1157 return 2; /* return error */
1158 }
1159 if (handle->inited != 1) /* check handle initialization */
1160 {
1161 return 3; /* return error */
1162 }
1163
1164 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_PERSIST_SETTINGS, NULL, 0); /* write config */
1165 if (res != 0) /* check result */
1166 {
1167 handle->debug_print("scd4x: persist settings failed.\n"); /* persist settings failed */
1168
1169 return 1; /* return error */
1170 }
1171 handle->delay_ms(800); /* delay 800ms */
1172
1173 return 0; /* success return 0 */
1174}
1175
1188uint8_t scd4x_get_serial_number(scd4x_handle_t *handle, uint16_t number[3])
1189{
1190 uint8_t res;
1191 uint8_t buf[9];
1192
1193 if (handle == NULL) /* check handle */
1194 {
1195 return 2; /* return error */
1196 }
1197 if (handle->inited != 1) /* check handle initialization */
1198 {
1199 return 3; /* return error */
1200 }
1201
1202 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_SERIAL_NUMBER, buf, 9, 1); /* read config */
1203 if (res != 0) /* check result */
1204 {
1205 handle->debug_print("scd4x: get serial number failed.\n"); /* get serial number failed */
1206
1207 return 1; /* return error */
1208 }
1209 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
1210 {
1211 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1212
1213 return 4; /* return error */
1214 }
1215 if (buf[5] != a_scd4x_generate_crc(&buf[3], 2)) /* check crc */
1216 {
1217 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1218
1219 return 4; /* return error */
1220 }
1221 if (buf[8] != a_scd4x_generate_crc(&buf[6], 2)) /* check crc */
1222 {
1223 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1224
1225 return 4; /* return error */
1226 }
1227 number[0] = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set number0 */
1228 number[1] = (uint16_t)(((uint16_t)buf[3]) << 8) | buf[4]; /* set number1 */
1229 number[2] = (uint16_t)(((uint16_t)buf[6]) << 8) | buf[7]; /* set number2 */
1230
1231 return 0; /* success return 0 */
1232}
1233
1246uint8_t scd4x_perform_self_test(scd4x_handle_t *handle, scd4x_bool_t *malfunction_detected)
1247{
1248 uint8_t res;
1249 uint8_t buf[3];
1250 uint16_t prev;
1251
1252 if (handle == NULL) /* check handle */
1253 {
1254 return 2; /* return error */
1255 }
1256 if (handle->inited != 1) /* check handle initialization */
1257 {
1258 return 3; /* return error */
1259 }
1260
1261 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_PERFORM_SELF_TEST, buf, 3, 10000); /* read config */
1262 if (res != 0) /* check result */
1263 {
1264 handle->debug_print("scd4x: perform self test failed.\n"); /* perform self test failed */
1265
1266 return 1; /* return error */
1267 }
1268 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
1269 {
1270 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1271
1272 return 4; /* return error */
1273 }
1274 prev = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* set prev */
1275 if (prev != 0) /* check data */
1276 {
1277 *malfunction_detected = SCD4X_BOOL_TRUE; /* true */
1278 }
1279 else
1280 {
1281 *malfunction_detected = SCD4X_BOOL_FALSE; /* false */
1282 }
1283
1284 return 0; /* success return 0 */
1285}
1286
1298{
1299 uint8_t res;
1300
1301 if (handle == NULL) /* check handle */
1302 {
1303 return 2; /* return error */
1304 }
1305 if (handle->inited != 1) /* check handle initialization */
1306 {
1307 return 3; /* return error */
1308 }
1309
1310 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_PERFORM_FACTORY_RESET, NULL, 0); /* write config */
1311 if (res != 0) /* check result */
1312 {
1313 handle->debug_print("scd4x: perform factory reset failed.\n"); /* perform factory reset failed */
1314
1315 return 1; /* return error */
1316 }
1317 handle->delay_ms(1200); /* delay 1200ms */
1318
1319 return 0; /* success return 0 */
1320}
1321
1333{
1334 uint8_t res;
1335
1336 if (handle == NULL) /* check handle */
1337 {
1338 return 2; /* return error */
1339 }
1340 if (handle->inited != 1) /* check handle initialization */
1341 {
1342 return 3; /* return error */
1343 }
1344
1345 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_REINIT, NULL, 0); /* write config */
1346 if (res != 0) /* check result */
1347 {
1348 handle->debug_print("scd4x: reinit failed.\n"); /* reinit failed */
1349
1350 return 1; /* return error */
1351 }
1352 handle->delay_ms(30); /* delay 30ms */
1353
1354 return 0; /* success return 0 */
1355}
1356
1369{
1370 uint8_t res;
1371
1372 if (handle == NULL) /* check handle */
1373 {
1374 return 2; /* return error */
1375 }
1376 if (handle->inited != 1) /* check handle initialization */
1377 {
1378 return 3; /* return error */
1379 }
1380 if (handle->type == SCD40) /* check type */
1381 {
1382 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1383
1384 return 4; /* return error */
1385 }
1386
1387 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_MEASURE_SINGLE_SHOT, NULL, 0); /* write config */
1388 if (res != 0) /* check result */
1389 {
1390 handle->debug_print("scd4x: measure single shot failed.\n"); /* measure single shot failed */
1391
1392 return 1; /* return error */
1393 }
1394 handle->delay_ms(5000); /* delay 5000ms */
1395
1396 return 0; /* success return 0 */
1397}
1398
1411{
1412 uint8_t res;
1413
1414 if (handle == NULL) /* check handle */
1415 {
1416 return 2; /* return error */
1417 }
1418 if (handle->inited != 1) /* check handle initialization */
1419 {
1420 return 3; /* return error */
1421 }
1422 if (handle->type == SCD40) /* check type */
1423 {
1424 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1425
1426 return 4; /* return error */
1427 }
1428
1429 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY, NULL, 0); /* write config */
1430 if (res != 0) /* check result */
1431 {
1432 handle->debug_print("scd4x: measure single shot rht only failed.\n"); /* measure single shot rht only failed */
1433
1434 return 1; /* return error */
1435 }
1436 handle->delay_ms(50); /* delay 50ms */
1437
1438 return 0; /* success return 0 */
1439}
1440
1453{
1454 uint8_t res;
1455
1456 if (handle == NULL) /* check handle */
1457 {
1458 return 2; /* return error */
1459 }
1460 if (handle->inited != 1) /* check handle initialization */
1461 {
1462 return 3; /* return error */
1463 }
1464 if (handle->type == SCD40) /* check type */
1465 {
1466 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1467
1468 return 4; /* return error */
1469 }
1470
1471 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_POWER_DOWN, NULL, 0); /* write config */
1472 if (res != 0) /* check result */
1473 {
1474 handle->debug_print("scd4x: power down failed.\n"); /* power down failed */
1475
1476 return 1; /* return error */
1477 }
1478 handle->delay_ms(1); /* delay 1ms */
1479
1480 return 0; /* success return 0 */
1481}
1482
1495{
1496 if (handle == NULL) /* check handle */
1497 {
1498 return 2; /* return error */
1499 }
1500 if (handle->inited != 1) /* check handle initialization */
1501 {
1502 return 3; /* return error */
1503 }
1504 if (handle->type == SCD40) /* check type */
1505 {
1506 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1507
1508 return 4; /* return error */
1509 }
1510
1511 (void)a_scd4x_iic_write(handle, SCD4X_COMMAND_WAKE_UP, NULL, 0); /* write config */
1512 handle->delay_ms(30); /* delay 30ms */
1513
1514 return 0; /* success return 0 */
1515}
1516
1531{
1532 uint8_t res;
1533 uint8_t buf[3];
1534
1535 if (handle == NULL) /* check handle */
1536 {
1537 return 2; /* return error */
1538 }
1539 if (handle->inited != 1) /* check handle initialization */
1540 {
1541 return 3; /* return error */
1542 }
1543 if (handle->type == SCD40) /* check type */
1544 {
1545 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1546
1547 return 4; /* return error */
1548 }
1549 if ((hour % 4) != 0) /* check hour */
1550 {
1551 handle->debug_print("scd4x: hour is not integer multiples of 4.\n"); /* hour is not integer multiples of 4 */
1552
1553 return 5; /* return error */
1554 }
1555
1556 buf[0] = (hour >> 8) & 0xFF; /* msb */
1557 buf[1] = (hour >> 0) & 0xFF; /* lsb */
1558 buf[2] = a_scd4x_generate_crc(&buf[0], 2); /* crc */
1559 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_INIT_PERIOD, buf, 3); /* write config */
1560 if (res != 0) /* check result */
1561 {
1562 handle->debug_print("scd4x: set automatic self calibration initial period failed.\n"); /* set automatic self calibration initial period failed */
1563
1564 return 1; /* return error */
1565 }
1566 handle->delay_ms(1); /* delay 1ms */
1567
1568 return 0; /* success return 0 */
1569}
1570
1585{
1586 uint8_t res;
1587 uint8_t buf[3];
1588
1589 if (handle == NULL) /* check handle */
1590 {
1591 return 2; /* return error */
1592 }
1593 if (handle->inited != 1) /* check handle initialization */
1594 {
1595 return 3; /* return error */
1596 }
1597 if (handle->type == SCD40) /* check type */
1598 {
1599 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1600
1601 return 4; /* return error */
1602 }
1603
1604 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_INIT_PERIOD, buf, 3, 1); /* read config */
1605 if (res != 0) /* check result */
1606 {
1607 handle->debug_print("scd4x: get automatic self calibration initial period failed.\n"); /* get automatic self calibration initial period failed */
1608
1609 return 1; /* return error */
1610 }
1611 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
1612 {
1613 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1614
1615 return 5; /* return error */
1616 }
1617 *hour = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get hour */
1618
1619 return 0; /* success return 0 */
1620}
1621
1636{
1637 uint8_t res;
1638 uint8_t buf[3];
1639
1640 if (handle == NULL) /* check handle */
1641 {
1642 return 2; /* return error */
1643 }
1644 if (handle->inited != 1) /* check handle initialization */
1645 {
1646 return 3; /* return error */
1647 }
1648 if (handle->type == SCD40) /* check type */
1649 {
1650 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1651
1652 return 4; /* return error */
1653 }
1654 if ((hour % 4) != 0) /* check hour */
1655 {
1656 handle->debug_print("scd4x: hour is not integer multiples of 4.\n"); /* hour is not integer multiples of 4 */
1657
1658 return 5; /* return error */
1659 }
1660
1661 buf[0] = (hour >> 8) & 0xFF; /* msb */
1662 buf[1] = (hour >> 0) & 0xFF; /* lsb */
1663 buf[2] = a_scd4x_generate_crc(&buf[0], 2); /* crc */
1664 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD, buf, 3); /* write config */
1665 if (res != 0) /* check result */
1666 {
1667 handle->debug_print("scd4x: set automatic self calibration standard period failed.\n"); /* set automatic self calibration standard period failed */
1668
1669 return 1; /* return error */
1670 }
1671 handle->delay_ms(1); /* delay 1ms */
1672
1673 return 0; /* success return 0 */
1674}
1675
1690{
1691 uint8_t res;
1692 uint8_t buf[3];
1693
1694 if (handle == NULL) /* check handle */
1695 {
1696 return 2; /* return error */
1697 }
1698 if (handle->inited != 1) /* check handle initialization */
1699 {
1700 return 3; /* return error */
1701 }
1702 if (handle->type == SCD40) /* check type */
1703 {
1704 handle->debug_print("scd4x: only scd41 and scd43 has this function.\n"); /* only scd41 and scd43 has this function */
1705
1706 return 4; /* return error */
1707 }
1708
1709 res = a_scd4x_iic_read(handle, SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD, buf, 3, 1); /* read config */
1710 if (res != 0) /* check result */
1711 {
1712 handle->debug_print("scd4x: get automatic self calibration standard period failed.\n"); /* get automatic self calibration standard period failed */
1713
1714 return 1; /* return error */
1715 }
1716 if (buf[2] != a_scd4x_generate_crc(&buf[0], 2)) /* check crc */
1717 {
1718 handle->debug_print("scd4x: crc is error.\n"); /* crc is error */
1719
1720 return 5; /* return error */
1721 }
1722 *hour = (uint16_t)(((uint16_t)buf[0]) << 8) | buf[1]; /* get hour */
1723
1724 return 0; /* success return 0 */
1725}
1726
1738{
1739 if (handle == NULL) /* check handle */
1740 {
1741 return 2; /* return error */
1742 }
1743 if (handle->debug_print == NULL) /* check debug_print */
1744 {
1745 return 3; /* return error */
1746 }
1747 if (handle->iic_init == NULL) /* check iic_init */
1748 {
1749 handle->debug_print("scd4x: iic_init is null.\n"); /* iic_init is null */
1750
1751 return 3; /* return error */
1752 }
1753 if (handle->iic_deinit == NULL) /* check iic_deinit */
1754 {
1755 handle->debug_print("scd4x: iic_deinit is null.\n"); /* iic_deinit is null */
1756
1757 return 3; /* return error */
1758 }
1759 if (handle->iic_write_cmd == NULL) /* check iic_write_cmd */
1760 {
1761 handle->debug_print("scd4x: iic_write_cmd is null.\n"); /* iic_write_cmd is null */
1762
1763 return 3; /* return error */
1764 }
1765 if (handle->iic_read_cmd == NULL) /* check iic_read_cmd */
1766 {
1767 handle->debug_print("scd4x: iic_read_cmd is null.\n"); /* iic_read_cmd is null */
1768
1769 return 3; /* return error */
1770 }
1771 if (handle->delay_ms == NULL) /* check delay_ms */
1772 {
1773 handle->debug_print("scd4x: delay_ms is null.\n"); /* delay_ms is null */
1774
1775 return 3; /* return error */
1776 }
1777
1778 if (handle->iic_init() != 0) /* iic init */
1779 {
1780 handle->debug_print("scd4x: iic init failed.\n"); /* iic init failed */
1781
1782 return 1; /* return error */
1783 }
1784 handle->inited = 1; /* flag finish initialization */
1785
1786 return 0; /* success return 0 */
1787}
1788
1801{
1802 uint8_t res;
1803
1804 if (handle == NULL) /* check handle */
1805 {
1806 return 2; /* return error */
1807 }
1808 if (handle->inited != 1) /* check handle initialization */
1809 {
1810 return 3; /* return error */
1811 }
1812
1813 res = a_scd4x_iic_write(handle, SCD4X_COMMAND_STOP_PERIODIC, NULL, 0); /* write config */
1814 if (res != 0) /* check result */
1815 {
1816 handle->debug_print("scd4x: stop periodic measurement failed.\n"); /* stop periodic measurement failed */
1817
1818 return 4; /* return error */
1819 }
1820 if (handle->iic_deinit() != 0) /* iic deinit */
1821 {
1822 handle->debug_print("scd4x: iic close failed.\n"); /* iic close failed */
1823
1824 return 3; /* return error */
1825 }
1826 handle->inited = 0; /* flag close initialization */
1827
1828 return 0; /* success return 0 */
1829}
1830
1844uint8_t scd4x_set_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
1845{
1846 if (handle == NULL) /* check handle */
1847 {
1848 return 2; /* return error */
1849 }
1850 if (handle->inited != 1) /* check handle initialization */
1851 {
1852 return 3; /* return error */
1853 }
1854
1855 return a_scd4x_iic_write(handle, reg, buf, len); /* write data */
1856}
1857
1872uint8_t scd4x_get_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len, uint16_t delay_ms)
1873{
1874 if (handle == NULL) /* check handle */
1875 {
1876 return 2; /* return error */
1877 }
1878 if (handle->inited != 1) /* check handle initialization */
1879 {
1880 return 3; /* return error */
1881 }
1882
1883 return a_scd4x_iic_read(handle, reg, buf, len, delay_ms); /* read data */
1884}
1885
1895{
1896 if (info == NULL) /* check handle */
1897 {
1898 return 2; /* return error */
1899 }
1900
1901 memset(info, 0, sizeof(scd4x_info_t)); /* initialize scd4x info structure */
1902 strncpy(info->chip_name, CHIP_NAME, 32); /* copy chip name */
1903 strncpy(info->manufacturer_name, MANUFACTURER_NAME, 32); /* copy manufacturer name */
1904 strncpy(info->interface, "IIC", 8); /* copy interface name */
1905 info->supply_voltage_min_v = SUPPLY_VOLTAGE_MIN; /* set minimal supply voltage */
1906 info->supply_voltage_max_v = SUPPLY_VOLTAGE_MAX; /* set maximum supply voltage */
1907 info->max_current_ma = MAX_CURRENT; /* set maximum current */
1908 info->temperature_max = TEMPERATURE_MAX; /* set minimal temperature */
1909 info->temperature_min = TEMPERATURE_MIN; /* set maximum temperature */
1910 info->driver_version = DRIVER_VERSION; /* set driver version */
1911
1912 return 0; /* success return 0 */
1913}
#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_INIT_PERIOD
#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION
#define SCD4X_CRC8_POLYNOMIAL
crc8 definition
#define SCD4X_COMMAND_PERFORM_FORCED_RECALIBRATION
#define MAX_CURRENT
#define SCD4X_COMMAND_STOP_PERIODIC
#define SCD4X_COMMAND_PERFORM_FACTORY_RESET
#define SCD4X_COMMAND_SET_TEMPERATURE_OFFSET
#define SCD4X_COMMAND_POWER_DOWN
#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT
#define SCD4X_COMMAND_GET_SERIAL_NUMBER
#define SUPPLY_VOLTAGE_MAX
#define SCD4X_COMMAND_SET_SENSOR_ALTITUDE
#define SCD4X_COMMAND_START_LOW_POWER_PERIODIC
#define SCD4X_COMMAND_PERSIST_SETTINGS
#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION
#define SCD4X_COMMAND_REINIT
#define SCD4X_COMMAND_GET_TEMPERATURE_OFFSET
#define SCD4X_COMMAND_PERFORM_SELF_TEST
#define SCD4X_ADDRESS
chip address definition
#define TEMPERATURE_MAX
#define SCD4X_COMMAND_READ
#define SCD4X_COMMAND_GET_SENSOR_ALTITUDE
#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_INIT_PERIOD
#define SCD4X_COMMAND_START_PERIODIC
chip command definition
#define MANUFACTURER_NAME
#define TEMPERATURE_MIN
#define SCD4X_COMMAND_WAKE_UP
#define SUPPLY_VOLTAGE_MIN
#define SCD4X_CRC8_INIT
#define SCD4X_COMMAND_GET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD
#define SCD4X_COMMAND_GET_DATA_READY_STATUS
#define SCD4X_COMMAND_SET_AUTO_SELF_CALIBRATION_STANDARD_PERIOD
#define CHIP_NAME
chip information definition
#define DRIVER_VERSION
#define SCD4X_COMMAND_SET_AMBIENT_PRESSURE
#define SCD4X_COMMAND_MEASURE_SINGLE_SHOT_RHT_ONLY
#define SCD4X_COMMAND_GET_AMBIENT_PRESSURE
driver scd4x header file
uint8_t scd4x_wake_up(scd4x_handle_t *handle)
wake up
uint8_t scd4x_set_automatic_self_calibration_standard_period(scd4x_handle_t *handle, uint16_t hour)
set automatic self calibration standard period
uint8_t scd4x_set_automatic_self_calibration_initial_period(scd4x_handle_t *handle, uint16_t hour)
set automatic self calibration initial period
uint8_t scd4x_power_down(scd4x_handle_t *handle)
power down
uint8_t scd4x_measure_single_shot(scd4x_handle_t *handle)
measure single shot
uint8_t scd4x_get_automatic_self_calibration_standard_period(scd4x_handle_t *handle, uint16_t *hour)
get automatic self calibration standard period
uint8_t scd4x_get_automatic_self_calibration_initial_period(scd4x_handle_t *handle, uint16_t *hour)
get automatic self calibration initial period
uint8_t scd4x_measure_single_shot_rht_only(scd4x_handle_t *handle)
measure single shot rht only
struct scd4x_info_s scd4x_info_t
scd4x information structure definition
uint8_t scd4x_get_type(scd4x_handle_t *handle, scd4x_t *type)
get type
uint8_t scd4x_get_data_ready_status(scd4x_handle_t *handle, scd4x_bool_t *enable)
get data ready status
uint8_t scd4x_stop_periodic_measurement(scd4x_handle_t *handle)
stop periodic measurement
uint8_t scd4x_get_sensor_altitude(scd4x_handle_t *handle, uint16_t *altitude)
get sensor altitude
uint8_t scd4x_sensor_altitude_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *m)
convert the register raw data to the sensor altitude
uint8_t scd4x_set_temperature_offset(scd4x_handle_t *handle, uint16_t offset)
set temperature offset
uint8_t scd4x_get_serial_number(scd4x_handle_t *handle, uint16_t number[3])
get serial number
uint8_t scd4x_deinit(scd4x_handle_t *handle)
close the chip
uint8_t scd4x_get_automatic_self_calibration(scd4x_handle_t *handle, scd4x_bool_t *enable)
get automatic self calibration status
uint8_t scd4x_set_ambient_pressure(scd4x_handle_t *handle, uint16_t pressure)
set ambient pressure
uint8_t scd4x_co2_convert_to_register(scd4x_handle_t *handle, float ppm, uint16_t *reg)
convert the co2 to the register raw data
uint8_t scd4x_read(scd4x_handle_t *handle, uint16_t *co2_raw, uint16_t *co2_ppm, uint16_t *temperature_raw, float *temperature_s, uint16_t *humidity_raw, float *humidity_s)
read data
uint8_t scd4x_set_type(scd4x_handle_t *handle, scd4x_t type)
set type
uint8_t scd4x_get_temperature_offset(scd4x_handle_t *handle, uint16_t *offset)
get temperature offset
uint8_t scd4x_temperature_offset_convert_to_register(scd4x_handle_t *handle, float degrees, uint16_t *reg)
convert the temperature offset to the register raw data
uint8_t scd4x_reinit(scd4x_handle_t *handle)
reinit
uint8_t scd4x_ambient_pressure_convert_to_register(scd4x_handle_t *handle, float pa, uint16_t *reg)
convert the ambient pressure to the register raw data
uint8_t scd4x_co2_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *ppm)
convert the register raw data to the co2
uint8_t scd4x_set_automatic_self_calibration(scd4x_handle_t *handle, scd4x_bool_t enable)
enable or disable automatic self calibration
uint8_t scd4x_init(scd4x_handle_t *handle)
initialize the chip
uint8_t scd4x_perform_forced_recalibration(scd4x_handle_t *handle, uint16_t co2_raw, uint16_t *frc)
perform forced recalibration
uint8_t scd4x_perform_factory_reset(scd4x_handle_t *handle)
perform factory reset
uint8_t scd4x_persist_settings(scd4x_handle_t *handle)
persist settings
uint8_t scd4x_start_periodic_measurement(scd4x_handle_t *handle)
start periodic measurement
struct scd4x_handle_s scd4x_handle_t
scd4x handle structure definition
uint8_t scd4x_perform_self_test(scd4x_handle_t *handle, scd4x_bool_t *malfunction_detected)
perform self test
uint8_t scd4x_info(scd4x_info_t *info)
get chip information
uint8_t scd4x_ambient_pressure_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *pa)
convert the register raw data to the ambient pressure
uint8_t scd4x_set_sensor_altitude(scd4x_handle_t *handle, uint16_t altitude)
set sensor altitude
uint8_t scd4x_sensor_altitude_convert_to_register(scd4x_handle_t *handle, float m, uint16_t *reg)
convert the sensor altitude to the register raw data
uint8_t scd4x_temperature_offset_convert_to_data(scd4x_handle_t *handle, uint16_t reg, float *degrees)
convert the register raw data to the temperature offset
scd4x_t
scd4x type enumeration definition
scd4x_bool_t
scd4x bool enumeration definition
uint8_t scd4x_get_ambient_pressure(scd4x_handle_t *handle, uint16_t *pressure)
get ambient pressure
uint8_t scd4x_start_low_power_periodic_measurement(scd4x_handle_t *handle)
start low power periodic measurement
@ SCD40
@ SCD4X_BOOL_TRUE
@ SCD4X_BOOL_FALSE
uint8_t scd4x_set_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len)
set the chip register
uint8_t scd4x_get_reg(scd4x_handle_t *handle, uint16_t reg, uint8_t *buf, uint16_t len, uint16_t delay_ms)
get the chip register
void(* delay_ms)(uint32_t ms)
void(* debug_print)(const char *const fmt,...)
uint8_t(* iic_init)(void)
uint8_t(* iic_read_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
uint8_t(* iic_deinit)(void)
uint8_t(* iic_write_cmd)(uint8_t addr, uint8_t *buf, uint16_t len)
float temperature_max
float supply_voltage_max_v
uint32_t driver_version
float temperature_min
float max_current_ma
char manufacturer_name[32]
float supply_voltage_min_v
char interface[8]
char chip_name[32]