Carlo Collodi / kangaroo

Dependencies:   QEI mbed

Committer:
sherryxy
Date:
Tue Nov 12 21:24:53 2013 +0000
Revision:
13:8f54a702b9aa
Parent:
12:99c0f833a7de
Child:
15:4edd16cdc84b
communication chipselecting1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sherryxy 12:99c0f833a7de 1 #include "mbed.h"
sherryxy 12:99c0f833a7de 2 #include "SPI.h"
sherryxy 12:99c0f833a7de 3
sherryxy 13:8f54a702b9aa 4 SPI device(p5, p6, p7); //mosi, miso, sclk
sherryxy 13:8f54a702b9aa 5 DigitalOut cs1(p8); //cs1 = chip select - slave 1
sherryxy 13:8f54a702b9aa 6 DigitalOut cs2(p9); //cs2 = chip select - slave 2
sherryxy 13:8f54a702b9aa 7 DigitalOut cs3(p10); //cs3 = chip select - slave 3
sherryxy 13:8f54a702b9aa 8
sherryxy 13:8f54a702b9aa 9 int main() {
sherryxy 13:8f54a702b9aa 10 // Chip must be deselected
sherryxy 13:8f54a702b9aa 11 cs1 = 1;
sherryxy 13:8f54a702b9aa 12 cs2 = 1;
sherryxy 13:8f54a702b9aa 13 cs3 = 1;
sherryxy 13:8f54a702b9aa 14
sherryxy 13:8f54a702b9aa 15 // Setup the spi for 8 bit data, high steady state clock,
sherryxy 13:8f54a702b9aa 16 // second edge capture, with a 1MHz clock rate
sherryxy 13:8f54a702b9aa 17 device.format(8,3);
sherryxy 13:8f54a702b9aa 18 device.frequency(1000000);
sherryxy 13:8f54a702b9aa 19
sherryxy 13:8f54a702b9aa 20 // Select the device by seting chip select low
sherryxy 13:8f54a702b9aa 21 cs1 = 0;
sherryxy 13:8f54a702b9aa 22
sherryxy 13:8f54a702b9aa 23 // Send 0x8f, the command to read the WHOAMI register
sherryxy 13:8f54a702b9aa 24 device.write(0x8F);
sherryxy 13:8f54a702b9aa 25
sherryxy 13:8f54a702b9aa 26 // Send a dummy byte to receive the contents of the WHOAMI register
sherryxy 13:8f54a702b9aa 27 int whoami = device.write(0x00);
sherryxy 13:8f54a702b9aa 28 printf("WHOAMI register = 0x%X\n", whoami);
sherryxy 13:8f54a702b9aa 29
sherryxy 13:8f54a702b9aa 30 // Deselect the device
sherryxy 13:8f54a702b9aa 31 cs1 = 1;
sherryxy 13:8f54a702b9aa 32 }