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-10-04
- Revision:
- 6:66955ebd56dd
- Parent:
- 5:915a9d45c969
- Child:
- 7:4bb0c1e05e33
File content as of revision 6:66955ebd56dd:
#include "mbed.h" #include "rtos.h" #include "st7565LCD.h" #define SPI_SPEED (4000000) #define SPI_DUMMY_DATA (0x55) #define LOOP_N (8) 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); //ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0); ST7565 gLCD(PB_15, PB_13, PB_12, PB_2, PB_1); volatile bool isStepChanged = false; uint8_t prevSendVal = 0x00; void setChangeStep() { isStepChanged = true; } int main() { printf("\r\n\nNucleo rtos SPI Master Test..\r\n"); #if DEVICE_SPI_ASYNCH printf("DEVICE_SPI_ASYNCH: defined\r\n"); #else printf("DEVICE_SPI_ASYNCH: not defined\r\n"); #endif // Setup LCD gLCD.begin(0x10); gLCD.drawstring(0, 0, "SPI Master Test"); gLCD.display(); // 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); Thread::wait(1000); //gLCD.clear(); uint8_t count = 0; for (;;) { SpiMCs = 0; int step = -1; for (int i = 0; i < LOOP_N; i++) { uint8_t recievedVal = SpiM.write(count); if (isStepChanged) { step = recievedVal; isStepChanged = false; } count++; } SpiMCs = 1; if (step != -1) { char lineBuffer[20]; sprintf(lineBuffer, "Step: %02d", step); gLCD.drawstring(0, 0, lineBuffer); gLCD.display(); } Thread::wait(1); //wait_us(100); } }