demo demo / Mbed 2 deprecated LIS302HelloWorld

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 SPI spi (p11, p12, p13);
00004 DigitalOut cs (p10);
00005 
00006 int main() {
00007 
00008     spi.format(8, 3);         // 8 bit, mode 3 (high clk, 2nd edge capture)
00009     spi.frequency(1000000);   // 1MHz clock rate
00010 
00011     // Enable the device, and all three channels
00012     cs = 0;
00013     spi.write(0x20);
00014     spi.write(0x40);
00015     cs = 1;
00016 
00017     wait (0.01);
00018 
00019     // Send the command to read the WHOAMI register
00020     cs = 0;
00021     spi.write(0x8F);
00022     char value = spi.write(0x00);
00023     cs = 1;
00024 
00025     printf("WHOAMI register contains 0x%X\n", value);
00026 }