SSLM1 / Mbed 2 deprecated P-7100

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
sasakisho
Date:
Wed Jun 03 15:46:55 2020 +0000
Commit message:
version0

Changed in this revision

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/main.cpp	Wed Jun 03 15:46:55 2020 +0000
@@ -0,0 +1,83 @@
+/* ADコンバータであるMCP3204を使い,圧力センサP-7100からデータを取得するためのコード */
+
+#include "mbed.h"
+
+SPI spi(p5, p6, p7);
+DigitalOut cs(p8);
+Timer t;
+
+Serial pc(USBTX, USBRX);
+
+int main()
+{
+    // ADC val
+    uint8_t high, low;
+    double value, v, tp;
+    
+    //file val
+    int i = 0, j = 0, k = 1000;
+    double V[k], TP[k],T[k];
+    
+    spi.format(7, 0);
+    spi.frequency(1000000);
+    
+    pc.baud(460800);
+    
+    pc.printf("start!\n");
+    
+    t.start();
+    
+    while(j < 20)
+    {
+    
+    while(i < k)
+    {
+        cs = 0;
+        
+        spi.write(0x60); //シングル
+        //spi.write(0x40); //差動
+        
+        high = spi.write(0x00);
+        low = spi.write(0x00);
+        
+        low = (high << 5) | (low >> 2);
+        high = high >> 3;
+        
+        value = (high << 8) | low;
+        
+        v = value / 4096 * 5.0;
+        
+        tp = 0.25 * v - 0.125;
+        
+        V[i] = v;
+        TP[i] = tp;
+        T[i] = t.read();
+        
+        //pc.printf("sensor 0 value = %lf\n", value);
+        
+        cs = 1;
+        
+        i++;
+        
+        wait(0.009);
+    }
+    
+    i  = 0;
+    
+    while(i < k)
+    {
+        pc.printf("%f, %f, %f\n", T[i], V[i], TP[i]);
+        
+        i++;
+    }
+    
+    i = 0;
+    
+    j++;
+    
+    }
+    
+    t.stop();
+    
+    pc.printf("finish!");
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jun 03 15:46:55 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file