Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Inductive_Sensor Inductive_Sensor_Jasper Inductive_Sensor_3
Revision 0:abb33be87221, committed 2016-03-24
- Comitter:
- bobgiesberts
- Date:
- Thu Mar 24 16:26:24 2016 +0000
- Child:
- 1:ef7e5efc8794
- Commit message:
- It's working, no memory leaks anymore, great!
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1825.cpp Thu Mar 24 16:26:24 2016 +0000
@@ -0,0 +1,49 @@
+#include "DS1825.h"
+#include "OneWire.h"
+#include "mbed.h"
+
+
+//DS1825::DS1825( PinName pin ) : _onewire( pin )
+DS1825::DS1825( PinName pin )
+{
+ _onewire = new OneWire( pin );
+}
+
+DS1825::~DS1825( )
+{
+ _onewire->depower(); // Does not work perfectly: 1,1 V remains...
+ delete _onewire;
+ _onewire = NULL;
+}
+
+bool DS1825::validateTemperature( uint8_t d[9] )
+{
+ return (d[8] == _onewire->crc8(d, 8));
+}
+
+float DS1825::getTemperature( void )
+{
+ _onewire->reset();
+ _onewire->skip(); // Skip ROM --> because there is only one sensor, no need to search for the correct ID
+ _onewire->write( 0x44, 1 ); // Convert T --> initiate temperature conversion, data is stored on scratchpad, after writing put the wire high to power the DS1825
+ wait_ms( 750 ); // with 12-bit resolution, t_conv = 750 ms
+
+ _onewire->reset();
+ _onewire->skip(); // Skip ROM
+ _onewire->write( 0xBE ); // Command to read scratchpad
+
+ uint8_t Tdata[9];
+ for (int i = 0; i < 9; i++)
+ Tdata[i] = _onewire->read(); // read scratchpad
+
+ _onewire->depower();
+
+ if( validateTemperature( Tdata ) )
+ {
+ int16_t T_bin;
+ T_bin = (Tdata[1] << 8) | Tdata[0];
+ T = T_bin / 16.0;
+ return T;
+ }
+ return 0;
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1825.h Thu Mar 24 16:26:24 2016 +0000
@@ -0,0 +1,30 @@
+#ifndef _DS1825_H
+#define _DS1825_H
+
+/**
+* @file DS1825.h
+* @brief this header file will contain all required
+* definitions for the functions to interface with the DS1825.
+*
+* @author Bob Giesberts
+*
+* @date 2016-03-23
+*/
+
+#include "mbed.h"
+#include "OneWire.h"
+
+class DS1825 {
+ public:
+ DS1825(PinName pin);
+ ~DS1825();
+ float getTemperature(void);
+ OneWire *_onewire;
+ float T;
+
+ private:
+ bool validateTemperature(uint8_t data[9]);
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/OneWire.lib Thu Mar 24 16:26:24 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/hudakz/code/OneWire/#68746e80003d