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

Committer:
brunoalfano
Date:
Sun Feb 16 18:30:04 2014 +0000
Revision:
0:0056857990b9
Library for Honeywell HSC pressure sensor via SPI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brunoalfano 0:0056857990b9 1 #include <mbed.h>
brunoalfano 0:0056857990b9 2 #include "hsc_spi.h"
brunoalfano 0:0056857990b9 3
brunoalfano 0:0056857990b9 4 hsc_spi::hsc_spi(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs) {}
brunoalfano 0:0056857990b9 5
brunoalfano 0:0056857990b9 6 void hsc_spi::spi_init(){
brunoalfano 0:0056857990b9 7 spi.format(16,0);
brunoalfano 0:0056857990b9 8 }
brunoalfano 0:0056857990b9 9
brunoalfano 0:0056857990b9 10 float hsc_spi::read_temp() {
brunoalfano 0:0056857990b9 11 unsigned int response;
brunoalfano 0:0056857990b9 12 float temperature;
brunoalfano 0:0056857990b9 13 select();
brunoalfano 0:0056857990b9 14 response=spi.write(0x0000);
brunoalfano 0:0056857990b9 15 response=spi.write(0x0000);
brunoalfano 0:0056857990b9 16 response=response/32;
brunoalfano 0:0056857990b9 17 temperature=response*200.0/2047.0 - 50.0;
brunoalfano 0:0056857990b9 18 deselect();
brunoalfano 0:0056857990b9 19 return temperature;
brunoalfano 0:0056857990b9 20 }
brunoalfano 0:0056857990b9 21
brunoalfano 0:0056857990b9 22 float hsc_spi::read_press() {
brunoalfano 0:0056857990b9 23 unsigned int response;
brunoalfano 0:0056857990b9 24 float pressure;
brunoalfano 0:0056857990b9 25 select();
brunoalfano 0:0056857990b9 26 response=spi.write(0x0000);
brunoalfano 0:0056857990b9 27 pressure=1.0*(response - OUTPUT_MIN)*(P_MAX - P_MIN)/(OUTPUT_MAX - OUTPUT_MIN) + P_MIN;
brunoalfano 0:0056857990b9 28 deselect();
brunoalfano 0:0056857990b9 29 return pressure;
brunoalfano 0:0056857990b9 30 }
brunoalfano 0:0056857990b9 31
brunoalfano 0:0056857990b9 32 void hsc_spi::select() {
brunoalfano 0:0056857990b9 33 spi_init();
brunoalfano 0:0056857990b9 34 //Set CS low to start transmission (interrupts conversion)
brunoalfano 0:0056857990b9 35 ncs = 0;
brunoalfano 0:0056857990b9 36 }
brunoalfano 0:0056857990b9 37
brunoalfano 0:0056857990b9 38 void hsc_spi::deselect() {
brunoalfano 0:0056857990b9 39 //Set CS high to stop transmission (restarts conversion)
brunoalfano 0:0056857990b9 40 ncs = 1;
brunoalfano 0:0056857990b9 41 }