Library for the MAX11300

Dependents:   MAX_IOT_KIT MAX_IOT_KIT

Fork of MAX11300 by Maxim Integrated

The MAX11300/01/11/12 are configurable mixed signal integrated circuits. The MAX11300/11 offer a SPI interface while the MAX11301/12 offer an I2C interface. The MAX11300/01 are 20 port devices while the MAX11311/12 are 12 port devices.

This library supports the family of parts by providing member functions that can manipulate the GPIO, ADC, DAC, and analog switches of the device, after it has been configured. For configuration of the device, this library requires a header file that can be generated by the MAX11300/01/11/12 Configuration Software. The configuration software can be found at the following link.

https://www.maximintegrated.com/en/products/analog/data-converters/analog-to-digital-converters/MAX11300.html/tb_tab2

Include the generated MAX113XXHex.h file into your project and update the #include in MAX113XX_Pixi.h.

Revision:
17:658202c79f33
Parent:
16:01d793a25548
Child:
18:8ee1928ffe6c
--- a/MAX113XX_Pixi.cpp	Thu May 11 20:28:40 2017 +0000
+++ b/MAX113XX_Pixi.cpp	Sat May 13 00:11:38 2017 +0000
@@ -526,8 +526,10 @@
 
 
 //*************************** I2C Implementation ******************************
-MAX113XX_I2C::MAX113XX_I2C(I2C &i2cBus, MAX113XX_Pixi::Device_e device, PinName cnvt):
-MAX113XX_Pixi(device, cnvt), m_i2cBus(i2cBus)
+MAX113XX_I2C::MAX113XX_I2C(I2C &i2cBus, MAX113XX_Pixi::Device_e device, 
+uint8_t i2cAdrs, PinName cnvt):
+MAX113XX_Pixi(device, cnvt), m_i2cBus(i2cBus), m_w_adrs(i2cAdrs << 1), 
+m_r_adrs((i2cAdrs << 1) | 1)
 {
     if((m_device == MAX11300) || (m_device == MAX11301)) //20 port device
     {
@@ -550,7 +552,14 @@
 //*********************************************************************
 void MAX113XX_I2C::writeRegister(uint8_t reg, const uint16_t data)
 {
+   char localData[3];
+   uint8_t idx = 0;
    
+   localData[idx++] = reg;
+   localData[idx++] = ((data & 0xFF00) >> 8);
+   localData[idx++] = (data & 0x00FF);
+   
+   m_i2cBus.write(m_w_adrs, localData, idx);
 }
 
 //*********************************************************************    
@@ -558,6 +567,18 @@
 {
     uint16_t rtn_val = 0;
     
+    char localData[2];
+    localData[0] = reg;
+    
+    if(m_i2cBus.write(m_w_adrs, localData, 1, true) == 0)
+    {
+        if(m_i2cBus.read(m_r_adrs, localData, 2) == 0)
+        {
+            rtn_val |= (localData[0] << 8);
+            rtn_val |= localData[1];
+        }
+    }
+    
     return rtn_val;
 }
 
@@ -565,11 +586,40 @@
 void MAX113XX_I2C::blockWrite(uint8_t reg, const uint16_t *data, 
                                const uint8_t num_reg)
 {
-    
+   uint16_t numBytes = ((num_reg * 2) + 1);
+   char localData[numBytes];
+   uint8_t idx(0), dataIdx(0);
+   
+   localData[idx++] = reg;
+   do
+   {
+       localData[idx++] = ((data[dataIdx] & 0xFF00) >> 8);
+       localData[idx++] = (data[dataIdx++] & 0x00FF);
+   }
+   while(idx < numBytes);
+   
+   m_i2cBus.write(m_w_adrs, localData, numBytes);   
 }
 
 //*********************************************************************        
 void MAX113XX_I2C::blockRead(uint8_t reg, uint16_t *data, const uint8_t num_reg)
 {
+    uint16_t numBytes = (num_reg * 2);
+    char localData[numBytes];
     
+    localData[0] = reg;
+    
+    if(m_i2cBus.write(m_w_adrs, localData, 1, true) == 0)
+    {
+        if(m_i2cBus.read(m_r_adrs, localData, numBytes) == 0)
+        {
+            uint8_t dataIdx = 0;
+            for(uint8_t idx = 0; idx < numBytes; idx += 2)
+            {
+                data[dataIdx] = 0;
+                data[dataIdx] |= (localData[idx] << 8);
+                data[dataIdx++] |= localData[idx + 1];
+            }
+        }
+    }
 }