Martin Spencer / Mbed 2 deprecated SPIRW

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // Writes hex over SPI from pc input
00002 
00003 #include "mbed.h"
00004 
00005 SPI spi(p5, p6, p7); // mosi, miso, sclk
00006 DigitalOut cs(p10);
00007 
00008 Serial pc(USBTX, USBRX); // tx, rx
00009 
00010 int main() {
00011     spi.format(8,3);
00012     spi.frequency(1000000);
00013     wait(0.1);
00014 
00015 while(1){
00016 
00017 
00018 int n;
00019 pc.printf("hex: ");
00020 pc.scanf("%xx", &n);
00021 pc.printf("%xx", n);
00022 
00023     int o;
00024     
00025 pc.printf("hex2: ");
00026 pc.scanf("%xx", &o);
00027 pc.printf("%xx", o);
00028 
00029     // Select the device
00030     cs=0;
00031     int dataA = spi.write(n);
00032     //wait(0.01);
00033         int dataB = spi.write(o);
00034      cs=1;
00035     pc.printf("Data out = 0x%X\n", dataA);
00036 
00037    
00038     pc.printf("data out = 0x%X\n", dataB);
00039     wait(0.1);
00040     
00041 
00042 
00043 }    
00044 
00045 }