Library to interface the SCP1000 temperature and pressure sensor.
Dependents: SCP1000_Example ku-make_sensor ku-make_sensor201302 SCP1000_Example ... more
SCP1000.h@9:47d6f205890b, 2010-10-08 (annotated)
- Committer:
- kadams6
- Date:
- Fri Oct 08 17:44:49 2010 +0000
- Revision:
- 9:47d6f205890b
- Parent:
- 8:1049590388b6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadams6 | 8:1049590388b6 | 1 | /** |
kadams6 | 9:47d6f205890b | 2 | * @section LICENSE |
kadams6 | 9:47d6f205890b | 3 | * This program is free software; you can redistribute it and/or modify |
kadams6 | 9:47d6f205890b | 4 | * it under the terms of the GNU General Public License as published by |
kadams6 | 9:47d6f205890b | 5 | * the Free Software Foundation; either version 2 of the License, or |
kadams6 | 9:47d6f205890b | 6 | * (at your option) any later version. |
kadams6 | 9:47d6f205890b | 7 | * |
kadams6 | 9:47d6f205890b | 8 | * This program is distributed in the hope that it will be useful, but |
kadams6 | 9:47d6f205890b | 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
kadams6 | 9:47d6f205890b | 10 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
kadams6 | 9:47d6f205890b | 11 | * for more details. |
kadams6 | 9:47d6f205890b | 12 | * |
kadams6 | 9:47d6f205890b | 13 | * You should have received a copy of the GNU General Public License along |
kadams6 | 9:47d6f205890b | 14 | * with this program; if not, write to the Free Software Foundation, Inc., |
kadams6 | 9:47d6f205890b | 15 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
kadams6 | 9:47d6f205890b | 16 | * |
kadams6 | 9:47d6f205890b | 17 | * @section DESCRIPTION |
kadams6 | 9:47d6f205890b | 18 | * Library to interface with the SCP1000 pressure and temperature sensor. |
kadams6 | 8:1049590388b6 | 19 | */ |
kadams6 | 3:4d8b8ca54451 | 20 | |
kadams6 | 0:0b8b5828e1a3 | 21 | #ifndef _SCP1000_H |
kadams6 | 0:0b8b5828e1a3 | 22 | #define _SCP1000_H |
kadams6 | 0:0b8b5828e1a3 | 23 | |
kadams6 | 0:0b8b5828e1a3 | 24 | #include "mbed.h" |
kadams6 | 0:0b8b5828e1a3 | 25 | |
kadams6 | 8:1049590388b6 | 26 | /** |
kadams6 | 8:1049590388b6 | 27 | * Class to interface with the SCP1000 pressure and temperature sensor. |
kadams6 | 8:1049590388b6 | 28 | */ |
kadams6 | 0:0b8b5828e1a3 | 29 | class SCP1000 { |
kadams6 | 0:0b8b5828e1a3 | 30 | public: |
kadams6 | 7:61d2e698d988 | 31 | /** |
kadams6 | 7:61d2e698d988 | 32 | * Constructor. |
kadams6 | 7:61d2e698d988 | 33 | * |
kadams6 | 7:61d2e698d988 | 34 | * @param mosi SPI MOSI pin |
kadams6 | 7:61d2e698d988 | 35 | * @param miso SPI MISO pin |
kadams6 | 7:61d2e698d988 | 36 | * @param sclk SPI SCLK pin |
kadams6 | 7:61d2e698d988 | 37 | * @param cs Chip select pin |
kadams6 | 7:61d2e698d988 | 38 | */ |
kadams6 | 4:295e118b6e85 | 39 | SCP1000(PinName mosi, PinName miso, PinName sclk, PinName cs); |
kadams6 | 0:0b8b5828e1a3 | 40 | |
kadams6 | 0:0b8b5828e1a3 | 41 | ~SCP1000() { /* empty */ }; |
kadams6 | 0:0b8b5828e1a3 | 42 | |
kadams6 | 1:5fcf1fe4a161 | 43 | /** |
kadams6 | 7:61d2e698d988 | 44 | * Read the pressure. |
kadams6 | 7:61d2e698d988 | 45 | * |
kadams6 | 7:61d2e698d988 | 46 | * @returns The pressure in pascals. |
kadams6 | 7:61d2e698d988 | 47 | */ |
kadams6 | 4:295e118b6e85 | 48 | unsigned long readPressure(); |
kadams6 | 0:0b8b5828e1a3 | 49 | |
kadams6 | 7:61d2e698d988 | 50 | /** |
kadams6 | 7:61d2e698d988 | 51 | * Read the temperature. |
kadams6 | 7:61d2e698d988 | 52 | * |
kadams6 | 7:61d2e698d988 | 53 | * @returns The temperature in Celsius. |
kadams6 | 7:61d2e698d988 | 54 | */ |
kadams6 | 4:295e118b6e85 | 55 | float readTemperature(); |
kadams6 | 0:0b8b5828e1a3 | 56 | |
kadams6 | 0:0b8b5828e1a3 | 57 | |
kadams6 | 0:0b8b5828e1a3 | 58 | private: |
kadams6 | 0:0b8b5828e1a3 | 59 | static const char PRESSURE = 0x1F; //Pressure 3 MSB |
kadams6 | 0:0b8b5828e1a3 | 60 | static const char PRESSURE_LSB = 0x20; //Pressure 16 LSB |
kadams6 | 0:0b8b5828e1a3 | 61 | static const char TEMP = 0x21; //16 bit temp |
kadams6 | 0:0b8b5828e1a3 | 62 | SPI m_spi; |
kadams6 | 0:0b8b5828e1a3 | 63 | DigitalOut m_cs; |
kadams6 | 0:0b8b5828e1a3 | 64 | |
kadams6 | 4:295e118b6e85 | 65 | char read_register(char register_name); |
kadams6 | 4:295e118b6e85 | 66 | void write_register(char register_name, char register_value); |
kadams6 | 4:295e118b6e85 | 67 | float read_register16(char register_name); |
kadams6 | 0:0b8b5828e1a3 | 68 | |
kadams6 | 0:0b8b5828e1a3 | 69 | }; |
kadams6 | 0:0b8b5828e1a3 | 70 | |
kadams6 | 0:0b8b5828e1a3 | 71 | #endif // _SCP1000_H |