v2 i2c slave sending 4 bit sensor data to master

Dependencies:   mbed

Fork of xslave by Chaitanya Viswa

Files at this revision

API Documentation at this revision

Comitter:
viswachaitanya
Date:
Mon Jul 07 07:28:35 2014 +0000
Parent:
0:acc1f8a1b321
Commit message:
v2

Changed in this revision

slave.cpp Show annotated file Show diff for this revision Revisions of this file
slave.h Show annotated file Show diff for this revision Revisions of this file
--- a/slave.cpp	Sat Jul 05 06:38:13 2014 +0000
+++ b/slave.cpp	Mon Jul 07 07:28:35 2014 +0000
@@ -22,14 +22,14 @@
 
 
 
-void FUNC_I2C_SLAVE_MAIN(int slave_address,int iterations)
+void FUNC_I2C_SLAVE_MAIN(int iterations)
 {
     wait(0.5);
     screen.printf("\nSlave entered\n");
     slave.address(slave_address);                           //assigning slave address
-    int Switch_Variable;
-    int ReadAddressed=1;
-    int WriteGeneral=3;
+    char Switch_Variable;
+    
+    
     int loopvariable1=1;
     int loopvariable2=0;
     int loopvariable3=1;
@@ -48,7 +48,7 @@
       switch(Switch_Variable)
       {
       
-       case 1:    while(loopvariable3)
+       case '1':    while(loopvariable3)
                   {
                      if(slave.receive()==ReadAddressed)             //check if slave is addressed to read 
                    {
@@ -78,7 +78,7 @@
                     }//while(loopvariable3)
                   
                   break;
-         case 2 : screen.printf(" telecommand 2\n");
+         case '2' : screen.printf(" telecommand 2\n");
                   break;         
                  
         }//switch case ends
--- a/slave.h	Sat Jul 05 06:38:13 2014 +0000
+++ b/slave.h	Mon Jul 07 07:28:35 2014 +0000
@@ -1,4 +1,6 @@
 #include "mbed.h"
-
+#define WriteGeneral 3
+#define ReadAddressed 1
+#define slave_address 0x20
 void write_to_master(char);                    //function to write data to master
-void FUNC_I2C_SLAVE_MAIN(int slave_address,int iterations);
+void FUNC_I2C_SLAVE_MAIN(int iterations);