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

Dependents:   Demo_ADT7310

Files at this revision

API Documentation at this revision

Comitter:
MikamiUitOpen
Date:
Sat Oct 28 14:51:32 2017 +0000
Parent:
0:6890e1214ea6
Commit message:
2

Changed in this revision

ADT7310.cpp Show annotated file Show diff for this revision Revisions of this file
ADT7310.hpp Show annotated file Show diff for this revision Revisions of this file
diff -r 6890e1214ea6 -r 38a276440674 ADT7310.cpp
--- a/ADT7310.cpp	Sat Jun 27 08:09:59 2015 +0000
+++ b/ADT7310.cpp	Sat Oct 28 14:51:32 2017 +0000
@@ -1,7 +1,7 @@
 //--------------------------------------------------------------
-//  Class for using ADT7310 on one-shot mode
+//  Class for ADT7310 on one-shot mode
 //      Default: 13-bit resolution
-//  2015/06/27, Copyright (c) 2015 MIKAMI, Naoki
+//  2017/10/28, Copyright (c) 2017 MIKAMI, Naoki
 //--------------------------------------------------------------
 
 #include "ADT7310.hpp"
@@ -15,7 +15,7 @@
     {
         Reset();
         spi_.format(8, 3);  // mode: 8 bits, POL = 1, PHA = 1
-        SetConfigReg(0x00); // Set 13-bit resolution
+        SetConfigReg(0x00); // Clear configuration register.
     }
 
     // Software reset
@@ -66,8 +66,9 @@
         Deselect();
 
         uint8_t config = GetConfigReg() & 0x80;
-        SetConfigReg(0x20 | config);     // Start conversion
+        SetConfigReg(0x20 | config);     // One-shot mode, Start conversion
 
         return data/128.0f;    
     }
 }
+
diff -r 6890e1214ea6 -r 38a276440674 ADT7310.hpp
--- a/ADT7310.hpp	Sat Jun 27 08:09:59 2015 +0000
+++ b/ADT7310.hpp	Sat Oct 28 14:51:32 2017 +0000
@@ -1,10 +1,10 @@
 //--------------------------------------------------------------
-//  Class for using ADT7310 on one-shot mode (Header)
+//  Class for 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
+//  2017/10/28, Copyright (c) 2017 MIKAMI, Naoki
 //--------------------------------------------------------------
 
 #ifndef ADT7310_HPP
@@ -20,21 +20,6 @@
         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
@@ -53,6 +38,23 @@
         uint8_t GetStatusReg() { return GetReg(ST); }
         // Read data and translate to temperature
         float Read();
+
+    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); }
     };
 }
 #endif  // ADT7310_HPP
+