SPI 接続の温度センサ ADT7310 用のライブラリ. Library for temperature sensor ADT7310 connected using SPI interface.

Dependents:   Demo_ADT7310

Revision:
0:6890e1214ea6
Child:
1:38a276440674
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ADT7310.hpp	Sat Jun 27 08:09:59 2015 +0000
@@ -0,0 +1,58 @@
+//--------------------------------------------------------------
+//  Class for using ADT7310 on one-shot mode (Header)
+//      Default: 13-bit resolution
+//  You want to know format of command byte for SPI,
+//  see Table15 on data sheet of ADT7310, Rev. A p.18.
+//
+//  2015/06/27, Copyright (c) 2015 MIKAMI, Naoki
+//--------------------------------------------------------------
+
+#ifndef ADT7310_HPP
+#define ADT7310_HPP
+
+#include "mbed.h"
+
+namespace Mikami
+{
+    class ADT7310
+    {
+    private:
+        enum Reg { ST = 0x00, CONFIG = 0x08, DATA = 0x10 };
+        DigitalOut ss_;     // Object for output of ss
+
+    protected:
+        SPI spi_;           // Object of SPI
+        // Select SPI device
+        void Select() { ss_ = 0; }
+        // Deselect SPI device
+        void Deselect() { ss_ = 1; }
+        // Set configuration register
+        void SetConfigReg(uint8_t value);
+        // Pre-transform for read
+        void SendRead(Reg myReg) { spi_.write(myReg | 0x40); }
+        // Pre-transform for write
+        void SendWrite(Reg myReg) { spi_.write(myReg); }
+        // Transform data
+        uint8_t SendData(uint8_t data = 0) { return spi_.write(data); }
+
+    public:
+        // Constructor
+        ADT7310(PinName ss,             // for slave select
+                PinName mosi = D11,     // MOSI
+                PinName miso = D12,     // MISO
+                PinName sck  = D13);    // SCK
+        // Software reset
+        void Reset();
+        // Set resolution
+        void SetResolution16(bool res = false);
+        // Get specified register
+        uint8_t GetReg(Reg myReg);
+        // Get configuration register
+        uint8_t GetConfigReg() { return GetReg(CONFIG); }
+        // Get status register
+        uint8_t GetStatusReg() { return GetReg(ST); }
+        // Read data and translate to temperature
+        float Read();
+    };
+}
+#endif  // ADT7310_HPP