Test for mike

Dependencies:   mbed DevInterfaces MCP4728 MCP4728setaddr I2Cinterfaces

Files at this revision

API Documentation at this revision

Comitter:
wbeaumont
Date:
Wed Jan 13 14:15:21 2016 +0000
Child:
1:d175631a5803
Commit message:
inital not tested with MCP4728 , but was tested in the SOLID project

Changed in this revision

DevInterfaces.lib Show annotated file Show diff for this revision Revisions of this file
I2Cinterfaces.lib Show annotated file Show diff for this revision Revisions of this file
MCP4728.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DevInterfaces.lib	Wed Jan 13 14:15:21 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/wbeaumont/code/DevInterfaces/#58f1d5a3f850
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/I2Cinterfaces.lib	Wed Jan 13 14:15:21 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/wbeaumont/code/I2Cinterfaces/#80ebfbf95667
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MCP4728.lib	Wed Jan 13 14:15:21 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/wbeaumont/code/MCP4728/#f45f4ff5a51a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 13 14:15:21 2016 +0000
@@ -0,0 +1,64 @@
+#include "mbed.h"
+
+#if   defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
+  PinName const SDA = PTE25;
+  PinName const SCL = PTE24;
+#elif defined (TARGET_KL05Z)
+  PinName const SDA = PTB4;
+  PinName const SCL = PTB3;
+#elif defined (TARGET_K20D50M)
+  PinName const SDA = PTB1;
+  PinName const SCL = PTB0;
+#else
+  #error TARGET NOT DEFINED
+#endif
+
+
+#include "I2C.h"
+#include "I2CInterface.h" 
+#include "MBEDI2CInterface.h" 
+#include "DACInterface.h" 
+#include "dev_interface_def.h"
+#include "mcp4728.h"
+
+MBEDI2CInterface mbedi2c( SDA, SCL); 
+MBEDI2CInterface* mbedi2cp=  &mbedi2c ;
+I2CInterface* i2cdev= mbedi2cp;
+const float Vdd=5.0;
+
+Serial pc(USBTX, USBRX);
+
+int main(void) {
+  
+   // get the version of getVersion 
+   getVersion gv;
+   printf("getVersion :%s\n\r",gv.getversioninfo());
+   
+   MCP4728  dac( i2cdev ,0, Vdd);  // assuming the address  of the MCP4728 is set to 0 factory default 
+   printf("MCP4728 :%s\n\r",dac.getversioninfo());
+   wait(4);
+   float voltage=0;
+   int cnt=0;
+   while(1){
+           // first set the 4 channels 
+           for ( int cc =0 ; cc <4 ; cc++) { 
+               if ( dac.setDACvalue(cnt,cc) )
+                   printf("failed to set dac value %d for channel %d\n\r",cnt,cc);
+            }
+            printf("set DAC value  to %d result in",cnt);
+               // no else read anyway even if set fails 
+            for ( int cc =0 ; cc <4 ; cc++) { 
+                if ( dac.getVoltage(voltage,cc)) 
+                    printf("\n\rfailed to readback voltage for channel %d\n\r",cc);    
+                else 
+                  printf(" CH%d %f[V]",cc,voltage);
+             }
+             printf("\n\r");
+             cnt++;
+             cnt=cnt % 4096;     
+             wait_ms(200);
+
+  }  
+    // never reach this   
+    return 1;
+}   
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 13 14:15:21 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c
\ No newline at end of file