![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
)))
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 00003 SPI spi(D11, D12, D13); 00004 DigitalOut cs(D9); 00005 AnalogOut my_output(PA_4); 00006 int SIZE; 00007 00008 int main() { 00009 while(1) 00010 { 00011 // Chip must be deselected 00012 cs = 1; 00013 00014 // Setup the spi for 8 bit data, high steady state clock, 00015 // second edge capture, with a 1MHz clock rate 00016 spi.format(8,0); 00017 spi.frequency(1000000); 00018 00019 // Select the device by seting chip select low 00020 cs = 0; 00021 00022 // Send 0x8f, the command to read the WHOAMI register 00023 spi.write(0x03); 00024 spi.write(0x00); 00025 spi.write(0x00); 00026 spi.write(0x00); 00027 00028 // Send a dummy byte to receive the contents of the WHOAMI register 00029 SIZE = 600000; 00030 for(int i=0; i<SIZE; i++) 00031 { 00032 uint16_t sample = spi.write(0x01); 00033 // my_output.write_u16(sample); 00034 //wait_us(125); 00035 } 00036 // Deselect the device 00037 cs = 1; 00038 } 00039 }
Generated on Tue Jul 12 2022 18:54:52 by
![doxygen](doxygen.png)