Control Code with I/O and ADC working

Dependencies:   MODSERIAL mbed

Revision:
19:0946665b37c7
Parent:
18:aaec99ca68c3
Child:
20:cdeed4dad690
diff -r aaec99ca68c3 -r 0946665b37c7 main.cpp
--- a/main.cpp	Wed Jun 20 18:33:26 2018 +0000
+++ b/main.cpp	Thu Jun 28 21:30:44 2018 +0000
@@ -14,8 +14,8 @@
 #define DEBUG2               0
 #define DEBUG3               0
 #define DEBUG5               0
-#define UID_PRINT            1
-#define TEMP_PRINT           0
+#define UID_PRINT            0
+#define TEMP_PRINT           1
 #define LOOP_TIME            0  
 #define CHN_COUNT            8
 #define MIN_TEMP             10
@@ -725,7 +725,7 @@
    Returns: N/A
 */
 
-void error_check(int chnl, float currentTempFront, float currentTempBack, int currTimeMin){
+void error_check(int chnl, float currentTempFront, float currentTempBack, int currTimeMin, int ioSDA, int adcSDA){
     if((currentTempFront >= MAX_TEMP) && (currentTempBack >= MAX_TEMP)){
         status_led(chnl, STATUS_BAD);
         sendError(chnl, 1);
@@ -766,10 +766,19 @@
             if(DEBUG3) pc.printf("DBG: [%d] ERROR 5 \r\n", chnl);
         }
     }
+    //check that the SDA lines aren't stuck low
+    if((ioSDA != 1) || (adcSDA != 1)){
+            status_led(chnl, STATUS_BAD);
+            sendError(chnl, 6);
+            chnlStatus[chnl].error = 1;
+            chnlStatus[chnl].heater_init_time = 0;
+            if(DEBUG3) pc.printf("DBG: [%d] ERROR 6 \r\n", chnl);
+    }        
     if(chnlStatus[chnl].error == 1){
         status_led(chnl, STATUS_BAD);
         chnlStatus[chnl].error = 1;
     }
+    
 }
 
 
@@ -851,9 +860,19 @@
             
             //float currentTempBack = get_temp(chnl, BACK_THERM);
             float currentTemp = currentTempBack;
+            
+            //check if I2C dataline is pulled high
+            DigitalIn isoSDAIn(PTC9);
+            DigitalIn adcSDAIn(PTC11);
+            int isoSDA = isoSDAIn.read();
+            int adcSDA = adcSDAIn.read();
+            pc.printf("DBG: TEMPERATURE SDA LINE: %d \r\n", isoSDA);
+            pc.printf("DBG: IO SDA LINE: %d \r\n", adcSDA);
+            MCP23008 io_control(PTC9, PTC8, 0x10, 100000); //sda, scl
+            LTC2487 ltc2487(PTC11, PTC10, 0x23, 100000); //sda, scl
 
             //Error check on fixture
-            error_check(chnl, currentTempFront, currentTempBack, time_min);
+            error_check(chnl, currentTempFront, currentTempBack, time_min, isoSDA, adcSDA);
 
             if(TEMP_PRINT) pc.printf("DBG: TEMPERATURE: [%d] Temp: F: %f B: %f\r\n", chnl, currentTempFront, currentTempBack);