30#include "pprzlink/messages.h"
35#define SHT_I2C_DEV i2c0
38#define SHT_SLAVE_ADDR 0x80
40#define SHT2_WRITE_USER 0xE6
41#define SHT2_READ_USER 0xE7
42#define SHT2_TRIGGER_TEMP 0xF3
43#define SHT2_TRIGGER_HUMID 0xF5
44#define SHT2_SOFT_RESET 0xFE
109 sht->sht_trans.buf[0] = 0xFA;
110 sht->sht_trans.buf[1] = 0x0F;
115 sht_serial[5] =
sht->sht_trans.buf[0];
116 sht_serial[4] =
sht->sht_trans.buf[2];
117 sht_serial[3] =
sht->sht_trans.buf[4];
118 sht_serial[2] =
sht->sht_trans.buf[6];
121 sht->sht_trans.buf[0] = 0xFC;
122 sht->sht_trans.buf[1] = 0xC9;
127 sht_serial[1] =
sht->sht_trans.buf[0];
128 sht_serial[0] =
sht->sht_trans.buf[1];
129 sht_serial[7] =
sht->sht_trans.buf[3];
130 sht_serial[6] =
sht->sht_trans.buf[4];
132 sht->sht_serial1 = sht_serial[7] << 24 | sht_serial[6] << 16 | sht_serial[5] << 8 | sht_serial[4];
133 sht->sht_serial2 = sht_serial[3] << 24 | sht_serial[2] << 16 | sht_serial[1] << 8 | sht_serial[0];
153 sht->tempsht_i2c = ((
sht->sht_trans.buf[0] << 8) |
sht->sht_trans.buf[1]) & 0xFFFC;
154 sht->ftempsht_i2c = -46.85 + 175.72 / 65536. *
sht->tempsht_i2c;
174 sht->humidsht_i2c = ((
sht->sht_trans.buf[0] << 8) |
sht->sht_trans.buf[1]) & 0xFFFC;
175 sht->fhumidsht_i2c = -6. + 125. / 65536. *
sht->humidsht_i2c;
183 for (i = 0; i < 2; i++) {
185 for (bit = 8; bit > 0; bit--) {
187 crc = (crc << 1) ^ 0x131;
193 if (crc != data[2]) {
void sys_time_usleep(uint32_t us)
sys_time_usleep(uint32_t us)
int pprz_bsem_wait_timeout(pprz_bsem_t *bsem, float timeout)
Wait on semaphore no more than timeout.
void pprz_bsem_init(pprz_bsem_t *bsem, bool taken)
int pprz_thread_create(pprz_thread_t *thread, size_t size, const char *name, uint8_t prio, void(*pf)(void *), void *arg)
Creates a new thread whose stack is dynamically allocated.
void pprz_bsem_signal(pprz_bsem_t *bsem)
Common code for AP and FBW telemetry.
enum I2CTransactionStatus i2c_blocking_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len, float timeout)
Submit a read only transaction and wait for it to complete.
enum I2CTransactionStatus i2c_blocking_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len, float timeout)
Submit a write only transaction and wait for it to complete.
enum I2CTransactionStatus i2c_blocking_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r, float timeout)
Submit a write/read transaction and wait for it to complete.
@ I2CTransSuccess
transaction successfully finished by I2C driver
static struct sht_humid_t sht
#define SHT2_TRIGGER_TEMP
static void sht_read_serial(struct sht_humid_t *sht)
void humid_sht_periodic_i2c(void)
static int sht_read_temp(struct sht_humid_t *sht)
static void humid_sht_thd(void *arg)
static int sht_read_humid(struct sht_humid_t *sht)
static int8_t humid_sht_crc(volatile uint8_t *data)
void humid_sht_init_i2c(void)
#define SHT2_TRIGGER_HUMID
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
signed char int8_t
Typedef defining 8 bit char type.