spi_comm

Dependencies:   mbed

Fork of spi_comm by Raphaël Drouin

Committer:
Ishwar_Anjana
Date:
Mon Dec 25 17:47:44 2017 +0000
Revision:
1:5a737795f89c
Parent:
0:ff086cd5333c
hi

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ShaolinPoutine 0:ff086cd5333c 1 #include "mbed.h"
Ishwar_Anjana 1:5a737795f89c 2 #include "SPI.h"
Ishwar_Anjana 1:5a737795f89c 3 SPI spi(D11, D12, D13); // mosi, miso, sclk
Ishwar_Anjana 1:5a737795f89c 4 DigitalOut cs(D9);
Ishwar_Anjana 1:5a737795f89c 5
Ishwar_Anjana 1:5a737795f89c 6 char hello[14] = "Hello World \n";
ShaolinPoutine 0:ff086cd5333c 7 int main() {
ShaolinPoutine 0:ff086cd5333c 8 // Chip must be deselected
ShaolinPoutine 0:ff086cd5333c 9 cs = 1;
ShaolinPoutine 0:ff086cd5333c 10
ShaolinPoutine 0:ff086cd5333c 11 // Setup the spi for 8 bit data, high steady state clock,
ShaolinPoutine 0:ff086cd5333c 12 // second edge capture, with a 1MHz clock rate
Ishwar_Anjana 1:5a737795f89c 13 spi.format(8,0);
ShaolinPoutine 0:ff086cd5333c 14 spi.frequency(1000000);
ShaolinPoutine 0:ff086cd5333c 15
ShaolinPoutine 0:ff086cd5333c 16 // Select the device by seting chip select low
ShaolinPoutine 0:ff086cd5333c 17
ShaolinPoutine 0:ff086cd5333c 18 // Send 0x8f, the command to read the WHOAMI register
Ishwar_Anjana 1:5a737795f89c 19 //spi.write(0x8F);
ShaolinPoutine 0:ff086cd5333c 20
ShaolinPoutine 0:ff086cd5333c 21 // Send a dummy byte to receive the contents of the WHOAMI register
Ishwar_Anjana 1:5a737795f89c 22 while(1){
Ishwar_Anjana 1:5a737795f89c 23 cs = 0;
Ishwar_Anjana 1:5a737795f89c 24 for(int i=0; i<14; i++){
Ishwar_Anjana 1:5a737795f89c 25 spi.write(hello[i]);
Ishwar_Anjana 1:5a737795f89c 26 }
Ishwar_Anjana 1:5a737795f89c 27 wait(2);
Ishwar_Anjana 1:5a737795f89c 28 cs = 1;
Ishwar_Anjana 1:5a737795f89c 29 wait(1);
Ishwar_Anjana 1:5a737795f89c 30 }
ShaolinPoutine 0:ff086cd5333c 31
ShaolinPoutine 0:ff086cd5333c 32 // Deselect the device
ShaolinPoutine 0:ff086cd5333c 33 }