Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
b540def4
Commit
b540def4
authored
10 years ago
by
Johann Fischer
Browse files
Options
Downloads
Patches
Plain Diff
drivers/hdc1000: Acquire exclusive access to I2C bus and minor bug fixes
fix doxygen warnings change default address
parent
aa639486
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
drivers/hdc1000/hdc1000.c
+23
-0
23 additions, 0 deletions
drivers/hdc1000/hdc1000.c
drivers/include/hdc1000.h
+8
-3
8 additions, 3 deletions
drivers/include/hdc1000.h
tests/driver_hdc1000/main.c
+2
-0
2 additions, 0 deletions
tests/driver_hdc1000/main.c
with
33 additions
and
3 deletions
drivers/hdc1000/hdc1000.c
+
23
−
0
View file @
b540def4
...
...
@@ -67,9 +67,13 @@ int hdc1000_test(hdc1000_t *dev)
char
reg
[
2
];
uint16_t
tmp
;
i2c_acquire
(
dev
->
i2c
);
if
(
i2c_read_regs
(
dev
->
i2c
,
dev
->
addr
,
HDC1000_MANUFACTURER_ID
,
reg
,
2
)
!=
2
)
{
i2c_release
(
dev
->
i2c
);
return
-
1
;
}
i2c_release
(
dev
->
i2c
);
tmp
=
((
uint16_t
)
reg
[
0
]
<<
8
)
|
reg
[
1
];
if
(
tmp
!=
HDC1000_MID_VALUE
)
{
return
-
1
;
...
...
@@ -87,10 +91,13 @@ int hdc1000_init(hdc1000_t *dev, i2c_t i2c, uint8_t address)
dev
->
addr
=
address
;
dev
->
initialized
=
false
;
i2c_acquire
(
dev
->
i2c
);
/* initialize the I2C bus */
if
(
i2c_init_master
(
i2c
,
I2C_SPEED
)
<
0
)
{
i2c_release
(
dev
->
i2c
);
return
-
1
;
}
i2c_release
(
dev
->
i2c
);
if
(
hdc1000_test
(
dev
))
{
return
-
2
;
...
...
@@ -101,11 +108,14 @@ int hdc1000_init(hdc1000_t *dev, i2c_t i2c, uint8_t address)
reg
[
0
]
=
(
uint8_t
)(
tmp
>>
8
);
reg
[
1
]
=
(
uint8_t
)
tmp
;
i2c_acquire
(
dev
->
i2c
);
if
(
i2c_write_regs
(
dev
->
i2c
,
dev
->
addr
,
HDC1000_CONFG
,
reg
,
2
)
!=
2
)
{
i2c_release
(
dev
->
i2c
);
return
-
3
;
}
dev
->
initialized
=
true
;
i2c_release
(
dev
->
i2c
);
return
0
;
}
...
...
@@ -117,9 +127,13 @@ int hdc1000_reset(hdc1000_t *dev)
reg
[
1
]
=
(
uint8_t
)
tmp
;
dev
->
initialized
=
false
;
i2c_acquire
(
dev
->
i2c
);
if
(
i2c_write_regs
(
dev
->
i2c
,
dev
->
addr
,
HDC1000_CONFG
,
reg
,
2
)
!=
2
)
{
i2c_release
(
dev
->
i2c
);
return
-
1
;
}
i2c_release
(
dev
->
i2c
);
return
0
;
}
...
...
@@ -128,13 +142,18 @@ int hdc1000_startmeasure(hdc1000_t *dev)
if
(
dev
->
initialized
==
false
)
{
return
-
1
;
}
i2c_acquire
(
dev
->
i2c
);
/* Trigger the measurements by executing a write access
* to the address 0x00 (HDC1000_TEMPERATURE).
* Conversion Time is 6.50ms by 14 bit resolution.
*/
if
(
i2c_write_bytes
(
dev
->
i2c
,
dev
->
addr
,
HDC1000_TEMPERATURE
,
1
)
!=
1
)
{
i2c_release
(
dev
->
i2c
);
return
-
1
;
}
i2c_release
(
dev
->
i2c
);
return
0
;
}
...
...
@@ -145,13 +164,17 @@ int hdc1000_read(hdc1000_t *dev, uint16_t *rawtemp, uint16_t *rawhum)
if
(
dev
->
initialized
==
false
)
{
return
-
1
;
}
i2c_acquire
(
dev
->
i2c
);
if
(
i2c_read_bytes
(
dev
->
i2c
,
dev
->
addr
,
buf
,
4
)
!=
4
)
{
i2c_release
(
dev
->
i2c
);
return
-
1
;
}
/* Register bytes are sent MSB first. */
*
rawtemp
=
((
uint16_t
)
buf
[
0
]
<<
8
)
|
buf
[
1
];
*
rawhum
=
((
uint16_t
)
buf
[
2
]
<<
8
)
|
buf
[
3
];
i2c_release
(
dev
->
i2c
);
return
0
;
}
...
...
This diff is collapsed.
Click to expand it.
drivers/include/hdc1000.h
+
8
−
3
View file @
b540def4
...
...
@@ -18,7 +18,10 @@
* be started by a write access to the address 0x00
* (HDC1000_TEMPERATURE). After completing the measurement
* the sensor will return to sleep mode. Typical
* Conversion Time by 14 bit resolution is 6.50ms.
* Conversion Time by 14 bit resolution is 6.50ms
* for humidity and 6.35ms for temperature.
* HDC1000_CONVERSION_TIME is twice as large to prevent
* the problems with timer resolution.
*
* @{
*
...
...
@@ -41,11 +44,11 @@ extern "C"
#endif
#ifndef HDC1000_I2C_ADDRESS
#define HDC1000_I2C_ADDRESS 0x4
1
#define HDC1000_I2C_ADDRESS 0x4
3
/**< Default Device Address */
#endif
#ifndef HDC1000_CONVERSION_TIME
#define HDC1000_CONVERSION_TIME
6500
#define HDC1000_CONVERSION_TIME
26000
/**< Default Conversion Time */
#endif
/**
...
...
@@ -109,6 +112,8 @@ int hdc1000_startmeasure(hdc1000_t *dev);
* @brief Read sensor's data.
*
* @param[in] dev device descriptor of sensor
* @param[out] rawtemp raw temperature value
* @param[out] rawhum raw humidity value
*
* @return 0 on success
* @return -1 on error
...
...
This diff is collapsed.
Click to expand it.
tests/driver_hdc1000/main.c
+
2
−
0
View file @
b540def4
...
...
@@ -56,6 +56,7 @@ int main(void)
return
-
1
;
}
vtimer_usleep
(
HDC1000_CONVERSION_TIME
);
hdc1000_read
(
&
dev
,
&
rawtemp
,
&
rawhum
);
printf
(
"Raw data T: %5i RH: %5i
\n
"
,
rawtemp
,
rawhum
);
...
...
@@ -63,6 +64,7 @@ int main(void)
printf
(
"Data T: %d RH: %d
\n
"
,
temp
,
hum
);
vtimer_usleep
(
SLEEP
);
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment