DECS_Tubee / Mbed 2 deprecated TPL0102_Potentiometer

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
JeongHoLee
Date:
Wed Jan 23 06:56:03 2019 +0000
Commit message:
TPL0102_Potentiometer 19.01.23

Changed in this revision

TPL0102.cpp Show annotated file Show diff for this revision Revisions of this file
TPL0102.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TPL0102.cpp	Wed Jan 23 06:56:03 2019 +0000
@@ -0,0 +1,29 @@
+#include "TPL0102.h"
+
+TPL0102::TPL0102(PinName SDA, 
+                 PinName SCL) : i2c_(SDA, SCL)
+{
+    i2c_.frequency(100000);
+//    i2c_.start();
+    wait_us(500);
+}
+
+int TPL0102::SlaveSelect(char address, char settings)
+{
+    return oneByteWrite(address, settings);
+}
+
+int TPL0102::AccessControlRegister(char settings)
+{
+    int tx=TPL0102_ACR;
+    return oneByteWrite(tx, settings);
+}
+
+int TPL0102::oneByteWrite(char address, char data)
+{
+   int ack = 0;
+   char tx[2];
+   tx[0] = address;
+   tx[1] = data;
+   return   ack | i2c_.write( TPL0102_Potentiometer_Address << 1 & 0xFE , tx, 2);  
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TPL0102.h	Wed Jan 23 06:56:03 2019 +0000
@@ -0,0 +1,27 @@
+#ifndef TPL0102_H
+#define TPL0102_H
+
+#include "mbed.h"
+
+#define TPL0102_Potentiometer_Address 0x50
+#define TPL0102_ACR 0x10 // 0x40 reset
+
+class TPL0102 {
+
+public:
+
+    TPL0102(PinName SDA, PinName SCL);
+
+    int SlaveSelect(char address, char settings);
+    int AccessControlRegister(char settings);
+//    void DeviceFunctionalMode(char settings);
+
+private:
+
+    I2C i2c_;
+
+    int oneByteWrite(char address, char data);
+
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 23 06:56:03 2019 +0000
@@ -0,0 +1,26 @@
+#include "TPL0102.h"
+
+TPL0102 potentiometer(PB_9, PB_8);  // PB_9 SDA, PB_8 SCL
+//AnalogIn analog_value(PA_0);
+Serial pc(USBTX, USBRX);
+
+int main()
+{
+    pc.printf("Start\r\n");
+    if(potentiometer.SlaveSelect(0x00, 0xC0)) { pc.printf("Not written\r\n"); }
+    else { pc.printf("written\r\n"); }
+
+    if(potentiometer.AccessControlRegister(0x40)) { pc.printf("ACR Not written\r\n"); }  // Non-volatile register, x:shutdown, read non-volatile write op.
+    else { pc.printf("ACR written\r\n"); }
+
+    int i=0xC0;
+    while(1)
+    {
+        i++;
+        potentiometer.SlaveSelect(0x00, i);
+        if(i==0xff) i=0x00;
+        wait(1);        
+    }
+    return 0;
+//    pc.printf("%d\r\n", analog_value);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 23 06:56:03 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file