test program to power up two MAX11410 ADCs and check the inputs of ADC1. Uses MAX11410 library.

Dependencies:   MAX11410 mbed

Files at this revision

API Documentation at this revision

Comitter:
laserdad
Date:
Wed Jan 10 02:17:31 2018 +0000
Parent:
5:d7b803aa9079
Commit message:
added serial prints

Changed in this revision

MAX11410.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r d7b803aa9079 -r c3db4eff9170 MAX11410.lib
--- a/MAX11410.lib	Fri Jan 05 22:37:07 2018 +0000
+++ b/MAX11410.lib	Wed Jan 10 02:17:31 2018 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/laserdad/code/MAX11410/#4784f0a3b76d
+https://os.mbed.com/users/laserdad/code/MAX11410/#5864c56ac8c5
diff -r d7b803aa9079 -r c3db4eff9170 main.cpp
--- a/main.cpp	Fri Jan 05 22:37:07 2018 +0000
+++ b/main.cpp	Wed Jan 10 02:17:31 2018 +0000
@@ -18,6 +18,8 @@
 #define MISO_1 D12
 #define SCLK_1 D13
 #define VDD 3.3
+
+
 AnalogOut vOut1(A3);
 AnalogOut vOut2(A4);
 DigitalOut cs_pin1(CS1);
@@ -27,6 +29,7 @@
 MAX11410 adc2(&spi,&cs_pin2);
 //Serial pc(USBTX, USBRX,115200);
 Serial pc(USBTX, USBRX, 9600);
+Serial rpi(PA_9,PA_10,115200);
 
 void starting()
 {
@@ -34,7 +37,10 @@
 }
 
 
-
+char getNthByte(int32_t data, int ind)
+{
+    return (data>>(8*ind)) & 0x000000FF ;
+}
 
 
 void print8bitRegsAdc1(char start_reg,char end_reg)
@@ -63,7 +69,7 @@
 int main() 
 {
     int32_t channel_data[10];
-    float vdiff=0.01;
+    double vdiff=0.01;
     vOut1 = 0.5-vdiff/2;
     vOut2 = 0.5+vdiff/2;
     starting();
@@ -158,10 +164,93 @@
     //config ADC 2: repeat above
     
     
+uint32_t checksum;
+char byte2print[40];
     
-//    while(1) 
-//    {
-//       
-//    }
+    while(1) 
+    {
+        for(int n=0; n<5; n++)
+        {
+            //read each channel
+            //select channel
+            char p_ch = 2*n<<4;
+            char n_ch = 2*n+1;
+            adc1.write8bitReg(REG_MUX_CTRL0, p_ch | n_ch );
+            
+            //select data output register and begin conversion
+            adc1.write8bitReg(REG_CONV_START, (_DEST(n) | SINGLE_CONV) );
+            
+            //optional: cal Gain
+            
+            //optional: cal Offset
+            
+            //optional: store cal parameters
+            
+            //begin conversion
+            
+            //wait for interrupt
+            while(!adc1.interrupt() )
+            {
+                wait_ms(CONV_DELAY_MS);//do nothing
+            }
+            
+            //read conversion
+           channel_data[n] = adc1.read24bitsSigned(REG_DATA0+n,&int_state);
+                     
+        }
+                for(int n=0; n<5; n++)
+        {
+            //read each channel
+            //select channel
+            char p_ch = 2*n<<4;
+            char n_ch = 2*n+1;
+            adc2.write8bitReg(REG_MUX_CTRL0, p_ch | n_ch );
+            
+            //select data output register and begin conversion
+            adc2.write8bitReg(REG_CONV_START, (_DEST(n) | SINGLE_CONV) );
+            
+            //optional: cal Gain
+            
+            //optional: cal Offset
+            
+            //optional: store cal parameters
+            
+            //begin conversion
+            
+            //wait for interrupt
+            while(!adc2.interrupt() )
+            {
+                wait_ms(CONV_DELAY_MS);//do nothing
+            }
+            
+            //read conversion
+           channel_data[n+5] = adc2.read24bitsSigned(REG_DATA0+n,&int_state);  
+        }
+            
+        //            calc checksum
+        checksum=0;
+        for (int n=0; n<10; n++)
+        {
+            checksum += channel_data[n];
+        }
+    
+        for (int n=0; n<10; n++)
+        {
+            for(int m=0;m<4;m++)
+            {
+               byte2print[n*4+m] = getNthByte(channel_data[n],3-m);
+            }
+        }
+        //print data and checksum
+        
+        //            print header 0x6601
+        rpi.putc(0x66);
+        rpi.putc(0x01);
+        for (int n =0; n<40;n++)
+        {
+            rpi.putc(byte2print[n]);
+        }
+        rpi.putc( (char) checksum );
+    } //end while
 
 } //END MAIN