BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
mcp9808.h
Go to the documentation of this file.
1 /* Copyright 2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef BSP430_SENSORS_MCP9808_H
33 #define BSP430_SENSORS_MCP9808_H
34 
52 #include <bsp430/serial.h>
53 #include <bsp430/periph/timer.h>
54 
57 #define BSP430_SENSORS_MCP9808_I2C_ADDRESS 0x18
58 
60 #define BSP430_SENSORS_MCP9808_REGNO_CONFIG 1
61 
63 #define BSP430_SENSORS_MCP9808_REGNO_TUPPER 2
64 
66 #define BSP430_SENSORS_MCP9808_REGNO_TLOWER 3
67 
69 #define BSP430_SENSORS_MCP9808_REGNO_TCRIT 4
70 
72 #define BSP430_SENSORS_MCP9808_REGNO_TA 5
73 
75 #define BSP430_SENSORS_MCP9808_REGNO_MFGID 6
76 
78 #define BSP430_SENSORS_MCP9808_REGNO_DEVID 7
79 
81 #define BSP430_SENSORS_MCP9808_REGNO_RESOLUTION 8
82 
84 #define BSP430_SENSORS_MCP9808_CONFIG_HYST0p0 0x0000
85 
87 #define BSP430_SENSORS_MCP9808_CONFIG_HYST1p5 0x0200
88 
90 #define BSP430_SENSORS_MCP9808_CONFIG_HYST3p0 0x0400
91 
93 #define BSP430_SENSORS_MCP9808_CONFIG_HYST6p0 0x0600
94 
96 #define BSP430_SENSORS_MCP9808_CONFIG_HYSTM 0x0600
97 
100 #define BSP430_SENSORS_MCP9808_CONFIG_SHDN 0x0010
101 
103 #define BSP430_SENSORS_MCP9808_CONFIG_CRITLCK 0x0080
104 
106 #define BSP430_SENSORS_MCP9808_CONFIG_WNDWLCK 0x0040
107 
109 #define BSP430_SENSORS_MCP9808_CONFIG_INTCLR 0x0020
110 
112 #define BSP430_SENSORS_MCP9808_CONFIG_ALRSTAT 0x0010
113 
115 #define BSP430_SENSORS_MCP9808_CONFIG_ALRCTL 0x0008
116 
118 #define BSP430_SENSORS_MCP9808_CONFIG_ALRSEL 0x0004
119 
121 #define BSP430_SENSORS_MCP9808_CONFIG_ALRPOL 0x0002
122 
124 #define BSP430_SENSORS_MCP9808_CONFIG_ALRMOD 0x0001
125 
127 #define BSP430_SENSORS_MCP9808_CONVERSION_ms(res_) ((0 == (res_)) ? 30 \
128  : (1 == (res_)) ? 35 \
129  : (2 == (res_)) ? 130 \
130  : 250)
131 
134 #define BSP430_SENSORS_MCP9808_TEMP_CRIT 0x8000
135 
138 #define BSP430_SENSORS_MCP9808_TEMP_HIGH 0x4000
139 
142 #define BSP430_SENSORS_MCP9808_TEMP_LOW 0x2000
143 
145 #define BSP430_SENSORS_MCP9808_TEMP_SIGN 0x1000
146 
148 #define BSP430_SENSORS_MCP9808_TEMP_MASK 0x0FFF
149 
152 #define BSP430_SENSORS_MCP9808_OFFSET_Kd160 (43704UL)
153 
155 static BSP430_CORE_INLINE int
157 {
158  long v = 10 * (raw & BSP430_SENSORS_MCP9808_TEMP_MASK);
160  /* Convert to K/1600 then divide by 16 to get K/100 = cK. */
161  v = (v * 10) / 16;
163  v = -v;
164  }
165  return (int)v;
166 }
167 
168 #endif /* BSP430_SENSORS_MCP9808_H */
static BSP430_CORE_INLINE int iBSP430sensorsMCP9808tempFromRaw_cK(uint16_t raw)
Definition: mcp9808.h:156
Hardware presentation/abstraction for generic timers (Timer_A/Timer_B)
#define BSP430_SENSORS_MCP9808_OFFSET_Kd160
Definition: mcp9808.h:152
#define BSP430_CORE_INLINE
Definition: core.h:439
Declarations for abstracted serial interface.
#define BSP430_SENSORS_MCP9808_TEMP_MASK
Definition: mcp9808.h:148
#define BSP430_SENSORS_MCP9808_TEMP_SIGN
Definition: mcp9808.h:145