Added bit shift for the I2C address. Changed return values to int8_t from int.
This commit is contained in:
@@ -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_ */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user