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
Diff: hsc_spi.cpp
- Revision:
- 0:0056857990b9
diff -r 000000000000 -r 0056857990b9 hsc_spi.cpp --- /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