SCA61T Single Axis Inclinometer

Dependents:   SCA61T_example

Committer:
Veino
Date:
Thu Mar 10 16:07:16 2011 +0000
Revision:
2:b0d8ca64cb0f
Parent:
1:663ebf72b607
v1.1, some typos fixed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Veino 1:663ebf72b607 1 /* mbed SCA61T Single Axis Inclinometer
Veino 0:eaca4c1a258f 2 * Copyright (c) 2010 Veikko Soininen
Veino 0:eaca4c1a258f 3 *
Veino 0:eaca4c1a258f 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
Veino 0:eaca4c1a258f 5 * of this software and associated documentation files (the "Software"), to deal
Veino 0:eaca4c1a258f 6 * in the Software without restriction, including without limitation the rights
Veino 0:eaca4c1a258f 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Veino 0:eaca4c1a258f 8 * copies of the Software, and to permit persons to whom the Software is
Veino 0:eaca4c1a258f 9 * furnished to do so, subject to the following conditions:
Veino 0:eaca4c1a258f 10 *
Veino 0:eaca4c1a258f 11 * The above copyright notice and this permission notice shall be included in
Veino 0:eaca4c1a258f 12 * all copies or substantial portions of the Software.
Veino 0:eaca4c1a258f 13 *
Veino 0:eaca4c1a258f 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Veino 0:eaca4c1a258f 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Veino 0:eaca4c1a258f 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Veino 0:eaca4c1a258f 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Veino 0:eaca4c1a258f 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Veino 0:eaca4c1a258f 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Veino 0:eaca4c1a258f 20 * THE SOFTWARE.
Veino 0:eaca4c1a258f 21 */
Veino 0:eaca4c1a258f 22
Veino 0:eaca4c1a258f 23 #ifndef _SCA61T_H_
Veino 0:eaca4c1a258f 24 #define _SCA61T_H_
Veino 0:eaca4c1a258f 25
Veino 0:eaca4c1a258f 26 #include "mbed.h"
Veino 0:eaca4c1a258f 27
Veino 1:663ebf72b607 28 /** SCA61T Inclinometer class
Veino 1:663ebf72b607 29 *
Veino 1:663ebf72b607 30 * Example:
Veino 1:663ebf72b607 31 * @code
Veino 1:663ebf72b607 32 * // Send temperature and angle to serial port every one second.
Veino 1:663ebf72b607 33 * #include "mbed.h"
Veino 1:663ebf72b607 34 * #include "SCA61T.h"
Veino 1:663ebf72b607 35 *
Veino 2:b0d8ca64cb0f 36 * SCA61T sca61t(p11,p12,p13,p21,0); // MOSI, MISO, SCLK, CSB, device selection
Veino 1:663ebf72b607 37 * // 0=SCA61T-FAHH1G, 1=SCA61T-FA1H1G
Veino 1:663ebf72b607 38 * Serial pc(USBTX, USBRX);
Veino 1:663ebf72b607 39 *
Veino 1:663ebf72b607 40 * int main(void)
Veino 1:663ebf72b607 41 * {
Veino 1:663ebf72b607 42 * while(1)
Veino 1:663ebf72b607 43 * {
Veino 1:663ebf72b607 44 * pc.printf("%i [C]\r\n",sca61t.ReadTemp()); // Writes the temperature to serial port.
Veino 1:663ebf72b607 45 * pc.printf("%.1f [deg]\r\n",sca61t.ReadX()); // Writes the angle to serial port.
Veino 1:663ebf72b607 46 * wait(1); // Waits for one second and repeats.
Veino 1:663ebf72b607 47 * }
Veino 1:663ebf72b607 48 * }
Veino 1:663ebf72b607 49 * @endcode
Veino 1:663ebf72b607 50 */
Veino 0:eaca4c1a258f 51
Veino 0:eaca4c1a258f 52 class SCA61T {
Veino 0:eaca4c1a258f 53 public:
Veino 2:b0d8ca64cb0f 54 SCA61T(PinName mosi, PinName miso, PinName sclk, PinName csb, int device_sel);
Veino 0:eaca4c1a258f 55 ~SCA61T() {};
Veino 0:eaca4c1a258f 56
Veino 1:663ebf72b607 57 /** Reads the angle
Veino 1:663ebf72b607 58 *
Veino 1:663ebf72b607 59 * @returns angle in degrees
Veino 1:663ebf72b607 60 */
Veino 1:663ebf72b607 61 float ReadX();
Veino 1:663ebf72b607 62
Veino 1:663ebf72b607 63 /** Reads the temperature
Veino 1:663ebf72b607 64 *
Veino 1:663ebf72b607 65 * @returns temperature in Celcius
Veino 1:663ebf72b607 66 */
Veino 1:663ebf72b607 67 int8_t ReadTemp();
Veino 1:663ebf72b607 68
Veino 1:663ebf72b607 69 /** Sets the sensor to measurement mode
Veino 1:663ebf72b607 70 *
Veino 1:663ebf72b607 71 * Default mode, not needed to call
Veino 1:663ebf72b607 72 * first
Veino 1:663ebf72b607 73 */
Veino 1:663ebf72b607 74 void MeasMode();
Veino 1:663ebf72b607 75
Veino 1:663ebf72b607 76 /** Reads the status register
Veino 1:663ebf72b607 77 *
Veino 1:663ebf72b607 78 * @returns value of status register
Veino 1:663ebf72b607 79 */
Veino 1:663ebf72b607 80 uint8_t ReadStatus();
Veino 1:663ebf72b607 81
Veino 1:663ebf72b607 82 /** Reloads NV.
Veino 1:663ebf72b607 83 *
Veino 1:663ebf72b607 84 */
Veino 1:663ebf72b607 85 void ReloadNV();
Veino 1:663ebf72b607 86
Veino 1:663ebf72b607 87 /** Sets the sensor to self test mode
Veino 1:663ebf72b607 88 *
Veino 1:663ebf72b607 89 * Discharges the sensor element. De-activated
Veino 1:663ebf72b607 90 * by MeasMode().
Veino 1:663ebf72b607 91 */
Veino 1:663ebf72b607 92 void SelfTest();
Veino 0:eaca4c1a258f 93
Veino 0:eaca4c1a258f 94 private:
Veino 0:eaca4c1a258f 95 SPI SPI_m;
Veino 2:b0d8ca64cb0f 96 DigitalOut CSB_m;
Veino 0:eaca4c1a258f 97
Veino 0:eaca4c1a258f 98 void SPI_SendByte(uint8_t byte);
Veino 0:eaca4c1a258f 99 uint8_t SPI_ReadReg(uint8_t reg);
Veino 0:eaca4c1a258f 100 void SPI_ReadWord(uint8_t cmd, char* table);
Veino 0:eaca4c1a258f 101 void SPI_Command(uint8_t cmd);
Veino 0:eaca4c1a258f 102 };
Veino 0:eaca4c1a258f 103
Veino 0:eaca4c1a258f 104 #endif