/* * sht30.c * * Created on: Aug 9, 2021 * Author: Think */ #include #include "stm32l4xx_hal.h" #include "sht30.h" //#define CONFIG_GPIO_I2C #ifdef CONFIG_GPIO_I2C #include "gpio_i2c_sht30.h" #else #include "i2c.h" #endif //#define CONFIG_SHT30_DEBUG #ifdef CONFIG_SHT30_DEBUG #define sht30_print(format,args...) printf(format, ##args) #else #define sht30_print(format,args...) do{} while(0) #endif static int sht30_send_cmd(SHT30_CMD cmd) { uint8_t buf[2]; buf[0] = cmd >> 8; buf[1] = cmd; #ifdef CONFIG_GPIO_I2C return I2C_Master_Transmit(SHT30_ADDR_WR, (uint8_t*)buf, 2); #else return HAL_I2C_Master_Transmit(&hi2c2, SHT30_ADDR_WR, (uint8_t*)buf, 2, 0xFFFF); #endif } static void sht30_soft_reset(void) { sht30_send_cmd(SOFT_RESET_CMD); HAL_Delay(1); } static int sht30_single_shot_measurement(uint8_t *buf, uint8_t buf_size) { uint16_t cmd = HIGH_ENABLED_CMD; /* High with clock stretching */ uint8_t rv; if( !buf || buf_size