Kevin Moloney
/
Nucleo_spi_master
test
main.cpp
- Committer:
- kevin1990
- Date:
- 2017-06-02
- Revision:
- 0:48b56cad57ae
- Child:
- 1:bb09fc532f44
File content as of revision 0:48b56cad57ae:
#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 } }