Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
LoRaWAN benchmark
RIOT - IM880B
Commits
63b3e0b4
Commit
63b3e0b4
authored
Apr 27, 2019
by
Guillaume Gonnet
Browse files
Add DS75LX temperature driver.
parent
d9cf54dd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
122 additions
and
3 deletions
+122
-3
Makefile
Makefile
+1
-0
src/app/drivers/ds75lx.c
src/app/drivers/ds75lx.c
+75
-0
src/app/drivers/ds75lx.h
src/app/drivers/ds75lx.h
+43
-2
src/app/drivers/gps.h
src/app/drivers/gps.h
+1
-1
src/app/main.c
src/app/main.c
+2
-0
No files found.
Makefile
View file @
63b3e0b4
...
...
@@ -50,6 +50,7 @@ USEMODULE += $(DRIVER)
USEMODULE
+=
random
USEMODULE
+=
periph_eeprom
USEMODULE
+=
periph_uart
USEMODULE
+=
periph_i2c
# Source directory is "src".
...
...
src/app/drivers/ds75lx.c
View file @
63b3e0b4
/*
Driver for the DS75LX digital thermometer.
Copyright (C) 2019, ENSIMAG students
This file is based on DS75LX module from IBM LMIC, under Eclipse Public License
v1.0.
*/
#include "ds75lx.h"
#define ENABLE_DEBUG (1)
#include <debug.h>
// I2C registers.
#define TEMP_REG 0x00 // Temperature register.
#define CONFIG_REG 0x01 // Configuration register.
// Masks to extract the concerned bits.
#define MASK_RESOLUTION 0x60 // 0b01100000
// Debug an I2C result.
#define DS75_DEBUG(text, res) \
if ((res) != 0) DEBUG("[ds75]" text ": %i\n", (res));
// Initialize DS75LX module.
uint8_t
ds75_init
(
void
)
{
i2c_acquire
(
DS75_I2C_DEV
);
int
res
=
i2c_write_reg
(
DS75_I2C_DEV
,
DS75_I2C_ADDRESS
,
CONFIG_REG
,
DS75_RES9
,
0
);
i2c_release
(
DS75_I2C_DEV
);
DS75_DEBUG
(
"initialize error"
,
res
);
return
res
;
}
// Set the resolution of DS75LX chip.
uint8_t
ds75_set_resolution
(
uint8_t
resol
)
{
uint8_t
config
;
i2c_acquire
(
DS75_I2C_DEV
);
int
res
=
i2c_read_reg
(
DS75_I2C_DEV
,
DS75_I2C_ADDRESS
,
CONFIG_REG
,
&
config
,
0
);
DS75_DEBUG
(
"read config error"
,
res
);
config
&=
~
MASK_RESOLUTION
;
config
|=
resol
;
res
=
i2c_write_reg
(
DS75_I2C_DEV
,
DS75_I2C_ADDRESS
,
CONFIG_REG
,
DS75_RES9
,
0
);
i2c_release
(
DS75_I2C_DEV
);
DS75_DEBUG
(
"set resolution error"
,
res
);
return
res
;
}
// Read temperature from DS75LX chip.
uint8_t
ds75_read_temperature
(
uint16_t
*
temp
)
{
uint8_t
buffer
[
2
];
i2c_acquire
(
DS75_I2C_DEV
);
int
res
=
i2c_read_regs
(
DS75_I2C_DEV
,
DS75_I2C_ADDRESS
,
TEMP_REG
,
buffer
,
2
,
0
);
i2c_release
(
DS75_I2C_DEV
);
*
temp
=
(
buffer
[
0
]
<<
8
)
|
buffer
[
1
];
DS75_DEBUG
(
"read temp error"
,
res
);
return
res
;
}
src/app/drivers/ds75lx.h
View file @
63b3e0b4
...
...
@@ -3,9 +3,50 @@
Driver for the DS75LX digital thermometer.
Copyright (C) 2019, ENSIMAG students
This file is based on DS75LX module from IBM LMIC, under Eclipse Public License
v1.0.
This project is under the MIT license
*/
#pragma once
#include <periph/i2c.h>
// Return codes.
#define DS75_SUCCESS 0
#define DS75_FAIL 1
// Default device to use.
#define DS75_I2C_DEV (I2C_DEV(0))
// Default I2C address to use.
#define DS75_I2C_ADDRESS (0x68)
// DS75LX resolution.
#define DS75_RES9 0x00
#define DS75_RES10 0x20
#define DS75_RES11 0x40
#define DS75_RES12 0x60
/**
* @brief Initialize DS75LX module.
* @return `DS75_SUCCESS` or I2C error code.
*/
uint8_t
ds75_init
(
void
);
/**
* @brief Set the resolution of DS75LX chip.
* @param resol The resolution to use.
* @return `DS75_SUCCESS` or I2C error code.
*/
uint8_t
ds75_set_resolution
(
uint8_t
resol
);
/**
* @brief Read temperature from DS75LX chip.
* @param temp Where to store the result.
* @return `DS75_SUCCESS` or I2C error code.
*/
uint8_t
ds75_read_temperature
(
uint16_t
*
temp
);
src/app/drivers/gps.h
View file @
63b3e0b4
...
...
@@ -3,7 +3,7 @@
Decode GPS data.
Copyright (C) 2019, ENSIMAG students
This
file is based on LoRaMAC-node from Semtech, under Revised BSD L
icense
.
This
project is under the MIT l
icense
*/
...
...
src/app/main.c
View file @
63b3e0b4
...
...
@@ -8,6 +8,7 @@ This project is under the MIT license
*/
#include "lorariot.h"
#include "drivers/ds75lx.h"
#include "providers/providers.h"
#include "commands/commands.h"
...
...
@@ -18,6 +19,7 @@ This project is under the MIT license
int
main
(
void
)
{
lorariot_init
();
ds75_init
();
cmds_init
();
#if RESET_ON_START
...
...
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