Initial I2C Working

Dependencies:   mbed

Revision:
1:444546e8cd20
Parent:
0:fbf82bf637bb
Child:
2:832cb4376d2a
diff -r fbf82bf637bb -r 444546e8cd20 MCP9803/MCP9803.cpp
--- a/MCP9803/MCP9803.cpp	Wed Mar 29 08:33:10 2017 +0000
+++ b/MCP9803/MCP9803.cpp	Wed Mar 29 12:20:34 2017 +0000
@@ -26,6 +26,8 @@
     _I2C -> stop();
     
     chipAddress = Address;
+    
+    inBuffer = (char *)malloc(1);
 }
 
 int MCP9803::ConfigSensor()
@@ -55,18 +57,25 @@
 
 char *MCP9803::I2C_Read(int dataLen)
 {
-    char inBuffer[dataLen];
+    setBufferSize(dataLen);
     
     int receiveStatus = _I2C -> read(chipAddress,inBuffer,dataLen,0);
-    
+   
     if(receiveStatus != 0)
     {
         for(int i = 0; i < dataLen; i++)
         {
-            inBuffer[i] = 0xFF - i;
+            if(i % 2 == 0)
+            {
+                inBuffer[i] = 0xFF;
+            }
+            else
+            {
+                inBuffer[i] = 0x00;
+            }
             printf("Buffer Value = %02x",inBuffer[i]);
         }
-    return inBuffer;
+        return inBuffer;
     }
     
     else
@@ -76,6 +85,22 @@
 
 }
     
+void MCP9803::setBufferSize(int dataLen)
+{
+    inBuffer = (char *)realloc(inBuffer, dataLen);
+}
+    
+char *MCP9803::getBuffer()
+{    
+    
+}
+
+void MCP9803::setBuffer()
+{
+    
+}
+  
+    
 
 /********************************************************************************************