Embedded system Fun Blog
























































Find out all the best information, libraries and circuit about the latest Embedded systems.
Showing posts with label mems. Show all posts
Showing posts with label mems. Show all posts

Sunday, 8 January 2012

MBED Snipet: Reading the WHOAMI register of an LIS302 accelerometer using SPI

.from: http://mbed.org/handbook/SPI?action=view&revision=442

#include "mbed.h"

SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p8);

Serial pc(USBTX, USBRX); // tx, rx

int main() {
    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    spi.format(8,3);
    spi.frequency(1000000);

    // Select the device by seting chip select low
    cs = 0;

    // Send 0x8f, the command to read the WHOAMI register
    spi.write(0x8F);

    // Send a dummy byte to receive the contents of the WHOAMI register
    int whoami = spi.write(0x00);
    pc.printf("WHOAMI register = 0x%X\n", whoami);

    // Deselect the device
    cs = 1;
}
 
/media/uploads/mbedofficial/spi_interfaces.png