A Simple program that simplifies development of SPI devices. It alows you to read and write to registers using a PC serial terminal in real time.

Dependencies:   mbed

Committer:
martin
Date:
Mon May 31 18:20:25 2010 +0000
Revision:
0:4568a8086f47

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martin 0:4568a8086f47 1 // Writes hex over SPI from pc input
martin 0:4568a8086f47 2
martin 0:4568a8086f47 3 #include "mbed.h"
martin 0:4568a8086f47 4
martin 0:4568a8086f47 5 SPI spi(p5, p6, p7); // mosi, miso, sclk
martin 0:4568a8086f47 6 DigitalOut cs(p10);
martin 0:4568a8086f47 7
martin 0:4568a8086f47 8 Serial pc(USBTX, USBRX); // tx, rx
martin 0:4568a8086f47 9
martin 0:4568a8086f47 10 int main() {
martin 0:4568a8086f47 11 spi.format(8,3);
martin 0:4568a8086f47 12 spi.frequency(1000000);
martin 0:4568a8086f47 13 wait(0.1);
martin 0:4568a8086f47 14
martin 0:4568a8086f47 15 while(1){
martin 0:4568a8086f47 16
martin 0:4568a8086f47 17
martin 0:4568a8086f47 18 int n;
martin 0:4568a8086f47 19 pc.printf("hex: ");
martin 0:4568a8086f47 20 pc.scanf("%xx", &n);
martin 0:4568a8086f47 21 pc.printf("%xx", n);
martin 0:4568a8086f47 22
martin 0:4568a8086f47 23 int o;
martin 0:4568a8086f47 24
martin 0:4568a8086f47 25 pc.printf("hex2: ");
martin 0:4568a8086f47 26 pc.scanf("%xx", &o);
martin 0:4568a8086f47 27 pc.printf("%xx", o);
martin 0:4568a8086f47 28
martin 0:4568a8086f47 29 // Select the device
martin 0:4568a8086f47 30 cs=0;
martin 0:4568a8086f47 31 int dataA = spi.write(n);
martin 0:4568a8086f47 32 //wait(0.01);
martin 0:4568a8086f47 33 int dataB = spi.write(o);
martin 0:4568a8086f47 34 cs=1;
martin 0:4568a8086f47 35 pc.printf("Data out = 0x%X\n", dataA);
martin 0:4568a8086f47 36
martin 0:4568a8086f47 37
martin 0:4568a8086f47 38 pc.printf("data out = 0x%X\n", dataB);
martin 0:4568a8086f47 39 wait(0.1);
martin 0:4568a8086f47 40
martin 0:4568a8086f47 41
martin 0:4568a8086f47 42
martin 0:4568a8086f47 43 }
martin 0:4568a8086f47 44
martin 0:4568a8086f47 45 }