EVE 1.0
temp-sensor-mcp9808.h
Go to the documentation of this file.
1 #ifndef DRIVER_TEMPERATURE_SENSOR_MCP9808_H
2 #define DRIVER_TEMPERATURE_SENSOR_MCP9808_H
3 /**********************************************************************/
4 /*
5  * Copyright (c) 2014, Jetro AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  * derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONRIBUTORS ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
22  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
28  * OF SUCH DAMAGE.
29  *
30  * This file is part of the EVE platform.
31  */
32 
33 /**
34  * \file
35  * @brief Driver for I2C-based temperature sensor type Microchip MCP9808.
36  *
37  * @author KLO, Jetro AS
38  */ /******************************************************************/
39 
40 #include <dev/i2c-master.h>
41 
42 /**
43  * \defgroup mcp9808 Microchip MCP9808 temperature sensor driver
44  * \ingroup extdrv
45  * \{
46  *
47  * This driver supports the I2C-based temperature sensor type Microchip MCP9808.
48  * The temperature sensor accuracy is typical ±0.25°C from -40°C to +125°C
49  * (max ±0.5°C from -20°C to +100°C, max ±1°C from -40°C to +125°C).
50  * The temperature sensor resolution is selectable from 1/16°C to 0.5°C.
51  * The highest sensor resolution is selected.
52  * Temperature convertion time is typical 250ms.
53  * Temperature measurement range is from -40°C to +125°C.
54  *
55  * The temperature sensor has 3 address lines.
56  * The I2C address range is 0x18 - 0x1f. Max baudrate is 400 kbit/s.
57  * Typical current consumption is 200µA in active mode and
58  * 0.1µA in power down mode.
59  *
60  * Both initialization and disabling of the sensor, and reading of
61  * temperature at 0.1°C or 1.0°C resolution are supported.
62  *
63  * The selected I2C port must be initialized before using the driver.
64  */
65 
66 /***********************************************************************
67  * Global defines
68 ***********************************************************************/
69 /**
70  * temp_sensor_t structure holds I2C port and slave address to be used.
71  *
72  */
74 {
75  const struct i2c_t *I2c;
76  uint8_t SlaveAddress;
77 };
78 
79 /**
80  * @name Functions called from application programs
81  * @{
82  */
83 
84 /**********************************************************************/
85 /**
86  * @brief Name: TempSensorInit\n
87  * Initializes the I2C-based temperature sensor for continously convertion.
88  * I2C address range is 0x18 - 0x1f. Max baudrate is 400 kbit/s.
89  * Higest resolution is selected (1/16°C).
90  * Temperature convertion time is typical 250ms.
91  * Temperature measurement range is from -40°C to +125°C.
92  * Typical current consumption is 200µA.
93  *
94  * @param TempSensor Parameters for the temperature sensor to be used
95  * @return true if OK, else false
96  ***********************************************************************/
97 extern bool TempSensorInit(const struct temp_sensor_t *TempSensor);
98 
99 /**********************************************************************/
100 /**
101  * @brief Name: TempSensorDisable\n
102  * Disables and powers down the I2C-based temperature sensor.
103  * Typical current consumption is 0.1µA in power down mode.
104  *
105  * @param TempSensor Parameters for the temperature sensor to be used
106  * @return true if OK, else false
107  ***********************************************************************/
108 extern bool TempSensorDisable(const struct temp_sensor_t *TempSensor);
109 
110 /**********************************************************************/
111 /**
112  * @brief Name: TempSensorGet\n
113  * Reads temperature value from temperature sensor. Resolution 1.0°C.
114  *
115  * @param TempSensor Parameters for the temperature sensor to be used
116  * @param Value Pointer to where to put the temperature value (int8_t)
117  * @return true if OK, else false
118  ***********************************************************************/
119 extern bool TempSensorGet(const struct temp_sensor_t *TempSensor, int8_t *Value);
120 
121 /**********************************************************************/
122 /**
123  * @brief Name: TempSensorHighResGet\n
124  * Reads temperature value from temperature sensor. Resolution 0.1°C.
125  *
126  * @param TempSensor Parameters for the temperature sensor to be used
127  * @param Value Pointer to where to put the temperature value (int16_t)
128  * @return true if OK, else false
129  ***********************************************************************/
130 extern bool TempSensorHighResGet(const struct temp_sensor_t *TempSensor, int16_t *Value);
131 
132 /** @} */
133 /** \} */
134 
135 #endif //DRIVER_TEMPERATURE_SENSOR_MCP9808_H
bool TempSensorHighResGet(const struct temp_sensor_t *TempSensor, int16_t *Value)
Name: TempSensorHighResGet Reads temperature value from temperature sensor. Resolution 0...
bool TempSensorInit(const struct temp_sensor_t *TempSensor)
Name: TempSensorInit Initializes the I2C-based temperature sensor for continously convertion...
Driver for I2C in nRF52 uC.
bool TempSensorDisable(const struct temp_sensor_t *TempSensor)
Name: TempSensorDisable Disables and powers down the I2C-based temperature sensor. Typical current consumption is 0.1µA in power down mode.
bool TempSensorGet(const struct temp_sensor_t *TempSensor, int8_t *Value)
Name: TempSensorGet Reads temperature value from temperature sensor. Resolution 1.0°C.