![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
WHOAMI Example for the LIS302
Diff: main.cpp
- Revision:
- 0:51161d5d0bb2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Feb 23 23:33:36 2010 +0000 @@ -0,0 +1,26 @@ +#include "mbed.h" + +SPI spi (p11, p12, p13); +DigitalOut cs (p10); + +int main() { + + spi.format(8, 3); // 8 bit, mode 3 (high clk, 2nd edge capture) + spi.frequency(1000000); // 1MHz clock rate + + // Enable the device, and all three channels + cs = 0; + spi.write(0x20); + spi.write(0x40); + cs = 1; + + wait (0.01); + + // Send the command to read the WHOAMI register + cs = 0; + spi.write(0x8F); + char value = spi.write(0x00); + cs = 1; + + printf("WHOAMI register contains 0x%X\n", value); +}