This is test program of mcp3204. This is operating normally.
Dependencies: mbed MCP320x TextLCD
Diff: Nucleo_mcp3204test.cpp
- Revision:
- 0:55aac36c4f0f
- Child:
- 1:50f0c5749724
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Nucleo_mcp3204test.cpp Thu Jan 28 05:34:51 2016 +0000 @@ -0,0 +1,47 @@ +#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); + } +} \ No newline at end of file