gen master public

Dependencies:   mbed

Fork of freemaster3_1 by Chaitanya Viswa

Files at this revision

API Documentation at this revision

Comitter:
viswachaitanya
Date:
Fri Dec 05 10:35:38 2014 +0000
Commit message:
gen free frdm master(mas write to slave and read 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:35:38 2014 +0000
@@ -0,0 +1,45 @@
+#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 master_status_write = true;
+            bool master_status_read = true;
+            char* data_send =  new char;
+            *data_send = 'b';
+            char *data_rec =  new char;
+            *data_rec = 'b';
+            bool write_loop = true;
+            bool read_loop = true;
+            while(write_loop){
+                printf("2 master clk freq setup and addressing slave\n\r");
+                master.frequency(100000);                       //set clock frequency
+                master.start();                                 //initiating the data transfer
+                master_status_write = (bool) master.write(addr|0x00,data_send,1);
+                if(!master_status_write){
+                    printf("3 master has written %c to slave\n\r",*data_send);
+                    write_loop=false;
+                }
+            }
+            printf("done\n\r");
+            
+            
+            while(read_loop){
+                printf("4 master clk freq setup and addressing slave\n\r");
+                master.frequency(100000);                       //set clock frequency
+                master.start();                                 //initiating the data transfer
+                master_status_read = (bool) master.read(addr,data_rec,1);
+                if(!master_status_read){
+                    printf("5 master has read %c from slave\n\r",*data_rec);
+                    read_loop=false;
+                }
+            }
+            printf("done\n\r");
+        }
+    }
+}           
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Dec 05 10:35:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file