My First Try with SPI

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
gabber
Date:
Mon Apr 15 09:13:12 2013 +0000
Commit message:
PWM and SPI tryout

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 Apr 15 09:13:12 2013 +0000
@@ -0,0 +1,37 @@
+#include "mbed.h"
+
+//SETTING THE PERIPHERIE
+DigitalOut myled(LED1);
+SPI spi(p5, p6, p7); // mosi, miso, sclk
+DigitalOut cs(p19); // chip select for SPI
+PwmOut PWM1(p21);PwmOut PWM2(p22);PwmOut PWM3(p23);
+PwmOut PWM4(p24);PwmOut PWM5(p25);PwmOut PWM6(p26);
+
+int main() {
+
+    
+    //SPI
+    spi.format(8,3);
+    spi.frequency(1e6);
+    char t_deadH=0x07; // 0830
+    char t_deadL=0xFF;
+    uint16_t t_dead = 0x0830;
+    cs = 0; 
+    spi.write(t_deadH); // KEEP THIS ORDER !    
+    spi.write(t_deadL);
+    cs = 1;
+    PWM1.period(7.0);
+    PWM1 = 2.0/7.0;
+    PWM2 = 3.0/7.0;
+    PWM3 = 4.0/7.0;
+    PWM4 = 5.0/7.0;
+    PWM5 = 6.0/7.0;
+    PWM6 = 1.0/7.0;
+    
+    while(1) {
+        myled = 1;
+        wait(0.2);        
+        myled = 0;
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Apr 15 09:13:12 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/5e5da4a5990b
\ No newline at end of file