master writing to slave

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
viswachaitanya
Date:
Sat Dec 06 06:19:00 2014 +0000
Commit message:
m_w_s1_1

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	Sat Dec 06 06:19:00 2014 +0000
@@ -0,0 +1,29 @@
+#include "mbed.h"
+
+const int addr = 0x20;                     //slave address 
+I2C master (D14,D15);                      //configure pins p27,p28 as I2C master
+Serial pc (USBTX,USBRX);
+
+void main()
+{
+    printf("press backspace for master to start \n\r");
+    while(1){
+        if(pc.getc()==8){
+            bool ack0 =true; 
+            char* data =  new char;
+            *data = 'b';
+            bool loopvariable0 = true;
+            while(loopvariable0){
+                printf("2 master clk freq setup and addressing slave\n\r");
+                master.frequency(100000);                       //set clock frequency
+                master.start();                                 //initiating the data transfer
+                ack0 = (bool) master.write(addr|0x00,data,1);
+                if(!ack0){
+                    printf("3 master has written %c to slave\n\r",*data);
+                    loopvariable0=false;
+                }
+            }
+            printf("done\n\r");
+        }
+    }
+}           
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 06 06:19:00 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file