MAX11410 high speed 24-bit Delta-Sigma ADC

Dependents:   MAX11410BOB_24bit_ADC MAX11410BOB_Serial_Tester

Revision:
13:df96a784cda6
Parent:
12:daecd93dd33a
Child:
14:b49eecf7e4d8
--- a/MAX11410.cpp	Tue Feb 18 09:35:46 2020 +0000
+++ b/MAX11410.cpp	Thu Feb 20 10:45:05 2020 +0000
@@ -80,7 +80,9 @@
     // SPI CS = ActiveLow
     // SPI FrameStart = CS
     m_SPI_cs_state = 1;
-    m_cs_pin = m_SPI_cs_state;
+    if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
+        m_cs_pin = m_SPI_cs_state;
+    }
 
     // SPI CPOL = 0
     // SPI CPHA = 0
@@ -128,7 +130,9 @@
     // CODE GENERATOR: extern function definition for function SPIoutputCS
     // CODE GENERATOR: extern function definition for standard SPI interface function SPIoutputCS(int isLogicHigh)
     m_SPI_cs_state = isLogicHigh;
-    m_cs_pin = m_SPI_cs_state;
+    if (m_cs_pin.is_connected()) { // avoid mbed runtime error if pin is NC not connected
+        m_cs_pin = m_SPI_cs_state;
+    }
 }
 
 // CODE GENERATOR: extern function requirement MAX11410::SPIwrite16bits
@@ -1540,7 +1544,7 @@
 }
 
 //----------------------------------------
-// Menu item '$'
+// Menu item '$' -> AINcode[0], AINcode[1], AINcode[2], AINcode[3], AINcode[4], AINcode[5], AINcode[6], AINcode[7], AINcode[8], AINcode[9], AINcode[10]
 // Measure all ADC channels in sequence.
 // @post AINcode[0..10]: measurement result LSB code
 //
@@ -1622,9 +1626,14 @@
     //----------------------------------------
     // TODO1: wait until STATUS_enum_t::STATUS_000010_DATA_RDY indicates data is available
     #warning "Not Verified Yet: wait until STATUS indicates data is available"
-    // // TODO1: possible infinite loop; need a timeout or futility countdown to escape
-    // // TODO1: bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02
-    while ((status &  /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) {
+    // A bad SPI interface can cause bit slippage, which makes this loop get stuck. Expect *PART_ID? = 0x000F02
+    // while ((status &  /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0) {
+    // possible infinite loop; need a timeout or futility countdown to escape
+    for (int futility_countdown = 30;
+        ((futility_countdown > 0) &&
+        ((status &  /* MAX11410_STATUS_enum_t:: */ STATUS_000010_DATA_RDY) == 0));
+        futility_countdown--)
+    {
         RegRead(CMD_r011_1000_dddd_dddd_dddd_dddd_dxxx_dddd_STATUS, &status);
     }