SPI Master used to test FPGA spi slave
Dependencies: mbed
Diff: main.cpp
- Revision:
- 2:24e22b31819c
- Parent:
- 1:f05471667f60
diff -r f05471667f60 -r 24e22b31819c main.cpp --- a/main.cpp Thu Sep 24 07:07:28 2015 +0000 +++ b/main.cpp Fri Sep 25 15:06:28 2015 +0000 @@ -1,6 +1,9 @@ #include "mbed.h" -/**/ -// https://developer.mbed.org/media/uploads/robt/mbed_course_notes_-_serial_spi.pdf +/* + SPI Master used to test the FPGA slave + https://developer.mbed.org/media/uploads/robt/mbed_course_notes_-_serial_spi.pdf +*/ + Serial serialIO(SERIAL_TX, SERIAL_RX); int main() { @@ -13,11 +16,16 @@ SPI spiMaster(PA_7, PA_6, PA_5); // mosi, miso, sclk DigitalOut chipSelect(PB_6); spiMaster.format(8,0); - spiMaster.frequency(5000000); + int frequency; + serialIO.printf("Choose SPI freq:\r\n"); + serialIO.scanf("%d",&frequency); + serialIO.printf("Setting frequency: %d\r\n",frequency); + spiMaster.frequency(frequency); //5000000 chipSelect = 1; int mode = 0; int byteToSend = 0; int countPackages = 3; + int foreverMode = 0; while(1) { if ((!byteToSend) || (countPackages == 0)) @@ -27,16 +35,30 @@ spiMaster.format(8,mode); serialIO.printf("Type the byte value to send, then press ENTER\r\n"); serialIO.scanf("%d",&byteToSend); - serialIO.printf("Number of times to send, then press ENTER\r\n"); - serialIO.scanf("%d",&countPackages); - serialIO.printf("Sending %d packages on mode %d\r\n",countPackages,mode); + serialIO.printf("Number of times to send, then press ENTER (-1) is forever\r\n"); + serialIO.scanf("%d",&countPackages); + if (countPackages < 0) + { + foreverMode = 1; + serialIO.printf("Sending %d packages on mode %d with freq: %d (FOREVER)\r\n",countPackages,mode,frequency); + } + else + serialIO.printf("Sending %d packages on mode %d with freq: %d\r\n",countPackages,mode,frequency); + } chipSelect = 0; int resp = spiMaster.write(byteToSend); - chipSelect = 1; - serialIO.printf("Sending data<%d> received<%d> %d times\r\n",byteToSend, resp, countPackages); + chipSelect = 1; wait_us(2); - byteToSend++; + if (!foreverMode) + { + serialIO.printf("Sending data<%d> received<%d> %d times\r\n",byteToSend, resp, countPackages); + byteToSend++; + } + else + { + serialIO.printf("Sending data<%d> received<%d> %d times at freq:%d\r\n",byteToSend, resp, countPackages,frequency); + } countPackages--; } }