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.
Diff: spiMasterProtocol.cpp
- Revision:
- 0:855b6e84e744
diff -r 000000000000 -r 855b6e84e744 spiMasterProtocol.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/spiMasterProtocol.cpp Fri Oct 31 22:13:47 2014 +0000
@@ -0,0 +1,52 @@
+#include "spiMasterProtocol.h"
+
+spiMasterProtocol::spiMasterProtocol() {
+ spiLine = new SPI(p5, p6, p7);
+ spiLine->format(8,3); // Setup: bit data, high steady state clock, 2nd edge capture
+ spiLine->frequency(1000000); // 1MHz
+
+ chipSelect = new DigitalOut(p8);
+ chipSelect->write(1);
+}
+
+ int spiMasterProtocol::get42() {
+ int temp = write(0x42);
+ wait_us(5);
+ int data = write(0x00);
+ wait_us(5);
+ int dataExtra = write(0x00);
+
+ printf("get42():\n\r");
+ printf("temp = %d\n\r", temp);
+ printf("data = %d\n\r", data);
+ printf("dataExtra = %d\n\r", data);
+ printf("\n");
+
+ return data;
+}
+
+ int spiMasterProtocol::get84() {
+ int temp = write(0x84);
+ wait_us(5);
+ int data1 = write(0x00);
+ wait_us(5);
+ int data2 = write(0x00);
+
+ printf("get84():\n\r");
+ printf("temp = %d\n\r", temp);
+ printf("data1 = %d\n\r", data1);
+ printf("data2 = %d\n\r", data2);
+ printf("\n");
+
+ return data2;
+}
+
+int spiMasterProtocol::write(int m) {
+ chipSelect->write(0);
+
+ int returnMess = spiLine->write(m);
+
+ chipSelect->write(1);
+
+ return returnMess;
+}
\ No newline at end of file