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.
main.cpp
- Committer:
- martin
- Date:
- 2010-05-31
- Revision:
- 0:4568a8086f47
File content as of revision 0:4568a8086f47:
// Writes hex over SPI from pc input
#include "mbed.h"
SPI spi(p5, p6, p7); // mosi, miso, sclk
DigitalOut cs(p10);
Serial pc(USBTX, USBRX); // tx, rx
int main() {
spi.format(8,3);
spi.frequency(1000000);
wait(0.1);
while(1){
int n;
pc.printf("hex: ");
pc.scanf("%xx", &n);
pc.printf("%xx", n);
int o;
pc.printf("hex2: ");
pc.scanf("%xx", &o);
pc.printf("%xx", o);
// Select the device
cs=0;
int dataA = spi.write(n);
//wait(0.01);
int dataB = spi.write(o);
cs=1;
pc.printf("Data out = 0x%X\n", dataA);
pc.printf("data out = 0x%X\n", dataB);
wait(0.1);
}
}