master working version 1.1

Dependencies:   mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
sakthipriya
Date:
Sat Dec 13 11:24:36 2014 +0000
Commit message:
master working

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib 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
diff -r 000000000000 -r 58b0c597a58c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Dec 13 11:24:36 2014 +0000
@@ -0,0 +1,135 @@
+#include "mbed.h"
+#include "rtos.h"
+
+const int addr = 0x20;                     //slave address 
+I2C master (D14,D15);                      //configure pins p27,p28 as I2C master
+Serial pc (USBTX,USBRX);
+DigitalOut interrupt(D9);
+InterruptIn data_ready(D10);
+
+int reset;
+
+typedef struct
+{
+    char data;          // To avoid dynamic memory allocation
+    int length;
+}i2c_data;
+
+Mail<i2c_data,16> i2c_data_receive;
+Mail<i2c_data,16> i2c_data_send;
+
+Thread * ptr_t_i2c;
+void FUNC_I2C_MASTER_FSLAVE(char * data,int length)
+{
+    //printf("press backspace for master to start \n\r");
+    //while(1){
+            //interrupt = 0;
+      //  if(pc.getc()=='z'){
+            wait(0.5);
+            interrupt = 1;
+            printf("\nMaster executed\n");
+            
+          
+            bool ack0 =true; 
+            bool loopvariable0 =true;
+            //char *data =  new char;
+            //*data = 'b';
+           
+           
+            
+             master.frequency(100000);                       //set clock frequency
+             //master.start();
+            /*while(write2slave)
+            {  *writedata = pc.getc();
+            wait(0.5);
+              
+                printf("master clk freq setup and addressing slave\n\r");
+                master.start();                                 //initiating the data transfer
+                master_status_write = (bool) master.write(addr|0x00,writedata,1);
+                if(master_status_write==0)
+                {
+                    printf("master has written %c to slave\n\r",*writedata);
+                    write2slave=false;
+                }
+                    
+                    
+             }*/
+             
+            while(ack0)
+            {
+                //printf("2 master clk freq setup and addressing slave\n\r");
+                
+                master.start();                                 //initiating the data transfer
+                ack0 =  master.read(addr,data,length);
+            }
+            if(!ack0)
+            {
+                    printf("\n master has read %c from slave\n\r",*data);
+                    loopvariable0=false;
+            }
+                //master.stop();
+            
+            //printf("done\n\r");
+            //delete data;
+            interrupt=0;
+}
+            
+void T_I2C_MASTER_FSLAVE(void const *args)
+{
+    char data_receive;
+    while(1)
+    {
+        Thread::signal_wait(0x1);
+        FUNC_I2C_MASTER_FSLAVE(&data_receive,1);
+        i2c_data * i2c_data_r = i2c_data_receive.alloc();
+        i2c_data_r->data = data_receive;
+        i2c_data_r->length = 1;
+        i2c_data_receive.put(i2c_data_r);
+        printf("\n Data received from CDMS is %c\n\r",data_receive);
+        i2c_data_receive.free(i2c_data_r);
+    }
+}
+
+void FUNC_INT()
+{
+  
+   ptr_t_i2c->signal_set(0x1);
+     
+}
+
+
+    
+
+int main()
+{   
+    ptr_t_i2c = new Thread(T_I2C_MASTER_FSLAVE);
+    
+    data_ready.rise(&FUNC_INT);
+    printf("\nstarted master\n");
+    bool write2slave;
+    char *writedata = new char;
+       
+   
+     bool master_status_write = true;
+    while(1)
+    { write2slave=true;
+    interrupt = 0;
+    
+      *writedata = pc.getc();
+      
+    interrupt = 1; 
+                master.frequency(100000);                        //set clock frequency
+                while(write2slave)
+           {                
+                printf("master clk freq setup and addressing slave\n\r");
+                master.start();                                 //initiating the data transfer
+                master_status_write = (bool) master.write(addr|0x00,writedata,1);
+                if(master_status_write==0)
+                    {
+                    printf("master has written %c to slave\n\r",*writedata);
+                    write2slave=false;
+                    }
+            }
+        
+    }
+}           
\ No newline at end of file
diff -r 000000000000 -r 58b0c597a58c mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Sat Dec 13 11:24:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#f1ef95efa5ad
diff -r 000000000000 -r 58b0c597a58c mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Dec 13 11:24:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file