Carlo Collodi / kangaroo

Dependencies:   QEI mbed

Master.cpp

Committer:
sherryxy
Date:
2013-11-12
Revision:
13:8f54a702b9aa
Parent:
12:99c0f833a7de
Child:
15:4edd16cdc84b

File content as of revision 13:8f54a702b9aa:

#include "mbed.h"
#include "SPI.h"

SPI device(p5, p6, p7); //mosi, miso, sclk
DigitalOut cs1(p8); //cs1 = chip select - slave 1
DigitalOut cs2(p9); //cs2 = chip select - slave 2
DigitalOut cs3(p10); //cs3 = chip select - slave 3
 
int main() {
    // Chip must be deselected
    cs1 = 1;
    cs2 = 1;
    cs3 = 1;
    
    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    device.format(8,3);
    device.frequency(1000000);
 
    // Select the device by seting chip select low
    cs1 = 0;
 
    // Send 0x8f, the command to read the WHOAMI register
    device.write(0x8F);
 
    // Send a dummy byte to receive the contents of the WHOAMI register
    int whoami = device.write(0x00);
    printf("WHOAMI register = 0x%X\n", whoami);
 
    // Deselect the device
    cs1 = 1;
}