gen slave

Dependencies:   mbed

Fork of freeslave3_1 by Chaitanya Viswa

Files at this revision

API Documentation at this revision

Comitter:
viswachaitanya
Date:
Fri Dec 05 10:37:01 2014 +0000
Commit message:
gen slave(master writing and reading from slave

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	Fri Dec 05 10:37:01 2014 +0000
@@ -0,0 +1,41 @@
+#include "mbed.h"
+
+void write_to_master(char);                    //function to write data to master
+
+I2CSlave slave(D14,D15);                       //configuring pins p27, p28 as I2Cslave
+Serial pc (USBTX,USBRX);
+
+void main(){
+    printf("press backspace for slave to start \n\r");
+    while(1){
+        if(pc.getc()==8){
+            bool read_loop = true;
+            char *data_rec = new char;
+            bool write_loop= true;
+            char *data_send = new char;
+            *data_send = 'k';
+            slave.address(0x20);
+            int slave_status=1;
+            while(read_loop){
+                if(slave.receive()==3){     
+                    slave_status=slave.read(data_rec,1);
+                    if(!slave_status){
+                        printf("1 read %c from master\n\r",*data_rec);
+                        read_loop = false;
+                        
+                        while(write_loop){
+                            if(slave.receive()==1){
+                            slave_status=slave.write(data_send,1);
+                                if(!slave_status){
+                                printf("2 wrote %c to master\n\r",*data_send);
+                                write_loop = false;
+                                }
+                            }
+                        }        
+                    }
+                }
+            printf("3 done");
+            }             
+        }                
+    }                
+}   
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Dec 05 10:37:01 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file