A library to use Honeywell pressure sensors from HSC series with SPI connection. For calibration scale and pressure range you have to set the declarations inside the hsc_spi.h file - Default values are for 10-90% calibration and 1.6bar absolute sensor

Files at this revision

API Documentation at this revision

Comitter:
brunoalfano
Date:
Sun Feb 16 18:30:04 2014 +0000
Commit message:
Library for Honeywell HSC pressure sensor via SPI

Changed in this revision

hsc_spi.cpp Show annotated file Show diff for this revision Revisions of this file
hsc_spi.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hsc_spi.cpp	Sun Feb 16 18:30:04 2014 +0000
@@ -0,0 +1,41 @@
+#include <mbed.h>
+#include "hsc_spi.h"
+
+hsc_spi::hsc_spi(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs) {}
+
+void hsc_spi::spi_init(){
+    spi.format(16,0);
+    }
+
+float hsc_spi::read_temp() {
+    unsigned int response;
+    float temperature;
+    select();
+        response=spi.write(0x0000);
+        response=spi.write(0x0000);
+        response=response/32;
+        temperature=response*200.0/2047.0 - 50.0;
+    deselect();
+    return temperature;
+}
+
+float hsc_spi::read_press() {
+    unsigned int response;
+    float pressure;
+    select();
+        response=spi.write(0x0000);
+        pressure=1.0*(response - OUTPUT_MIN)*(P_MAX - P_MIN)/(OUTPUT_MAX - OUTPUT_MIN) + P_MIN;
+    deselect();
+    return pressure;
+}
+
+void hsc_spi::select() {
+    spi_init();
+    //Set CS low to start transmission (interrupts conversion)
+    ncs = 0;
+}
+
+void hsc_spi::deselect() {
+    //Set CS high to stop transmission (restarts conversion)
+    ncs = 1;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hsc_spi.h	Sun Feb 16 18:30:04 2014 +0000
@@ -0,0 +1,33 @@
+#ifndef hsc_spi_h
+#define hsc_spi_h
+
+#include "mbed.h"
+
+#define OUTPUT_MAX 0x399A
+#define OUTPUT_MIN 0x0666
+#define P_MAX 1600
+#define P_MIN 0
+
+class hsc_spi
+{
+    SPI& spi;
+    DigitalOut ncs;
+    Timer pollTimer;
+  public:
+  
+    hsc_spi(SPI& _spi, PinName _ncs);
+    //void initialise(int out_max,int out_min,int pmax, int pmin);
+    float read_press();
+    float read_temp();
+    void spi_init();
+    void select();
+    void deselect();
+    
+  private:
+    PinName _CS_pin;
+    PinName _SO_pin;
+    PinName _SCK_pin;
+    float _error;
+};
+
+#endif