Simple driver for the 20-bit ADC MAX1120x from Maxim

Files at this revision

API Documentation at this revision

Comitter:
macgyveremir
Date:
Tue Oct 23 19:09:00 2012 +0000
Parent:
2:26afdc979a54
Commit message:
Working implementation. Can easily be extended to include higher-level functions

Changed in this revision

MAX1120x.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/MAX1120x.cpp	Fri Oct 12 18:30:48 2012 +0000
+++ b/MAX1120x.cpp	Tue Oct 23 19:09:00 2012 +0000
@@ -12,15 +12,19 @@
 void MAX1120x::do_self_calibration ()
 {
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_action(ACT_SELF_CAL));
     *cs = 1;
-    wait_ms(202);
+    wait_ms (202);
 }
 
 void MAX1120x::calibrate_system_zero ()
 {
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_action(ACT_SYS_OFF_CAL));
     *cs = 1;
@@ -30,6 +34,8 @@
 void MAX1120x::calibrate_system_gain ()
 {
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_action(ACT_SYS_GAN_CAL));
     *cs = 1;
@@ -41,6 +47,8 @@
     char value;
     
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_read(REG_STAT1));
     value = (char) spi->write(0);
@@ -52,6 +60,8 @@
 void MAX1120x::set_control_1 (char ctrl)
 {
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_write(REG_CTRL1));
     spi->write (ctrl);
@@ -63,6 +73,8 @@
     char value;
     
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_read(REG_CTRL1));
     value = (char) spi->write(0);
@@ -74,6 +86,8 @@
 void MAX1120x::set_control_2 (char ctrl)
 {
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_write(REG_CTRL2));
     spi->write (ctrl);
@@ -85,6 +99,8 @@
     char value;
     
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_read(REG_CTRL2));
     value = (char) spi->write(0);
@@ -96,6 +112,8 @@
 void MAX1120x::set_control_3 (char ctrl)
 {
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_write(REG_CTRL3));
     spi->write (ctrl);
@@ -107,6 +125,8 @@
     char value;
     
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_read(REG_CTRL3));
     value = (char) spi->write(0);
@@ -120,6 +140,8 @@
     UI32toC_t sample;
     
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_action(ACT_CONV_1SPS));
     *cs = 1;
@@ -143,6 +165,8 @@
     UI32toC_t data;
         
     spi->format (8, MAX1120x_SPI_MODE);
+    wait_us (5);
+    
     *cs = 0;
     spi->write (mode_register_read(register_add));
     data.bytes[2] = (char) spi->write(0);