jkjkjkjk

Dependencies:   mbed-rtos mbed

Fork of all_combined_week6 by green rosh

Revision:
7:5cf19bfdbacd
Parent:
6:82153349cc9b
diff -r 82153349cc9b -r 5cf19bfdbacd slave.cpp
--- a/slave.cpp	Tue Jul 15 10:04:38 2014 +0000
+++ b/slave.cpp	Thu Jul 17 11:22:41 2014 +0000
@@ -1,13 +1,14 @@
 #include "slave.h"
-#include "HK.h"
- 
-extern struct SensorData Sensor;
+
+ int acknowledge; 
+           int loopvariable4;
+SensorData Sensor; 
 I2CSlave slave(p28,p27);                       //configuring pins p27, p28 as I2Cslave
 Serial screen (USBTX,USBRX);
 void write_to_master(char send)                           //function to write data to master
         {
-           int acknowledge; 
-           int loopvariable4=1;
+            
+           loopvariable4=1;
            while(loopvariable4)
            {
            acknowledge = slave.write(send);    //sending the byte to master
@@ -24,10 +25,21 @@
  
 void FUNC_I2C_SLAVE_MAIN(int iterations)
 {
+    slave.address(slave_address);                           //assigning slave address
+    char Switch_Variable;
+    slave.stop();
+    Sensor.voltage[0]='a';Sensor.current[0]='1';Sensor.temp[0]='k';
+    Sensor.voltage[1]='b';Sensor.current[1]='2';Sensor.temp[1]='l';
+    Sensor.voltage[2]='c';Sensor.current[2]='3';Sensor.temp[2]='m';
+    Sensor.voltage[3]='d';Sensor.current[3]='4';Sensor.temp[3]='n';
+    Sensor.voltage[4]='e';Sensor.current[4]='5';Sensor.temp[4]='o';
+    Sensor.voltage[5]='f';Sensor.current[5]='1';Sensor.temp[5]='p';
+    Sensor.voltage[6]='g';Sensor.current[6]='2';Sensor.temp[6]='q';
+    Sensor.voltage[7]='h';Sensor.current[7]='3';Sensor.temp[7]='r';
     
     screen.printf("\nSlave entered\n");
-    slave.address(slave_address);                           //assigning slave address
-    char Switch_Variable;
+    
+    
     
     
     int loopvariable1=1;
@@ -59,17 +71,17 @@
                       if(loopvariable2%3==0)
                           {
                           screen.printf("\nvoltage%d\n",loopvariable2/3);
-                          write_to_master(Sensor.Voltage[loopvariable2/3]);
+                          write_to_master(Sensor.voltage[loopvariable2/3]);
                           }
                       else if(loopvariable2%3==1)
                           {   
                           screen.printf("\ncurrent%d\n",loopvariable2/3);
-                          write_to_master(Sensor.Current[loopvariable2/3]);
+                          write_to_master(Sensor.current[loopvariable2/3]);
                           }
                       else if(loopvariable2%3==2)
                           {   
                           screen.printf("\ntemp%d\n",loopvariable2/3);
-                          write_to_master(Sensor.Temperature[loopvariable2/3]);
+                          write_to_master(Sensor.temp[loopvariable2/3]);
                           }         
                       loopvariable2++;
                        }//while(loopvariable2<30)
@@ -87,6 +99,7 @@
         }//switch case ends
    }   
 }
+
    screen.printf("\nexited slave function\n");
 }
  
\ No newline at end of file