Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:d024d4d62f2e
--- /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!");
+}