Test, please delete

Revision:
7:4dbae381f693
Parent:
5:dbb2b71a59ed
--- a/main.cpp	Mon Sep 25 14:45:35 2017 +0000
+++ b/main.cpp	Fri Oct 20 15:58:01 2017 +0000
@@ -2,7 +2,9 @@
  ******************************************************************************
  * file:   main.cpp
  *-----------------------------------------------------------------------------
- *
+ */
+
+/*
 Copyright (c) 2017 Emutex Ltd. / Analog Devices, Inc.
 
 All rights reserved.
@@ -39,340 +41,197 @@
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *****************************************************************************/
-/******************************************************************************/
-/* Include Files                                                              */
-/******************************************************************************/
-#include "mbed.h"
-#include "inc/adisense1000.h"
-
-/*!
- ******************************************************************************
- * @file:   main.cpp
- * @brief:  Setup the following channels listed below to configure a burst of 5
- *          cycles to occur every 30 seconds.
- *          The time allocated to each individual cycle is 3 seconds
- */
-
-#define BITP_VALID_DATA     (7)
-#define SAMPLES_PER_CHANNEL (10)
-#define NUM_CHANNELS        (9)
-#define CYCLE_TIME (3)
-#define NUM_CYCLES_PER_FILL (5)
-#define MULTI_CYCLE_FILL_INTERVAL (30)
-
-void setupCJC0(void);    /* RTD 2-wire PT100 */
-void setupCJC1(void);    /* RTD 2-wire PT100 */
-void setupSENSOR0(void); /* RTD 2-wire PT100 */
-void setupSENSOR1(void); /* Thermocouple Type-K (compensation: CJC1) */
-void setupSENSOR2(void); /* Thermocouple Type-T (compensation: CJC0) */
-void setupSENSOR3(void); /* Thermocouple Type-J (compensation: CJC0) */
-void setupVOLTAGE(void); /* Honeywell Pressure (HSCMRNN1.6BAAA3) */
-void setupCURRENT(void); /* Honeywell Pressure (PX2CN2XX100PACH) */
-void setupI2C0(void);    /* Honeywell Humidity (HIH8000 Series) */
-
-Serial pc(PA_11, PA_12, 115200);
+*/
 
-ADI_Channel_Config_t CJC0;
-ADI_Channel_Config_t CJC1;
-ADI_Channel_Config_t SENSOR0;
-ADI_Channel_Config_t SENSOR1;
-ADI_Channel_Config_t SENSOR2;
-ADI_Channel_Config_t SENSOR3;
-ADI_Channel_Config_t VOLTAGE;
-ADI_Channel_Config_t CURRENT;
-ADI_Channel_Config_t I2C0;
-
-int main() {
-    uint8_t     chStatus        = 0;
-    uint16_t    deviceID        = 0;
-    uint32_t    rawSample       = 0;
-    float       processed        = 0;
-    bool        validSample     = 0;
-    bool        waitUntilReady  = true;
-    ADI_CORE_Status_t devStatus;
-    ADI_SENSE_RESULT retValue;
-
-    pc.printf("\r\n\r\n\r\n\r\n");
+#include "mbed.h"
+#include "inc/adi_sense_api.h"
+#include "inc/adi_sense_log.h"
 
-    retValue = ADISense1000_Open();
-    pc.printf("Host - Device Comms Opened with return:  %d\r\n", retValue);
-
-    pc.printf("Resetting ADI Sense 1000 device, please wait...\r\n");
-    retValue = ADISense1000_Reset(waitUntilReady);
-    pc.printf("Reset device with return:  %d\r\n", retValue);
-
-    retValue = ADISense1000_GetID(&deviceID);
-    pc.printf("Read device ID 0x%lx with return %d\r\n", deviceID, retValue);
+/* Define an arbitrary number of measurement cycles to execute */
+#define MAX_MEASUREMENT_CYCLES 10
 
-    retValue = ADISense1000_GetStatus(&devStatus);
-    pc.printf("Read Status 0x%lx with return %d\r\n", devStatus, retValue);
-
-    ADI_CORE_Mode_t modeReg;
-    modeReg.Conversion_Mode = CORE_MODE_MULTICYCLE;
-    modeReg.Drdy_Mode = CORE_MODE_DRDY_PER_FIFO_FILL;
-
-    retValue = ADISense1000_ConfigureModule(modeReg);
-    pc.printf("Configure Module with return %d\r\n", retValue);
-
-    ADI_CORE_Cycle_Control_t cycleControlReg;
-    cycleControlReg.Cycle_Time = CYCLE_TIME;
-    cycleControlReg.Cycle_Time_Units = CORE_CYCLE_CONTROL_SECONDS;
+#define ADI_SENSE_DEVICE_INDEX (0)
 
-    ADI_CORE_Fifo_Num_Cycles_t fifoNumCyclesReg;
-    fifoNumCyclesReg.Fifo_Num_Cycles = NUM_CYCLES_PER_FILL;
-
-    ADI_CORE_Multi_Cycle_Rate_t multiCycleRateReg;
-    multiCycleRateReg.Multi_Cycle_Rate = MULTI_CYCLE_FILL_INTERVAL;
-
-    retValue = ADISense1000_ConfigureCycleIntervals(cycleControlReg,
-                                                    fifoNumCyclesReg,
-                                                    multiCycleRateReg);
-    pc.printf("Configure Cycle Intervals with return %d\r\n", retValue);
-
-    setupCJC0();
-    pc.printf("\r\nStart CJC0 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_CJC0, &CJC0);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
+#define ASSERT(x)                                                       \
+do {                                                                    \
+    if (!(x))                                                           \
+    {                                                                   \
+        ADI_SENSE_LOG_ERROR("Assertion failed on line %d of %s",        \
+                            __LINE__, __FILE__);                        \
+        exit(1);                                                        \
+    }                                                                   \
+} while(0)
 
-    setupCJC1();
-    pc.printf("\r\nStart CJC1 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_CJC1, &CJC1);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    setupSENSOR0();
-    pc.printf("\r\nStart SENSOR0 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_SENSOR_0, &SENSOR0);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    setupSENSOR1();
-    pc.printf("\r\nStart SENSOR1 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_SENSOR_1, &SENSOR1);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    setupSENSOR2();
-    pc.printf("\r\nStart SENSOR2 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_SENSOR_2, &SENSOR2);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    setupSENSOR3();
-    pc.printf("\r\nStart SENSOR3 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_SENSOR_3, &SENSOR3);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
+extern ADI_SENSE_CONFIG adi_sense_config;
+extern ADI_SENSE_DSP_LUT_RAW adi_sense_dsp_lut;
 
-    setupVOLTAGE();
-    pc.printf("\r\nStart VOLTAGE Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_V_MEASURE, &VOLTAGE);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    setupCURRENT();
-    pc.printf("\r\nStart CURRENT Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_I_MEASURE, &CURRENT);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    setupI2C0();
-    pc.printf("\r\nStart I2C0 Channel Config \r\n");
-    retValue = ADISense1000_ConfigureChannel(ADI_SENSE_DIG_SENSOR_0, &I2C0);
-    pc.printf("Channel setup complete with return: %d\r\n", retValue);
-
-    ADI_CORE_Power_Config_t powerConfig;
-
-    powerConfig.Power_Mode_ADC = 3;  /* Full power */
-    powerConfig.Power_Mode_MCU = 0;  /* not yet defined */
-
-    retValue = ADISense1000_StartMeasurement(powerConfig, CORE_COMMAND_CONVERT_WITH_RAW);
-    pc.printf("Measurement started with return: %d\r\n\r\n", retValue);
-
-    /* In multi-cycle mode, a burst of measurement cycles will be executed at cycle intervals,
-       and then the burst is repeated at the multi-cycle interval */
-    while (true) {
-
-        pc.printf("\r\n\r\nWaiting for next multi-cycle fill to complete...\r\n\r\n");
-        /* Wait for the next cycle to complete */
-        while(!ADISense1000_SampleReady()) {
-        }
-
-
-        for(unsigned i=0; i<(SAMPLES_PER_CHANNEL*NUM_CHANNELS*NUM_CYCLES_PER_FILL); i++)
-        {
-            /* Read data from the enabled channels */
-            retValue = ADISense1000_GetData(&rawSample, &processed, &chStatus);
-            validSample = (chStatus >> BITP_VALID_DATA)&0x01;
-            pc.printf("-%s- :: Sample # %2d Channel # %2d :: -%s- :: Raw %8d  :: Processed %.7f\r\n",
-                      ((retValue>0) ? "ERROR" : "OK") , (i+1), (chStatus&0x0f), (validSample ? "VALID" : "INVALID"), rawSample, processed);
-        }
-    }
-
-}
+static ADI_SENSE_CONNECTION connectionInfo = {
+    .type = ADI_SENSE_CONNECTION_TYPE_SPI,
+    .spi = {
+        .mosiPin    = SPI_MOSI,
+        .misoPin    = SPI_MISO,
+        .sckPin     = SPI_SCK,
+        .csPin      = D10,
+        .maxSpeedHz = 2000000,
+    },
+    .gpio = {
+        .resetPin     = D6,
+        .errorPin     = D3,
+        .alertPin     = D4,
+        .datareadyPin = D5,
+    },
+};
 
 
-void setupCJC0(void)
+static void printSamples(ADI_SENSE_DATA_SAMPLE *pSampleBuffer, unsigned count)
 {
-    CJC0.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    CJC0.Count.Channel_Enable       =   1;
-
-    CJC0.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_RTD_2W_PT100;
-    CJC0.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-
-    CJC0.Details.CJC_Publish                =   1;
-    CJC0.Details.Vbias                      =   0;
-    CJC0.Details.Reference_Buffer_Disable   =   0;
-    CJC0.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_RINT1;
-    CJC0.Details.PGA_Gain                   =   3; /* G=8 */
-
-    CJC0.Excitation.IOUT_Excitation_Current     =   4; /* 500uA */
-    CJC0.Excitation.IOUT0_Disable               =   0;
-
-    CJC0.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    CJC0.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
+    for (unsigned i = 0; i < count; i++)
+    {
+        ADI_SENSE_LOG_DEBUG("sample %3u/%u: channel=%2u, value=%10f, raw=%10u, flags: %s %s",
+                            i+1, count,
+                            pSampleBuffer[i].channelId,
+                            pSampleBuffer[i].processedValue,
+                            pSampleBuffer[i].rawValue,
+                            pSampleBuffer[i].status & ADI_SENSE_DEVICE_STATUS_ERROR ? "ERROR" : "",
+                            pSampleBuffer[i].status & ADI_SENSE_DEVICE_STATUS_ALERT ? "ALERT" : "");
+    }
 }
 
-
-void setupCJC1(void)
+static void datareadyCallback(
+    ADI_SENSE_GPIO_PIN ePinId,
+    void *pArg)
 {
-    CJC1.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    CJC1.Count.Channel_Enable       =   1;
-
-    CJC1.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_RTD_2W_PT100;
-    CJC1.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-
-    CJC1.Details.CJC_Publish                =   1;
-    CJC1.Details.Vbias                      =   0;
-    CJC1.Details.Reference_Buffer_Disable   =   0;
-    CJC1.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_RINT1;
-    CJC1.Details.PGA_Gain                   =   3; /* G=8 */
-
-    CJC1.Excitation.IOUT_Excitation_Current =   4; /* 500uA */
-    CJC1.Excitation.IOUT0_Disable           =   0;
-
-    CJC1.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    CJC1.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
-
-
-void setupSENSOR0(void)
-{
-    SENSOR0.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    SENSOR0.Count.Channel_Enable       =   1;
+    volatile bool_t *pbDataready = (volatile bool_t *) pArg;
 
-    SENSOR0.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_RTD_2W_PT100;
-    SENSOR0.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-
-    SENSOR0.Details.Vbias                      =   0;
-    SENSOR0.Details.Reference_Buffer_Disable   =   0;
-    SENSOR0.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_RINT1;
-    SENSOR0.Details.PGA_Gain                   =   3; /* G=8 */
-
-    SENSOR0.Excitation.IOUT_Excitation_Current =   4; /* 500uA */
-    SENSOR0.Excitation.IOUT0_Disable           =   0;
-
-    SENSOR0.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    SENSOR0.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
-
-
-void setupSENSOR1(void)
-{
-    SENSOR1.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    SENSOR1.Count.Channel_Enable       =   1;
-
-    SENSOR1.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_THERMOCOUPLE_K;
-    SENSOR1.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-
-    SENSOR1.Details.Vbias                      =   1;
-    SENSOR1.Details.Reference_Buffer_Disable   =   1;
-    SENSOR1.Details.Compensation_Channel       =   1; /* CJC1 */
-    SENSOR1.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_INT;
-    SENSOR1.Details.PGA_Gain                   =   5; /* G=32 */
-
-    SENSOR1.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    SENSOR1.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
+    *pbDataready = true;
 }
 
-
-void setupSENSOR2(void)
-{
-    SENSOR2.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    SENSOR2.Count.Channel_Enable       =   1;
-
-    SENSOR2.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_THERMOCOUPLE_T;
-    SENSOR2.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-
-    SENSOR2.Details.Vbias                      =   1;
-    SENSOR2.Details.Reference_Buffer_Disable   =   1;
-    SENSOR2.Details.Compensation_Channel       =   0; /* CJC0 */
-    SENSOR2.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_INT;
-    SENSOR2.Details.PGA_Gain                   =   5; /* G=32 */
-
-    SENSOR2.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    SENSOR2.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
-
-
-void setupSENSOR3(void)
-{
-    SENSOR3.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    SENSOR3.Count.Channel_Enable       =   1;
-
-    SENSOR3.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_THERMOCOUPLE_J;
-    SENSOR3.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
-
-    SENSOR3.Details.Vbias                      =   1;
-    SENSOR3.Details.Reference_Buffer_Disable   =   1;
-    SENSOR3.Details.Compensation_Channel       =   0; /* CJC0 */
-    SENSOR3.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_INT;
-    SENSOR3.Details.PGA_Gain                   =   5; /* G=32 */
-
-    SENSOR3.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    SENSOR3.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
-
-
-void setupVOLTAGE(void)
+int main()
 {
-    VOLTAGE.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    VOLTAGE.Count.Channel_Enable       =   1;
+    ADI_SENSE_DEVICE_HANDLE hDevice;
+    ADI_SENSE_PRODUCT_ID productId;
+    ADI_SENSE_DATA_SAMPLE *pSampleBuffer;
+    ADI_SENSE_OPERATING_MODE eOperatingMode;
+    ADI_SENSE_DATA_PUBLISH_MODE eDataPublishMode;
+    uint32_t nSamplesPerDataready;
+    uint32_t nSamplesPerCycle;
+    bool_t bDeviceReady;
+
+    /*
+     * Open an ADI Sense device instance.
+     */
+    ASSERT(adi_sense_Open(0, &connectionInfo, &hDevice) == ADI_SENSE_SUCCESS);
 
-    VOLTAGE.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_VOLTAGE_PRESSURE1;
-    VOLTAGE.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
+    /*
+     * Reset the given ADI Sense device, and wait until the device is ready.
+     */
+    ADI_SENSE_LOG_INFO("Resetting ADI Sense device, please wait...");
+    ASSERT(adi_sense_Reset(hDevice) == ADI_SENSE_SUCCESS);
+
+    /*
+     * Wait until the device is ready.
+     */
+    do {
+        wait_ms(100);
+        ASSERT(adi_sense_GetDeviceReadyState(hDevice, &bDeviceReady) == ADI_SENSE_SUCCESS);
+    } while (! bDeviceReady);
+    ADI_SENSE_LOG_INFO("ADI Sense device ready");
 
-    VOLTAGE.Details.Vbias                      =   0;
-    VOLTAGE.Details.Reference_Buffer_Disable   =   1;
-    VOLTAGE.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_INT;
-    VOLTAGE.Details.PGA_Gain                   =   1; /* G=2 */
+    /*
+     * Read the product ID from the device registers.
+     */
+    ASSERT(adi_sense_GetProductID(hDevice, &productId) == ADI_SENSE_SUCCESS);
+    ADI_SENSE_LOG_INFO("Product ID: 0x%04X", productId);
+
+    /*
+     * Write configuration settings to the device registers.
+     * Settings are not applied until adi_sense_ApplyConfigUpdates() is called.
+     */
+    ASSERT(adi_sense_SetDeviceConfig(hDevice, &adi_sense_config) == ADI_SENSE_SUCCESS);
+    ASSERT(adi_sense_SetDspData(hDevice, &adi_sense_dsp_lut) == ADI_SENSE_SUCCESS);
+    ASSERT(adi_sense_ApplyConfigUpdates(hDevice) == ADI_SENSE_SUCCESS);
 
-    VOLTAGE.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    VOLTAGE.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
-
+    /*
+     * Allocate a buffer to store the samples retreived on each DATAREADY pulse
+     */
+    ASSERT(adi_sense_GetDataPublishingInfo(hDevice,
+                                           &eOperatingMode,
+                                           &eDataPublishMode,
+                                           &nSamplesPerDataready,
+                                           &nSamplesPerCycle) == ADI_SENSE_SUCCESS);
+    pSampleBuffer = new ADI_SENSE_DATA_SAMPLE[nSamplesPerDataready];
+    ASSERT(pSampleBuffer != NULL);
 
-void setupCURRENT(void)
-{
-    CURRENT.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    CURRENT.Count.Channel_Enable       =   1;
+    ADI_SENSE_LOG_INFO("Configuration loaded and applied, starting measurement cycles");
+
+    if (eOperatingMode == ADI_SENSE_OPERATING_MODE_SINGLECYCLE)
+    {
+        uint32_t nTotalCycles = 0;
 
-    CURRENT.Type.Sensor_Type           =   CORE_SENSOR_TYPE_SENSOR_CURRENT_PRESSURE1;
-    CURRENT.Type.Sensor_Category       =   CORE_SENSOR_TYPE_ANALOG;
+        /* For demonstration reasons only, we're using interrupt-triggered DATAREADY
+         * notifications in this mode */
+        volatile bool_t bDataReady = false;
+        ASSERT(adi_sense_RegisterGpioCallback(hDevice, ADI_SENSE_GPIO_PIN_DATAREADY,
+                                              datareadyCallback,
+                                              (void *)&bDataReady) == ADI_SENSE_SUCCESS);
+
+        do
+        {
+            ASSERT(adi_sense_StartMeasurement(hDevice) == ADI_SENSE_SUCCESS);
+
+            for (unsigned i = 0; i < nSamplesPerCycle / nSamplesPerDataready; i++)
+            {
+                uint32_t nReturned;
 
-    CURRENT.Details.Vbias                      =   0;
-    CURRENT.Details.Reference_Buffer_Disable   =   1;
-    CURRENT.Details.Reference_Select           =   CORE_SENSOR_DETAILS_REF_INT;
-    CURRENT.Details.PGA_Gain                   =   1; /* G=2 */
+                /*
+                 * Interrupt method: wait for DATAREADY interrupt callback
+                 *
+                 * Note that we could potentially enter a sleep mode here if this
+                 * GPIO interrupt is capable of waking the CPU...
+                 */
+                while (! bDataReady)
+                    ;
+                /* Reset bDataReady flag to detect the next callback */
+                bDataReady = false;
+
+                ASSERT(adi_sense_GetData(hDevice, pSampleBuffer, nSamplesPerDataready, &nReturned) == ADI_SENSE_SUCCESS);
+                ASSERT(nReturned == nSamplesPerDataready);
+
+                printSamples(pSampleBuffer, nReturned);
+            }
+            nTotalCycles++;
 
-    CURRENT.FilterSelect.ADC_Filter_Type       = CORE_FILTER_SELECT_FIR;
-    CURRENT.FilterSelect.ADC_FIR_Sel           = 3; /* 25 SPS */;
-}
+        } while (nTotalCycles < MAX_MEASUREMENT_CYCLES);
+    }
+    else
+    {
+        uint32_t nTotalSamples = 0;
+        bool_t bDataReady = false;
 
+        ASSERT(adi_sense_StartMeasurement(hDevice) == ADI_SENSE_SUCCESS);
+
+        do
+        {
+            uint32_t nReturned;
 
-void setupI2C0(void)
-{
-    I2C0.Count.Channel_Count        =   SAMPLES_PER_CHANNEL - 1;
-    I2C0.Count.Channel_Enable       =   1;
+            /* Polling method: continuously check DATAREADY until it is asserted */
+            do {
+                ASSERT(adi_sense_GetGpioState(hDevice, ADI_SENSE_GPIO_PIN_DATAREADY, &bDataReady) == ADI_SENSE_SUCCESS);
+            } while (! bDataReady);
+
+            ASSERT(adi_sense_GetData(hDevice, pSampleBuffer, nSamplesPerDataready, &nReturned) == ADI_SENSE_SUCCESS);
+            ASSERT(nReturned == nSamplesPerDataready);
+            nTotalSamples += nReturned;
 
-    I2C0.Type.Sensor_Type           =   CORE_SENSOR_TYPE_I2C_PRESSURE1;
-    I2C0.Type.Sensor_Category       =   CORE_SENSOR_TYPE_I2C;
+            printSamples(pSampleBuffer, nReturned);
+        } while ((nTotalSamples / nSamplesPerCycle) < MAX_MEASUREMENT_CYCLES);
 
-    I2C0.DigitalAddress.Digital_Sensor_Address = 0x27;
+        ASSERT(adi_sense_StopMeasurement(hDevice) == ADI_SENSE_SUCCESS);
+    }
+    delete [] pSampleBuffer;
+
+    ASSERT(adi_sense_Close(hDevice) == ADI_SENSE_SUCCESS);
+
+    return 0;
 }