Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
humid_htm_b71.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2011 Martin Mueller <martinmm@pfump.org>
3 *
4 * This file is part of paparazzi.
5 *
6 * paparazzi is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * paparazzi is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with paparazzi; see the file COPYING. If not, write to
18 * the Free Software Foundation, 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 */
22
28/* nice sensor but not very collaborative with others on the i2c bus */
29
30
32
33#include "mcu_periph/sys_time.h"
34#include "mcu_periph/i2c.h"
35#include "mcu_periph/uart.h"
36#include "pprzlink/messages.h"
38
39
40#ifndef HTM_I2C_DEV
41#define HTM_I2C_DEV i2c0
42#endif
43
44#define HTM_SLAVE_ADDR 0x28
45
50
51
53{
55}
56
58{
59 if (sys_time.nb_sec > 1) {
60 /* measurement request: wake up sensor, sample temperature/humidity */
63 }
64}
65
66/* needs 18.5ms delay from measurement request */
68{
69 if (htm_status == HTM_MR_OK) {
70 /* read humid and temp*/
73 }
74}
75
77{
79 switch (htm_status) {
80
81 case HTM_MR:
84 break;
85
86 case HTM_READ_DATA:
87 /* check stale status */
88 if (((htm_trans.buf[0] >> 6) & 0x3) == 0) {
89 /* humidity */
90 humidhtm = ((htm_trans.buf[0] & 0x3F) << 8) | htm_trans.buf[1];
91 fhumidhtm = humidhtm / 163.83;
92 /* temperature */
93 temphtm = (htm_trans.buf[2] << 6) | (htm_trans.buf[3] >> 2);
94 ftemphtm = -40.00 + 0.01 * temphtm;
96 }
98 break;
99
100 default:
102 break;
103 }
104 }
105}
106
volatile uint8_t buf[I2C_BUF_LEN]
Transaction buffer With I2C_BUF_LEN number of bytes.
Definition i2c.h:122
enum I2CTransactionStatus status
Transaction status.
Definition i2c.h:126
bool i2c_transmit(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len)
Submit a write only transaction.
Definition i2c.c:202
bool i2c_receive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint16_t len)
Submit a read only transaction.
Definition i2c.c:212
@ I2CTransSuccess
transaction successfully finished by I2C driver
Definition i2c.h:57
@ I2CTransDone
transaction set to done by user level
Definition i2c.h:59
I2C transaction structure.
Definition i2c.h:93
void humid_htm_event(void)
uint8_t htm_status
#define HTM_I2C_DEV
uint16_t temphtm
struct i2c_transaction htm_trans
float fhumidhtm
void humid_htm_init(void)
uint16_t humidhtm
void humid_htm_read(void)
float ftemphtm
#define HTM_SLAVE_ADDR
void humid_htm_start(void)
@ HTM_MR
@ HTM_IDLE
@ HTM_READ_DATA
@ HTM_MR_OK
Architecture independent I2C (Inter-Integrated Circuit Bus) API.
uint16_t foo
Definition main_demo5.c:58
Architecture independent timing functions.
volatile uint32_t nb_sec
full seconds since startup
Definition sys_time.h:72
arch independent UART (Universal Asynchronous Receiver/Transmitter) API
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.