test

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
kevin1990
Date:
Tue Jun 20 13:19:11 2017 +0000
Parent:
0:48b56cad57ae
Commit message:
first test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jun 02 09:14:50 2017 +0000
+++ b/main.cpp	Tue Jun 20 13:19:11 2017 +0000
@@ -1,34 +1,30 @@
 #include "mbed.h"
  
-SPI spi(D11, D12, D13); // mosi, miso, sclk
-DigitalOut chipSelect(D10);
- 
-Serial pc(USBTX, USBRX); // tx, rx
+SPI spi(PA_7, PA_6, PA_5);          // mosi, miso, sclk
+DigitalOut cs(PB_6);
+DigitalOut syncPin (D8);
+
+Serial pc(USBTX, USBRX, 9600);      // tx, rx
  
 int main() {
  
-    int valueToSendToSlave = 20; // Starting value only, this increments
-    spi.format(8,3);        // Setup:  bit data, high steady state clock, 2nd edge capture
-    spi.frequency(1000000); //1MHz
- 
-    pc.printf("======================================================\r\n");
-    pc.printf("Press any key to start...\r\n");
-    pc.getc(); // wait for keyboard
- 
-    int counter = 1;
-    while (1) {
+    // set sync pin to known state
+    syncPin  = 0;
+    // Chip must be deselected
+    cs = 1;
+    int value = 4;
+    
+    spi.format(8,3);                // Setup:  bit data, high steady state clock, 2nd edge capture
+    spi.frequency(1000000);         //1MHz
  
-        pc.printf("%d Value to send = %d ", counter++, valueToSendToSlave);
-        
-        chipSelect = 0; // Select device
-        int dataFromSlave =  spi.write(valueToSendToSlave);
-        chipSelect = 1; // Deselect device
- 
-        pc.printf("  returns %d\r\n", dataFromSlave);
-        
-        valueToSendToSlave++;
-        
-        wait(5); // Wait for 5 seconds for readability only
-        
+    // set sync pin high
+    syncPin  = 1;
+    for (int i = 0; i < 6; i++) {
+        // Select device     
+        cs = 0;                         
+        spi.write(value);
+        // Deselect device
+        cs = 1;
+        value++; 
     }
 }
\ No newline at end of file