Test application to demonstrate MCP4xxxx_SPI library

Dependencies:   DebugLibrary MCP4xxxx_SPI mbed

Revision:
3:7dbac45b8fd3
Parent:
1:a463807bf483
--- a/main.cpp	Sun Jan 27 17:11:44 2013 +0000
+++ b/main.cpp	Tue Jan 29 15:02:41 2013 +0000
@@ -2,6 +2,9 @@
 #include <iostream>
 #include <iomanip>
 
+/**
+ * Tests were done with schema proposed here: DS11195C-page 11 FIGURE 2-25: Potentiometer Divider Non-Linearity Error Test Circuit (DNL, INL)
+ */
 #include "MCP4xxxx_SPI.h"
 
 struct UserChoice {
@@ -20,15 +23,23 @@
  */
 DigitalOut g_availableLed(LED1); // To verify if program in running
 Ticker g_available; // LED1 will flash with a period of 2s
+#define __MANAGE_CS__ // /CS managed by application
+#undef  __MANAGE_CS__ // /CS managed by library
+#if defined(__MANAGE_CS__)
 DigitalOut g_chipSelect(p8); // /CS to select MCP4xxxx device
-CMCP4xxxx_SPI g_digitalPot(p5, p6, p7, NC, NC); // Create an instance of the class CMCP4xxxx_SPI, p5/p6/p7: SPI#1, /RESET input not connected, , /SHDN input not connected
+CMCP4xxxx_SPI g_digitalPot(p5, p6, p7, NC, NC, NC); // Create an instance of the class CMCP4xxxx_SPI, p5/p6/p7: SPI#1, /CS managed by application, /RESET input not connected, , /SHDN input not connected
+#else // __MANAGE_CS__
+CMCP4xxxx_SPI g_digitalPot(p5, p6, p7, p8, NC, NC); // Create an instance of the class CMCP4xxxx_SPI, p5/p6/p7: SPI#1, /CS managed by library, /RESET input not connected, , /SHDN input not connected
+#endif // __MANAGE_CS__
 UserChoice g_userChoice; // Used to store user choice from displayed menu
 
 int main() {
 
     unsigned char potLevel = 0x80; // Initial digital potentiometer value
     
-    g_chipSelect = 1; // Device is disabled 
+#if defined(__MANAGE_CS__)
+    g_chipSelect.write(1); // Disable chip
+#endif // __MANAGE_CS__
 
     // Launch available indicator
     g_available.attach(&AvailableIndicator, 2.0);
@@ -39,44 +50,66 @@
          switch (g_userChoice.choice) {
             case 'a':
                 potLevel += 1;
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(0);
+#endif // __MANAGE_CS__
                 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot1, potLevel);
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(1);
+#endif // __MANAGE_CS__
                 break;
             case 'b':
                 potLevel += 1;
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(0);
+#endif // __MANAGE_CS__
                 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot2, potLevel);
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(1);
+#endif // __MANAGE_CS__
                break;
             case 'c':
                 potLevel -= 1;
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(0);
+#endif // __MANAGE_CS__
                 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot1, potLevel);
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(1);
+#endif // __MANAGE_CS__
                 break;
             case 'd':
                 potLevel -= 1;
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(0);
+#endif // __MANAGE_CS__
                 g_digitalPot.Write(CMCP4xxxx_SPI::WriteToPot2, potLevel);
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(1);
+#endif // __MANAGE_CS__
                 break;
             case 'e':
                 potLevel -= 1;
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(0);
+#endif // __MANAGE_CS__
                 g_digitalPot.Write(CMCP4xxxx_SPI::ShutdownPot1);
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(1);
+#endif // __MANAGE_CS__
                 break;
             case 'f':
                 potLevel -= 1;
+#if defined(__MANAGE_CS__)
                 g_chipSelect.write(0);
+#endif // __MANAGE_CS__
                 g_digitalPot.Write(CMCP4xxxx_SPI::ShutdownPot2);
+ #if defined(__MANAGE_CS__)
                 g_chipSelect.write(1);
+#endif // __MANAGE_CS__
                 break;
             case 'r':
-                g_chipSelect.write(0);
                 g_digitalPot.Reset();
-                g_chipSelect.write(1);
                 break;
             default:
                 std::cout << "Invalid user choice\r" << std::endl;