ENPRA_Foot / Mbed 2 deprecated Nucleo_spi_master

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Keith_N
Date:
Mon Nov 19 05:26:08 2018 +0000
Commit message:
spi_master

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
diff -r 000000000000 -r 241cea911735 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Nov 19 05:26:08 2018 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+
+SPI spi(PB_5, PB_4, PB_3); // mosi, miso, sclk
+DigitalOut cs(PA_1);
+Serial pc(USBTX, USBRX);
+DigitalOut led(LED1);
+
+#define DTIME 0.005
+
+int main()
+{
+    cs = 1;
+    spi.format(8,0);
+    spi.frequency(1000000);
+    led = 0;
+
+    while(1) {
+        led = 1;        
+        cs=0;
+        wait(DTIME);
+        int byte_1 = spi.write(0x03);
+        pc.printf("byte_1: %d ",byte_1);
+        cs=1;
+
+        cs=0;
+        wait(DTIME);
+        int byte_2 = spi.write(0xFF);
+        pc.printf("byte_2: %d ",byte_2);
+        cs=1;
+        
+        cs=0;
+        wait(DTIME);
+        int byte_waste = spi.write(0xFF);
+        cs=1;
+
+        int rbyte = (byte_1<<8)+byte_2;
+        pc.printf("rbyte: %d\r\n",rbyte);
+        led = 0;
+        
+        wait(0.05);
+    }
+
+}
\ No newline at end of file
diff -r 000000000000 -r 241cea911735 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Nov 19 05:26:08 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/e95d10626187
\ No newline at end of file