Kevin Moloney
/
Nucleo_spi_master
test
Diff: main.cpp
- Revision:
- 0:48b56cad57ae
- Child:
- 1:bb09fc532f44
diff -r 000000000000 -r 48b56cad57ae main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Jun 02 09:14:50 2017 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" + +SPI spi(D11, D12, D13); // mosi, miso, sclk +DigitalOut chipSelect(D10); + +Serial pc(USBTX, USBRX); // tx, rx + +int main() { + + int valueToSendToSlave = 20; // Starting value only, this increments + spi.format(8,3); // Setup: bit data, high steady state clock, 2nd edge capture + spi.frequency(1000000); //1MHz + + pc.printf("======================================================\r\n"); + pc.printf("Press any key to start...\r\n"); + pc.getc(); // wait for keyboard + + int counter = 1; + while (1) { + + pc.printf("%d Value to send = %d ", counter++, valueToSendToSlave); + + chipSelect = 0; // Select device + int dataFromSlave = spi.write(valueToSendToSlave); + chipSelect = 1; // Deselect device + + pc.printf(" returns %d\r\n", dataFromSlave); + + valueToSendToSlave++; + + wait(5); // Wait for 5 seconds for readability only + + } +} \ No newline at end of file