Added bit shift for the I2C address. Changed return values to int8_t from int.

This commit is contained in:
David Žaitlík
2021-06-13 11:39:30 +02:00
parent 4833a4fb99
commit 178daebf59
66 changed files with 7465 additions and 34 deletions

View File

@@ -47,8 +47,8 @@ typedef enum {
* Function prototypes
*/
int sht4x_send_cmd(sht4x_cmd_t cmd);
int sht4x_read_data(uint8_t *buffer, int len);
int sht4x_measure(int *temperature, int *relative_humidity);
int8_t sht4x_send_cmd(sht4x_cmd_t cmd);
int8_t sht4x_read_data(uint8_t *buffer, int len);
int8_t sht4x_measure(int *temperature, int *relative_humidity);
#endif /* INC_SHT4X_H_ */

View File

@@ -112,15 +112,20 @@ int main(void)
i2c_context_t i2c_context;
i2c_context.i2c = I2C1;
i2c_init(&i2c_context);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
int T, RH;
sht4x_measure(&T, &RH);
while (1)
{
/* USER CODE END WHILE */
int T, RH;
sht4x_measure(&T, &RH);
LL_mDelay(1000);
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */

View File

@@ -7,30 +7,30 @@
#include "sht4x.h"
int sht4x_send_cmd(sht4x_cmd_t cmd)
int8_t sht4x_send_cmd(sht4x_cmd_t cmd)
{
}
int sht4x_read_data(uint8_t *buffer, int len)
int8_t sht4x_read_data(uint8_t *buffer, int len)
{
}
int sht4x_measure(int *temperature, int *relative_humidity)
int8_t sht4x_measure(int *temperature, int *relative_humidity)
{
uint8_t buffer[32];
int result;
// start measurement
buffer[0] = START_MEAS_HIGH_PRECISION;
result = i2c_transmit(SHT4X_I2C_ADDRESS, buffer, 1);
result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1);
if (result != I2C_OK) {
return SHT4X_ERROR;
}
LL_mDelay(100); // 10 ms should be enough
// read out
result = i2c_receive(SHT4X_I2C_ADDRESS, buffer, 6);
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
if (result != I2C_OK) {
return SHT4X_ERROR;
}