Kevin Anderson
/
DataCommFreedom
Using FRDM Board to output data and a clock for communications example.
Diff: main.cpp
- Revision:
- 0:7c7f4b30d64f
- Child:
- 1:4c0c28cc2b2c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 26 14:52:18 2015 +0000 @@ -0,0 +1,50 @@ +#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 +Timer t; //timer for controlling the clock and data skew +int msecs; //clock time needed for data transfer +int sksecs; //skew time +int skew_flag; //skew flag for while loop + +int main() { + + //turn on red led to show programming has worked + myled = 0; + //initialize output pins + clock_pin = 0; + serial_out = 0; + //skew flag + skew_flag = 1; + + //set timers + msecs = 10; + sksecs = 8; + + //output a clock pulse and data. + while(1) + { + //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 + if(!clock_pin && skew_flag && t.read_ms() > sksecs) + { + //switch data signal + serial_out = !serial_out; + skew_flag = 0; + } + } + //stop and reset the timer + t.stop(); + t.reset(); + //switch clock signal + clock_pin = !clock_pin; + //reset skew flag + skew_flag = 1; + } +} \ No newline at end of file