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-01
- Revision:
- 3:2b2c6c0e9f1d
- Parent:
- 2:95204570426c
- Child:
- 4:c2b67c69d048
File content as of revision 3:2b2c6c0e9f1d:
#include "mbed.h" #include "rtos.h" #include "st7565LCD.h" #define SPI_SPEED (10000000) 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); PwmOut LCDBackLight(PA_11); volatile bool isStepChanged = false; uint8_t prevSendVal = 0x00; void setChangeStep() { isStepChanged = true; } int main() { printf("\r\n\nNucleo rtos SPI Master Test..\r\n"); // Setup LCD LCDBackLight.period_ms(10); LCDBackLight = 0.6f; Thread::wait(10); 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); for (;;) { uint8_t sendVal = ~Switches.read(); if (prevSendVal != sendVal || isStepChanged) { SpiMCs = 0; uint8_t receivedVal = SpiM.write(sendVal); SpiMCs = 1; prevSendVal = sendVal; if (isStepChanged) { char lineBuffer[32]; sprintf(lineBuffer, "Step: %02d", receivedVal); gLCD.drawstring(0, 1, lineBuffer); gLCD.display(); isStepChanged = false; } } } }