|
@@ -28,12 +28,13 @@ double deviceID;
|
|
|
*/
|
|
|
|
|
|
void DS18B20_init(void){
|
|
|
+ OneWire_init();
|
|
|
if(OW_reset()){
|
|
|
logger_error("Unable to reset 1-Wire Bus, no Device present %s\n", strerror(errno));
|
|
|
return;
|
|
|
}
|
|
|
DS18B20_readRom();
|
|
|
- deviceID = (double (ROM[6]) | ROM[5] << 8 | ROM[5] << 16 | ROM[5] << 24 | ROM[5] << 32 | ROM[5] << 40);
|
|
|
+ deviceID = double (ROM[1]);// | ROM[5] << 8 | ROM[5] << 16 | ROM[5] << 24 | ROM[5] << 32 | ROM[5] << 40);
|
|
|
if(ROM[7] == 0x28){
|
|
|
logger(V_HAL, "Found Temperatur Sensor on 1-Wire Bus\n");
|
|
|
logger(V_HAL, "Device ID: %12X", deviceID);
|
|
@@ -48,7 +49,12 @@ void DS18B20_readRom(void){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-uint16_t DS18B20_readTemp (void){
|
|
|
+/**
|
|
|
+ * Reads the Temperatur of the DS18B20 Sensor
|
|
|
+ * It rounds the value read from the Sensor rounded to the next integer
|
|
|
+ */
|
|
|
+int8_t DS18B20_readTemp (void){
|
|
|
+ OW_writeByte(SKIP_ROM);
|
|
|
OW_writeByte(CONVERT_T);
|
|
|
while(!OW_readBit()){
|
|
|
//wait to finish conversion
|
|
@@ -57,7 +63,13 @@ uint16_t DS18B20_readTemp (void){
|
|
|
OW_writeByte(READ_SCRATCH);
|
|
|
uint8_t scratchPad[9];
|
|
|
uint8_t i;
|
|
|
+ int8_t temp;
|
|
|
for(i = 0; i < 9; i++){
|
|
|
scratchPad[i] = OW_readByte();
|
|
|
}
|
|
|
+ //Information about temperatur is stored in byte[0] and byte[1]
|
|
|
+ temp = scratchPad[0] >> 4;
|
|
|
+ temp |= (scratchPad[1] << 4) & 0xF0;
|
|
|
+ return temp;
|
|
|
+ //todo return a float value and do proper rounding
|
|
|
}
|