Library to communicate with LDC1614

Dependencies:   SHTx

Dependents:   Inductive_Sensor_3

Fork of LDC1101 by Bob Giesberts

Revision:
22:8da965ce5af3
Parent:
21:7c9e04e7d34f
Child:
23:8faeabb395db
diff -r 7c9e04e7d34f -r 8da965ce5af3 LDC1101.cpp
--- a/LDC1101.cpp	Tue Jan 05 11:03:22 2016 +0000
+++ b/LDC1101.cpp	Sat Jan 16 09:12:32 2016 +0000
@@ -12,10 +12,11 @@
 #include "LDC1101.h"
 
  
-LDC1101::LDC1101(PinName mosi, PinName miso, PinName sck, PinName cs, float capacitor, float f_CLKIN, PinName clock_out) : _spiport(mosi,miso,sck, NC), _cs_pin(cs)//, _clock(clock_out,1)
+LDC1101::LDC1101(PinName mosi, PinName miso, PinName sck, PinName cs, float capacitor, float f_CLKIN, PinName clock_out) : _spiport(mosi,miso,sck, NC), _cs_pin(cs) //, _clock(clock_out,1)
 {
     // settings
     _cap = capacitor;
+       
     _spiport.format(8,3);
     _spiport.frequency(1E6);
     setFrequency(f_CLKIN);
@@ -27,17 +28,28 @@
 }
 
 void LDC1101::func_mode(LDC_MODE mode) { writeSPI((uint8_t *)(&mode), 0x0B); wait_ms(0.8); }
-void LDC1101::sleep(void) { /* stop toggling the CLKIN pin input and drive the CLKIN pin Low */ func_mode( LDC_MODE_STANDBY ); }
-void LDC1101::wakeup(void) { /* start toggling the clock input on the CLKIN pin */ func_mode( LDC_MODE_ACTIVE ); wait(0.5); }
+
+void LDC1101::sleep(void)
+{ 
+    /* stop toggling the CLKIN pin input and drive the CLKIN pin Low */ 
+    func_mode( LDC_MODE_SHUTDOWN );
+    _cs_pin.write(0); // CSB down
+    
+    suicide( this );
+}
+void LDC1101::wakeup(void) { 
+    /* start toggling the clock input on the CLKIN pin */ 
+    init(); 
+    wait(0.5); 
+}
 
 
 void LDC1101::init()
 {
     /********* SETTINGS *****************
-    ** C_sensor     = 120 pF
-    ** L_sensor     =   5 uH
-    ** Rs           = ??? Ohm
-    ** Rp_min       = ??? Ohm
+    ** C_sensor     =  120 pF
+    ** L_sensor     =    5 uH
+    ** Rp_min       = 1500 Ohm
     **
     ** RCount       = 65535
     ** Samplerate   =    15.3 Hz
@@ -65,8 +77,8 @@
     setf_sensorMin( 6.4 ); // 6.4 MHz
     
     // - disable RP_MAX
-    // - set RP_MIN to 3 kOhm
-    setRPsettings( 1, RPMIN_12 );
+    // - set RP_MIN to 1,5 kOhm (RPMIN_1)
+    setRPsettings( 1, RPMIN_1 );
 
     //  - set Divider to 2
     setDivider( DIVIDER_2 );  
@@ -123,10 +135,31 @@
     writeSPIregister(0x04, ((buffer[0] & 0x0F) + (MIN_FREQ << 4)));
 }
 
+bool LDC1101::is_New_LHR_data(void)
+{
+    return(~(get_LHR_status() & 0x01));
+}
 
+bool LDC1101::is_Oscillation_Error(void)
+{
+    return(get_status() & 0x80);
+}
 
-  
+uint8_t LDC1101::get_status(void)
+{
+    
+    uint8_t buffer[1];
+    readSPI(buffer, 0x20, 1);
+    
+    return buffer[0];
+}
 
+uint8_t LDC1101::get_LHR_status(void)
+{
+    uint8_t buffer[1];
+    readSPI(buffer, 0x3B, 1);
+    return buffer[0];
+}
 
 float LDC1101::get_Q(void){ return _RPmin * sqrt(_cap/_inductance*1000000); }