80 #define DBPRINT_TIMEOUT 0 83 #define TIMEOUT_INIT 20 84 #define TIMEOUT_CONVERSION 500 116 uint16_t counter = 0;
119 bool conversionCompleted =
false;
122 uint8_t rawDataFromDS18B20Arr[9] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
147 if (testByte > 0) conversionCompleted =
true;
156 #if DEBUG_DBPRINT == 1 157 dbcrit(
"Waiting time for DS18B20 conversion reached!");
175 #if DBPRINT_TIMEOUT == 1 179 #if DEBUG_DBPRINT == 1 180 dbwarnInt(
"DS18B20 conversion (", counter,
")");
203 return (
convertTempData(rawDataFromDS18B20Arr[0], rawDataFromDS18B20Arr[1]));
240 CMU_ClockEnable(cmuClock_HFPER,
true);
241 CMU_ClockEnable(cmuClock_GPIO,
true);
274 uint32_t counter = 0;
278 USTIMER_DelayIntSafe(480);
292 #if DEBUG_DBPRINT == 1 293 dbcrit(
"No DS18B20 presence pulse detected in time!");
300 #if DBPRINT_TIMEOUT == 1 304 #if DEBUG_DBPRINT == 1 305 dbwarnInt(
"DS18B20 INIT (", counter,
")");
312 USTIMER_DelayIntSafe(480);
335 for (uint8_t i = 0; i < 8; i++)
343 for (uint8_t i=0; i<5; i++);
346 USTIMER_DelayIntSafe(60);
352 USTIMER_DelayIntSafe(60);
356 for (uint8_t i=0; i<5; i++);
384 for (uint8_t i = 0; i < 8; i++)
400 USTIMER_DelayIntSafe(70);
425 uint16_t rawDataMerge;
426 uint16_t reverseRawDataMerge;
428 int32_t finalTemperature;
434 rawDataMerge = tempMS;
440 rawDataMerge += tempLS;
443 reverseRawDataMerge = ~rawDataMerge;
446 finalTemperature = -(reverseRawDataMerge + 1) * 62.5;
451 rawDataMerge = tempMS;
457 rawDataMerge += tempLS;
460 finalTemperature = rawDataMerge * 62.5;
463 return (finalTemperature);
static void writeByteToDS18B20(uint8_t data)
Write a byte (uint8_t) to the DS18B20.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
static void powerDS18B20(bool enabled)
Enable or disable the power to the temperature sensor.
#define TIMEOUT_CONVERSION
void error(uint8_t number)
Error method.
static uint8_t readByteFromDS18B20(void)
Read a byte (uint8_t) from the DS18B20.
static int32_t convertTempData(uint8_t tempLS, uint8_t tempMS)
Convert temperature data.
The pin definitions for the regular and custom Happy Gecko board.
bool DS18B20_VDD_initialized
Enable or disable printing to UART with dbprint.
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
int32_t readTempDS18B20(void)
Get a temperature value from the DS18B20.
static bool init_DS18B20(void)
Initialize communication to the DS18B20.
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
All code for the DS18B20 temperature sensor.