Using FRDM Board to output data and a clock for communications example.

Dependencies:   mbed

Revision:
2:11f32d8cfa11
Parent:
1:4c0c28cc2b2c
Child:
3:027d30718bbc
--- a/main.cpp	Thu Feb 26 15:53:11 2015 +0000
+++ b/main.cpp	Sun Mar 15 03:02:48 2015 +0000
@@ -1,13 +1,18 @@
+//project to include preamble, addressing, control, error control.
+//currently fixed size data field but doesn't have to be. (post amble if not fixed size)
+
 #include "mbed.h"
 #include "stdio.h"
 
-DigitalOut myled(LED1); // Led on board
-DigitalOut clock_pin(D8); //send clock pulse
-DigitalOut serial_out(D7); //serial tx
+#define MAX 100 //set the size of the character data storage array
+
+DigitalOut myled(LED1); // red led on board
+DigitalOut clock_pin(D8), serial_out(D7); //send clock pulse and tx
 Timer t; //timer for controlling the clock and data skew
-int msecs; //clock time needed for data transfer
-int sksecs; //skew time
+int msecs, sksecs; //clock time needed for data transfer and skew time
 int skew_flag; //skew flag for while loop
+char data[100] = "Hi!"; //data output
+int i = 0, j = 128; //increment variables
 
 int main() {
     
@@ -18,25 +23,25 @@
     serial_out = 0;
     //skew flag
     skew_flag = 1;
-    
     //set timers
     msecs = 2000;
     sksecs = 1800;
     
     //output a clock pulse and data.
-    while(1)
+    while(i < 3)
     {
         //start timer for clock
         t.start();
         //wait until the timer has reached the set time.
         while(t.read_ms() < msecs)
         {
-            //switch data just before clock goes high
+            //extract data just before clock goes high
             if(!clock_pin && skew_flag && t.read_ms() > sksecs)
             {
-                //switch data signal
-                serial_out = !serial_out;
+                //extract data bit
+                serial_out = (data[i] / j) % 2;
                 skew_flag = 0;
+                j /= 2; //decrement j to get to next bit location
             }
         }
         //stop and reset the timer
@@ -46,7 +51,13 @@
         clock_pin = !clock_pin;
         //reset skew flag
         skew_flag = 1;
+        //last bit sent - reset/increment variables
+        if(j==0)
+        {
+            j=128;
+            i++;
+        }
     }
 }
 
-//crc = x^5+x^4+x^2+1
\ No newline at end of file
+//crc = x^4+x+1
\ No newline at end of file