)))

Dependencies:   mbed

main.cpp

Committer:
lucem1n
Date:
2019-03-25
Revision:
0:69fc4661515e

File content as of revision 0:69fc4661515e:

#include "mbed.h"
 
SPI spi(D11, D12, D13);
DigitalOut cs(D9);
AnalogOut my_output(PA_4);
int SIZE;
 
int main() {
    while(1)
    {
    // Chip must be deselected
    cs = 1;
 
    // Setup the spi for 8 bit data, high steady state clock,
    // second edge capture, with a 1MHz clock rate
    spi.format(8,0);
    spi.frequency(1000000);
 
    // Select the device by seting chip select low
    cs = 0;
 
    // Send 0x8f, the command to read the WHOAMI register
    spi.write(0x03);
    spi.write(0x00);
    spi.write(0x00);
    spi.write(0x00);
     
    // Send a dummy byte to receive the contents of the WHOAMI register
    SIZE = 600000;
    for(int i=0; i<SIZE; i++)
    {
    uint16_t sample = spi.write(0x01);
   // my_output.write_u16(sample);
    //wait_us(125);
    }
    // Deselect the device
    cs = 1;
    }
    }