This is test program of mcp3204. This is operating normally.

Dependencies:   mbed MCP320x TextLCD

Revision:
1:50f0c5749724
Parent:
0:55aac36c4f0f
--- a/Nucleo_mcp3204test.cpp	Thu Jan 28 05:34:51 2016 +0000
+++ b/Nucleo_mcp3204test.cpp	Fri Jan 29 03:02:09 2016 +0000
@@ -1,47 +1,34 @@
 #include "mbed.h"
- 
-SPI spi(D11, D12, D13); // mosi(out), miso(in), sclk(clock)
-DigitalOut cs(D10); // cs (the chip select signal)
- 
-Serial pc(USBTX, USBRX); // tx, rx ( the usb serial communication )
- 
-int main() {
-    // Setup the spi for 7 bit data, high steady state clock,
-    // second edge capture, with a 1MHz clock rate
-    spi.format(7,0);
-    spi.frequency(1000000);
- 
+#include "TextLCD.h"
+
+#include "MCP320x.h"
+
+#define MOSI    D11
+#define MISO    D12
+#define CLK     D13
+#define CS      D10
+#define CHIPFAMILLY     CMCP320x_SPI::_3204
+#define FREQ    100000
+
+TextLCD lcd(PB_0, PB_1, PA_12, PF_0, PF_1, PA_8, TextLCD::LCD20x2); // rs, e, d4-d7
+
+CMCP320x_SPI mcp3204(MOSI, MISO, CLK, CS, CHIPFAMILLY, FREQ);
+
+int main()
+{
     // notify the user that we are starting with the ADC communication
-    pc.printf("Starting ADC interaction\n");
-    
+    printf("Starting ADC interaction\n");
+
     // lets just do this forever
     while (1) {
- 
-        // Select the device by seting chip select low
-        cs = 0;
- 
-        // sending the 6 bits + 1 bit to ignore the null bit
-        // coming from the device, so the data that is sent is 1100000
-        spi.write(0x60);
-        
-        // now the device sends back the readings 12 bits, 7 bits at a time
-        uint8_t high = spi.write(0x00);
-        uint8_t low = spi.write(0x00);
- 
-        // shift out the right bits
-        low = ( high << 5 ) | (low >> 2);
-        high = high >> 3;
-        
-        // shift and or the result together
-        int value = ( high << 7 ) | low;
-        
-        // and voila we have the value and we can print it for the user
-        pc.printf("sensor 0 value = %u\n", value);
- 
-        // Deselect the device
-        cs = 1;
- 
+        //lcd.cls();
+        lcd.printf("CH0:%3.2f[deg]\n", mcp3204.Read(CMCP320x_SPI::CH0)/*/ 4095.0f*270.0f */);
+        lcd.printf("CH1:%3.2f[deg]\n", mcp3204.Read(CMCP320x_SPI::CH1)/*/ 4095.0f*270.0f */);
         // delay some time before reading again
-        wait(1);
+        wait(0.5);
+        lcd.printf("CH2:%3.2f[deg]\n", mcp3204.Read(CMCP320x_SPI::CH2)/*/ 4095.0f*270.0f */);
+        lcd.printf("CH3:%3.2f[deg]\n", mcp3204.Read(CMCP320x_SPI::CH3)/*/ 4095.0f*270.0f */);
+        // delay some time before reading again
+        wait(0.5);
     }
 }
\ No newline at end of file