Embedded system Fun Blog
























































Find out all the best information, libraries and circuit about the latest Embedded systems.

Sunday 8 January 2012

MBED SPI Sensor: How to read AD7904 output

.from: http://mbed.org/forum/mbed/topic/2444/

#include "mbed.h"

DigitalOut cs(p10);
SPI spi(p5, p6, p7);
Serial pc(USBTX, USBRX);

int adc;

int main()
{
    pc.baud(115200);
    pc.format(8,Serial::None,1);

    spi.format(16,3);
    spi.frequency(1000000);

   
    // dump read
    pc.printf("dump read\r\n");
    cs = 0;
    adc = spi.write(0x8300);
    cs = 1;
    pc.printf("ADC = %d\r\n", adc);

    // real reading
    pc.printf("real reading\r\n");
    cs = 0;
    adc = spi.write(0x0000);
    cs = 1;
    pc.printf("ADC = %d\r\n", adc);
}


No comments:

Post a Comment