Kevin Moloney / Mbed 2 deprecated Nucleo_spi_master

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 SPI spi(PA_7, PA_6, PA_5);          // mosi, miso, sclk
00004 DigitalOut cs(PB_6);
00005 DigitalOut syncPin (D8);
00006 
00007 Serial pc(USBTX, USBRX, 9600);      // tx, rx
00008  
00009 int main() {
00010  
00011     // set sync pin to known state
00012     syncPin  = 0;
00013     // Chip must be deselected
00014     cs = 1;
00015     int value = 4;
00016     
00017     spi.format(8,3);                // Setup:  bit data, high steady state clock, 2nd edge capture
00018     spi.frequency(1000000);         //1MHz
00019  
00020     // set sync pin high
00021     syncPin  = 1;
00022     for (int i = 0; i < 6; i++) {
00023         // Select device     
00024         cs = 0;                         
00025         spi.write(value);
00026         // Deselect device
00027         cs = 1;
00028         value++; 
00029     }
00030 }