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.
Dependencies: mbed-rtos mbed st7565LCD
main.cpp
- Committer:
- ryood
- Date:
- 2016-09-29
- Revision:
- 1:74e13cd94576
- Parent:
- 0:36cebc939c49
- Child:
- 2:95204570426c
File content as of revision 1:74e13cd94576:
#include "mbed.h" #include "rtos.h" #define SPI_SPEED (10000000) BusOut Leds(PA_8, PB_10, PB_4, PB_5); BusIn Switches(PA_0, PA_1, PA_4, PB_0, PC_1, PC_0); SPI SpiM(PA_7, PA_6, PA_5); // mosi, miso, sclk DigitalOut SpiMCs(PB_6); InterruptIn stepChangeInterrupt(PC_7); //DigitalOut myled(PA_10); volatile bool isStepChanged = false; uint8_t prevSendVal = 0x00; //float delay = 1.0f; void setChangeStep() { isStepChanged = true; /* static uint8_t f = 0x0f; Leds.write(f); f = ~f & 0x0f; */ /* if (delay == 1.0) delay = 0.2; // 200 ms else delay = 1.0; // 1 sec */ } int main() { printf("\r\n\nNucleo rtos SPI Master Test..\r\n"); // LED Check for (int i = 0; i < 5; i++) { Leds.write(0x0f); Thread::wait(100); Leds.write(0x00); Thread::wait(100); } // Setup Switches Switches.mode(PullUp); /* while(1) { printf("%x\r\n", ~Switches.read() &0x3f); Thread::wait(100); } */ // Setup Interrupt stepChangeInterrupt.fall(&setChangeStep); // Setup SPI SpiMCs = 1; SpiM.format(8, 0); SpiM.frequency(SPI_SPEED); for (;;) { uint8_t sendVal = ~Switches.read(); static uint8_t receivedVal; //if (prevSendVal != sendVal) { SpiMCs = 0; receivedVal = SpiM.write(sendVal); SpiMCs = 1; prevSendVal = sendVal; //} if (isStepChanged) { Leds.write(receivedVal & 0x0f); isStepChanged = false; } } }