Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Nucleo_rtos_SPISlave_Test by
Diff: main.cpp
- Revision:
- 1:ba17cd3b6ecf
- Parent:
- 0:4cc5b11f7d91
- Child:
- 2:46e25b11a043
diff -r 4cc5b11f7d91 -r ba17cd3b6ecf main.cpp
--- a/main.cpp Tue Sep 27 06:00:48 2016 +0000
+++ b/main.cpp Tue Sep 27 09:46:20 2016 +0000
@@ -5,13 +5,26 @@
#define SPI_SPEED (10000000)
BusOut Leds(PA_10, PB_3, PB_5, PB_4, PB_10, PA_8);
+DigitalOut StepChangePin(PC_7);
SPISlave SpiS(PA_7, PA_6, PA_5, PA_4); // mosi, miso, sclk, ssel
+unsigned int step = 0;
+
+void stepUp(void const* arg)
+{
+ step++;
+
+ // Slaveにinterruptをかける。
+ StepChangePin.write(1);
+ StepChangePin.write(0);
+}
+
int main()
{
printf("\r\n\nNucleo rtos SPISlave Test..\r\n");
+ // Setup LED
for (int i = 0; i < 5; i++) {
Leds.write(0x3f);
Thread::wait(100);
@@ -19,17 +32,20 @@
Thread::wait(100);
}
+ // Setup SPISlave
SpiS.format(8, 0);
SpiS.frequency(SPI_SPEED);
- unsigned int count = 0;
+ // RtosTimer
+ RtosTimer stepTimer(stepUp, osTimerPeriodic, (void *)0);
+ stepTimer.start(250); // BPM:60
+
SpiS.reply(0);
while(1) {
if(SpiS.receive()) {
int v = SpiS.read(); // Read byte from master
Leds.write(v);
- SpiS.reply(count % 16);
- count++;
+ SpiS.reply(step % 16);
}
}
}
