81 #define DBPRINT_TIMEOUT 0 84 #define TIMEOUT_INIT 100 85 #define TIMEOUT_CONVERSION 500 125 bool conversionCompleted =
false;
128 uint8_t rawDataDS18B20[9] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
153 if (testByte > 0) conversionCompleted =
true;
162 #if DEBUG_DBPRINT == 1 163 dbcrit(
"Waiting time for DS18B20 conversion reached!");
182 #if DBPRINT_TIMEOUT == 1 186 #if DEBUG_DBPRINT == 1 187 dbwarnInt(
"DS18B20 conversion (", counter,
")");
218 #if DEBUG_DBPRINT == 1 219 dbcrit(
"DS18B20 INIT failed!");
257 CMU_ClockEnable(cmuClock_HFPER,
true);
258 CMU_ClockEnable(cmuClock_GPIO,
true);
275 else if (number == 1) {
318 USTIMER_DelayIntSafe(480);
334 #if DEBUG_DBPRINT == 1 335 dbcrit(
"No DS18B20 presence pulse detected in time!");
342 #if DBPRINT_TIMEOUT == 1 346 #if DEBUG_DBPRINT == 1 347 dbwarnInt(
"DS18B20 INIT (", counter,
")");
354 USTIMER_DelayIntSafe(480);
378 for (
uint8_t i = 0; i < 8; i++)
395 USTIMER_DelayIntSafe(60);
405 USTIMER_DelayIntSafe(60);
441 for (
uint8_t i = 0; i < 8; i++)
464 USTIMER_DelayIntSafe(70);
498 rawDataMerge = tempMS;
504 rawDataMerge += tempLS;
507 reverseRawDataMerge = ~rawDataMerge;
510 finalTemperature = -(reverseRawDataMerge + 1) * 62.5;
515 rawDataMerge = tempMS;
521 rawDataMerge += tempLS;
524 finalTemperature = rawDataMerge * 62.5;
527 return (finalTemperature);
int32_t readTempDS18B20(uint8_t number)
Get a temperature value from the DS18B20.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
#define TIMEOUT_CONVERSION
bool TEMP1_VDD_initialized
void error(uint8_t number)
Error method.
int int32_t
Typedef defining 32 bit int type. The developer should modify this to suit the platform being deploye...
static bool init_DS18B20(uint8_t number)
Initialize communication to the DS18B20.
static int32_t convertTempData(uint8_t tempLS, uint8_t tempMS)
Convert temperature data.
The pin definitions for the custom board.
bool TEMP0_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.
static void powerDS18B20(uint8_t number, bool enabled)
Enable or disable the power to the temperature sensor.
void dbcrit(char *message)
Print a critical error string (char array) in red to USARTx and go to the next line.
static uint8_t readByteDS18B20(uint8_t number)
Read a byte (uint8_t) from the DS18B20.
unsigned short uint16_t
Typedef defining 16 bit unsigned short type. The developer should modify this to suit the platform be...
static void writeByteDS18B20(uint8_t number, uint8_t data)
Write a byte (uint8_t) to the DS18B20.
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
unsigned int uint32_t
Typedef defining 32 bit unsigned int type. The developer should modify this to suit the platform bein...
All code for the DS18B20 temperature sensor.