Embedded System Design 2 - Project
|
All code for the DS18B20 temperature sensor. More...
#include <stdint.h>
#include <stdbool.h>
#include "em_cmu.h"
#include "em_gpio.h"
#include "DS18B20.h"
#include "pin_mapping.h"
#include "debug_dbprint.h"
#include "delay.h"
#include "util.h"
#include "ustimer.h"
Go to the source code of this file.
Macros | |
#define | DBPRINT_TIMEOUT 0 |
#define | TIMEOUT_INIT 20 |
#define | TIMEOUT_CONVERSION 500 /* 12 bit resolution (reset default) = 750 ms max resolving time */ |
Functions | |
static void | powerDS18B20 (bool enabled) |
Enable or disable the power to the temperature sensor. More... | |
static bool | init_DS18B20 (void) |
Initialize communication to the DS18B20. More... | |
static void | writeByteToDS18B20 (uint8_t data) |
Write a byte (uint8_t ) to the DS18B20. More... | |
static uint8_t | readByteFromDS18B20 (void) |
Read a byte (uint8_t ) from the DS18B20. More... | |
static int32_t | convertTempData (uint8_t tempLS, uint8_t tempMS) |
Convert temperature data. More... | |
int32_t | readTempDS18B20 (void) |
Get a temperature value from the DS18B20. More... | |
Variables | |
bool | DS18B20_VDD_initialized = false |
All code for the DS18B20 temperature sensor.
out
(DOUT) argument. uint32_t
instead of float. int32_t
. error
function, added functionality to exit methods after error
call and updated version number. static
before the local variable (not necessary).Copyright (C) 2019 - Brecht Van Eeckhoudt
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
A copy of the GNU General Public License can be found in the LICENSE
file along with this source code.
Some methods also use code obtained from examples from Silicon Labs' GitHub. These sections are licensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.
Definition in file DS18B20.c.
#define DBPRINT_TIMEOUT 0 |
#define TIMEOUT_CONVERSION 500 /* 12 bit resolution (reset default) = 750 ms max resolving time */ |
|
static |
Convert temperature data.
[in] | tempLS | Least significant byte. |
[in] | tempMS | Most significant byte. |
Definition at line 423 of file DS18B20.c.
|
static |
Initialize communication to the DS18B20.
true
- Presence pulse detected in time. false
- No presence pulse detected. Definition at line 271 of file DS18B20.c.
|
static |
Enable or disable the power to the temperature sensor.
This method also initializes the pin-mode if necessary.
[in] | enabled |
|
Definition at line 237 of file DS18B20.c.
|
static |
int32_t readTempDS18B20 | ( | void | ) |
Get a temperature value from the DS18B20.
USTimer gets initialized, the sensor gets powered, the data-transmission takes place, the timer gets de-initialized to disable the clocks and interrupts, the data and power pin get disabled and finally the read values are converted to an int32_t
value.
Negative temperatures work fine.
Definition at line 113 of file DS18B20.c.
|
static |