Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
16beb6af
Commit
16beb6af
authored
Jan 15, 2016
by
Johny Mattsson
Browse files
Merge pull request #908 from elgarbe/dev_lm92
Add support for Temperature Comparison register set/get functions for LM92
parents
52e121f4
4c037bfe
Changes
2
Show whitespace changes
Inline
Side-by-side
lua_modules/lm92/README.md
View file @
16beb6af
# LM92 module
This module adds basic support for the LM92 +-0.33C 12bit+sign temperature sensor. More details in the
[
datasheet
](
http://www.ti.com/lit/ds/symlink/lm92.pdf
)
.
Works:
-
06/01/2016: Add get/set comparison registers. Thyst, Tlow, Thigh and Tcrit
-
getting the temperature
-
entering the chip's to shutdown mode (350uA -> 5uA power consumption)
-
waking up the chip from shutdown
...
...
@@ -94,5 +95,181 @@ shutdown()
```
lua
LM92
.
shutdown
()
```
##setThyst()
####Description
Set hysteresis Temperature.
####Syntax
setThyst(data_wr)
####Parameters
data_wr: 130~-55 ºC, hysteresis Temperature
####Returns
nil
####Example
```
lua
LM92
.
setThyst
(
3
)
```
##setTcrit()
####Description
Set Critical Temperature.
####Syntax
setTcrit(data_wr)
####Parameters
data_wr: 130~-55 ºC, Critical Temperature
####Returns
nil
####Example
```
lua
LM92
.
setTcrit
(
100
.
625
)
```
##setTlow()
####Description
Set Low Window Temperature.
####Syntax
setTlow(data_wr)
####Parameters
data_wr: 130~-55 ºC, Low Window Temperature
####Returns
nil
####Example
```
lua
LM92
.
setTlow
(
32
.
25
)
```
##setThigh()
####Description
Set High Window Temperature.
####Syntax
setThigh(data_wr)
####Parameters
data_wr: 130~-55 ºC, High Window Temperature
####Returns
nil
####Example
```
lua
LM92
.
setThigh
(
27
.
5
)
```
##getThyst()
####Description
Get hysteresis Temperature.
####Syntax
getThyst()
####Parameters
--
####Returns
Hysteresis Temperature in degree Celsius.
####Example
```
lua
t
=
LM92
.
getThyst
()
print
(
"Got hysteresis temperature: "
..
t
..
" C"
)
```
##getTcrit()
####Description
Get Critical Temperature.
####Syntax
getTcrit()
####Parameters
--
####Returns
Critical Temperature in degree Celsius.
####Example
```
lua
t
=
LM92
.
getTcrit
()
print
(
"Got Critical temperature: "
..
t
..
" C"
)
```
##getTlow()
####Description
Get Low Window Temperature.
####Syntax
getTlow()
####Parameters
--
####Returns
Low Window Temperature in degree Celsius.
####Example
```
lua
t
=
LM92
.
getTlow
()
print
(
"Got Low Window temperature: "
..
t
..
" C"
)
```
##getThigh()
####Description
Get High Window Temperature.
####Syntax
getThigh()
####Parameters
--
####Returns
High Window Temperature in degree Celsius.
####Example
```
lua
t
=
LM92
.
getThigh
()
print
(
"Got High Window temperature: "
..
t
..
" C"
)
```
##Full example
--node.compile("lm92.lua")
LM92 = require("lm92")
gpio0 = 3
gpio2 = 4
sda = gpio0
scl = gpio2
addr = 0x48
LM92.init(sda, scl,addr)
t = LM92.getTemperature()
print("Got temperature: "..t.." C")
--Seting comparison temperatures
LM92.setThyst(3)
LM92.setTcrit(40.75)
LM92.setTlow(28.5)
LM92.setThigh(31.625)
t = LM92.getThyst()
print("Got hyster: "..t.." C")
t = LM92.getTcrit()
print("Got Crit: "..t.." C")
t = LM92.getTlow()
print("Got Low: "..t.." C")
t = LM92.getThigh()
print("Got High: "..t.." C")
#### TODO:
-
add full support of the features, including interrupt and critical alert support
lua_modules/lm92/lm92.lua
View file @
16beb6af
...
...
@@ -3,6 +3,8 @@
--
-- Written by Levente Tamas <levente.tamas@navicron.com>
--
-- modify by Garberoglio Leonardo <leogarberoglio@gmail.com>
--
-- GNU LGPL, see https://www.gnu.org/copyleft/lesser.html
-- ******************************************************
...
...
@@ -47,6 +49,15 @@ local function write_reg(reg_addr, data)
i2c
.
stop
(
id
)
end
--write comparison reg with 2 bytes
local
function
write_comp_reg
(
reg_addr
,
msb
,
lsb
)
i2c
.
start
(
id
)
i2c
.
address
(
id
,
address
,
i2c
.
TRANSMITTER
)
i2c
.
write
(
id
,
reg_addr
)
i2c
.
write
(
id
,
msb
)
i2c
.
write
(
id
,
lsb
)
i2c
.
stop
(
id
)
end
-- initialize i2c
-- d: sda
-- c: scl
...
...
@@ -90,5 +101,96 @@ function M.wakeup()
write_reg
(
0x01
,
0x00
)
end
-- Write the LM92 Thyst SET POINT
function
M
.
setThyst
(
data_wr
)
local
tmp
=
data_wr
/
0
.
0625
if
(
tmp
>=
0x1000
)
then
tmp
=
tmp
-
0x2000
--convert the two's complement
end
tmp
=
bit
.
lshift
(
tmp
,
3
)
local
lsb
=
bit
.
band
(
tmp
,
0x00FF
)
tmp
=
bit
.
rshift
(
bit
.
band
(
tmp
,
0xFF00
),
8
)
write_comp_reg
(
0x02
,
tmp
,
lsb
)
end
-- Write the LM92 T_crit SET POINT
function
M
.
setTcrit
(
data_wr
)
local
tmp
=
data_wr
/
0
.
0625
if
(
tmp
>=
0x1000
)
then
tmp
=
tmp
-
0x2000
--convert the two's complement
end
tmp
=
bit
.
lshift
(
tmp
,
3
)
local
lsb
=
bit
.
band
(
tmp
,
0x00FF
)
tmp
=
bit
.
rshift
(
bit
.
band
(
tmp
,
0xFF00
),
8
)
write_comp_reg
(
0x03
,
tmp
,
lsb
)
end
-- Write the LM92 Tlow SET POINT
function
M
.
setTlow
(
data_wr
)
local
tmp
=
data_wr
/
0
.
0625
if
(
tmp
>=
0x1000
)
then
tmp
=
tmp
-
0x2000
--convert the two's complement
end
tmp
=
bit
.
lshift
(
tmp
,
3
)
local
lsb
=
bit
.
band
(
tmp
,
0x00FF
)
tmp
=
bit
.
rshift
(
bit
.
band
(
tmp
,
0xFF00
),
8
)
write_comp_reg
(
0x04
,
tmp
,
lsb
)
end
-- Write the LM92 T_high SET POINT
function
M
.
setThigh
(
data_wr
)
local
tmp
=
data_wr
/
0
.
0625
if
(
tmp
>=
0x1000
)
then
tmp
=
tmp
-
0x2000
--convert the two's complement
end
tmp
=
bit
.
lshift
(
tmp
,
3
)
local
lsb
=
bit
.
band
(
tmp
,
0x00FF
)
tmp
=
bit
.
rshift
(
bit
.
band
(
tmp
,
0xFF00
),
8
)
write_comp_reg
(
0x05
,
tmp
,
lsb
)
end
-- Read the LM92 Thyst SET POINT
function
M
.
getThyst
()
local
temperature
local
tmp
=
read_reg
(
0x02
,
2
)
--read 2 bytes from the Hysteresis register
temperature
=
bit
.
rshift
(
tmp
[
1
]
*
256
+
tmp
[
2
],
3
)
--lower 3 bits are status bits
if
(
temperature
>=
0x1000
)
then
temperature
=
temperature
-
0x2000
--convert the two's complement
end
return
temperature
*
0
.
0625
end
-- Read the LM92 T_crit SET POINT
function
M
.
getTcrit
()
local
temperature
local
tmp
=
read_reg
(
0x03
,
2
)
--read 2 bytes from the T Critical register
temperature
=
bit
.
rshift
(
tmp
[
1
]
*
256
+
tmp
[
2
],
3
)
--lower 3 bits are status bits
if
(
temperature
>=
0x1000
)
then
temperature
=
temperature
-
0x2000
--convert the two's complement
end
return
temperature
*
0
.
0625
end
-- Read the LM92 Tlow SET POINT
function
M
.
getTlow
()
local
temperature
local
tmp
=
read_reg
(
0x04
,
2
)
--read 2 bytes from the T Low register
temperature
=
bit
.
rshift
(
tmp
[
1
]
*
256
+
tmp
[
2
],
3
)
--lower 3 bits are status bits
if
(
temperature
>=
0x1000
)
then
temperature
=
temperature
-
0x2000
--convert the two's complement
end
return
temperature
*
0
.
0625
end
-- Read the LM92 T_high SET POINT
function
M
.
getThigh
()
local
temperature
local
tmp
=
read_reg
(
0x05
,
2
)
--read 2 bytes from the T High register
temperature
=
bit
.
rshift
(
tmp
[
1
]
*
256
+
tmp
[
2
],
3
)
--lower 3 bits are status bits
if
(
temperature
>=
0x1000
)
then
temperature
=
temperature
-
0x2000
--convert the two's complement
end
return
temperature
*
0
.
0625
end
return
M
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment