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
Revision 0:241cea911735, committed 2018-11-19
- 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 | 
--- /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
--- /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