Paparazzi UAS  v5.18.0_stable
Paparazzi is a free software Unmanned Aircraft System.
ads1114.c
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2010 ENAC
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 
23 
24 /* driver for the ADC ads1114 (16 bits I2C 860SpS max) from Texas instruments
25  * Navarro & Gorraz & Hattenberger
26  */
27 
28 #include "peripherals/ads1114.h"
29 
30 #if USE_ADS1114_1
31 struct ads1114_periph ads1114_1;
32 #endif
33 #if USE_ADS1114_2
34 struct ads1114_periph ads1114_2;
35 #endif
36 
37 void ads1114_init(void)
38 {
39  /* configure the ads1114_1 */
40 #if USE_ADS1114_1
41  ads1114_1.i2c_addr = ADS1114_1_I2C_ADDR;
42  ads1114_1.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
43  ads1114_1.trans.buf[1] = ADS1114_1_CONFIG_MSB;
44  ads1114_1.trans.buf[2] = ADS1114_1_CONFIG_LSB;
45  i2c_transmit(&ADS1114_I2C_DEV, &ads1114_1.trans, ADS1114_1_I2C_ADDR, 3);
46  ads1114_1.config_done = false;
47  ads1114_1.data_available = false;
48 #endif
49 
50  /* configure the ads1114_2 */
51 #if USE_ADS1114_2
52  ads1114_2.i2c_addr = ADS1114_2_I2C_ADDR;
53  ads1114_2.trans.buf[0] = ADS1114_POINTER_CONFIG_REG;
54  ads1114_2.trans.buf[1] = ADS1114_2_CONFIG_MSB;
55  ads1114_2.trans.buf[2] = ADS1114_2_CONFIG_LSB;
56  i2c_transmit(&ADS1114_I2C_DEV, &ads1114_2.trans, ADS1114_2_I2C_ADDR, 3);
57  ads1114_2.config_done = false;
58  ads1114_2.data_available = false;
59 #endif
60 }
61 
62 
64 {
65  // Config done with success
66  // start new reading when previous is done (and read if success)
67  if (p->config_done && p->trans.status == I2CTransDone) {
68  p->trans.buf[0] = ADS1114_POINTER_CONV_REG;
69  i2c_transceive(&ADS1114_I2C_DEV, &(p->trans), p->i2c_addr, 1, 2);
70  }
71 }
72 
73 
ADS1114_I2C_DEV
#define ADS1114_I2C_DEV
Definition: ads1114.h:113
ADS1114_1_CONFIG_MSB
#define ADS1114_1_CONFIG_MSB
Definition: ads1114.h:75
ADS1114_POINTER_CONFIG_REG
#define ADS1114_POINTER_CONFIG_REG
Definition: ads1114.h:44
ADS1114_2_CONFIG_LSB
#define ADS1114_2_CONFIG_LSB
Definition: ads1114.h:108
ads1114.h
ADS1114_2_CONFIG_MSB
#define ADS1114_2_CONFIG_MSB
Definition: ads1114.h:107
ADS1114_1_I2C_ADDR
#define ADS1114_1_I2C_ADDR
Definition: ads1114.h:36
ads1114_init
void ads1114_init(void)
Definition: ads1114.c:37
ADS1114_2_I2C_ADDR
#define ADS1114_2_I2C_ADDR
Definition: ads1114.h:39
ads1114_read
void ads1114_read(struct ads1114_periph *p)
Definition: ads1114.c:63
i2c_transmit
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:324
i2c_transceive
bool i2c_transceive(struct i2c_periph *p, struct i2c_transaction *t, uint8_t s_addr, uint8_t len_w, uint16_t len_r)
Submit a write/read transaction.
Definition: i2c.c:344
ADS1114_1_CONFIG_LSB
#define ADS1114_1_CONFIG_LSB
Definition: ads1114.h:76
ads1114_periph
Definition: ads1114.h:116
I2CTransDone
@ I2CTransDone
transaction set to done by user level
Definition: i2c.h:59
ADS1114_POINTER_CONV_REG
#define ADS1114_POINTER_CONV_REG
Definition: ads1114.h:43
p
static float p[2][2]
Definition: ins_alt_float.c:268