This code acts as the master controlling the slave actions, done using FRDM_KL_25Z

Dependencies:   mbed

Revision:
0:7478eb44f4b1
diff -r 000000000000 -r 7478eb44f4b1 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jul 29 10:00:16 2016 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+ 
+SPI spi(PTD2, PTD3, PTD1); // mosi, miso, sclk
+DigitalOut cs(PTD0);
+Serial pc(USBTX,USBRX);
+
+ 
+int main() {
+    pc.baud(115200);
+    // Chip must be deselected
+    cs = 1;
+
+    // Setup the spi for 8 bit data, high steady state clock,
+    // second edge capture, with a 1MHz clock rate
+    spi.format(8,1);
+    //spi.frequency(1000000);
+    spi.frequency(512000); //internal clock frequency of ADS1291
+ 
+    // Select the device by setting chip select low
+    cs = 0;
+ int v=0;
+    // Send 0x8f, the command to read the WHOAMI register
+    spi.write(0x8F);
+
+
+    // Send a dummy byte to receive the contents of the WHOAMI register
+    int whoami = spi.write(0x00);
+  //  printf("WHOAMI register = 0x%X\n", whoami);
+  while(1)
+  {
+      wait(1);
+      
+  spi.write(v);
+   pc.printf("read the data %d",v);
+  //led = !led;
+  if(v==255)
+  v=0;
+  else
+  v=v+1;
+}
+    // Deselect the device
+    cs = 1;
+}
\ No newline at end of file