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

Dependencies:   mbed MCP320x TextLCD

Nucleo_mcp3204test.cpp

Committer:
SK_ROBO_
Date:
2016-01-28
Revision:
0:55aac36c4f0f
Child:
1:50f0c5749724

File content as of revision 0:55aac36c4f0f:

#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);
 
    // notify the user that we are starting with the ADC communication
    pc.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;
 
        // delay some time before reading again
        wait(1);
    }
}