diff --git a/main.c b/main.c --- a/main.c +++ b/main.c @@ -2,8 +2,8 @@ #include "stm32l100c_discovery.h" #include "ssd1306.h" -#define LED_POWER GPIOB, GPIO_Pin_9 -#define LED_STAT GPIOA, GPIO_Pin_15 +#define LED_POWER GPIOB,GPIO_Pin_9 +#define LED_STAT GPIOA,GPIO_Pin_15 static __IO uint32_t TimingDelay; uint8_t BlinkSpeed = 0; @@ -23,40 +23,47 @@ int main(void) STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); - /* SysTick end of count event each 1ms */ + /* SysTick end of count event each 1ms */ RCC_GetClocksFreq(&RCC_Clocks); SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); /* Initiate Blink Speed variable */ BlinkSpeed = 1; + GPIO_ResetBits(LED_STAT); + Delay(100); + + init_gpio(); init_spi(); - //SPI_I2S_SendData(SPI1, 0x1); +// SPI_I2S_SendData(SPI1, 0x1); /* Init lcd driver */ -// SSD1303_Init(); +// SSD1303_Init(); // SSD1303_DrawPoint(3,3,1); // SSD1303_DrawPoint(5,5,0); //testme -// GPIO_SetBits(LED_PWR); - STM_EVAL_LEDOn(LED4); - Delay(1000); -// GPIO_ResetBits(LED_PWR); -STM_EVAL_LEDOff(LED4); - Delay(1000); + GPIO_SetBits(LED_POWER); +// GPIO_SetBits(LED_STAT); +// STM_EVAL_LEDOn(LED4); + Delay(500); + GPIO_ResetBits(LED_POWER); +// GPIO_ResetBits(LED_STAT); +// STM_EVAL_LEDOff(LED4); while(1) { /* Turn on LD4 Blue LED during 1s each time User button is pressed */ - STM_EVAL_LEDOn(LED4); + //STM_EVAL_LEDOn(LED4); + GPIO_SetBits(LED_POWER); //STM_EVAL_LEDOn(LED3); /* wait for 1s */ - Delay(300); + Delay(150); /* Turn off LD4 Blue LED after 1s each time User button is pressed */ - STM_EVAL_LEDOff(LED4); - Delay(300); + //STM_EVAL_LEDOff(LED4); + GPIO_ResetBits(LED_POWER); + Delay(150); } } @@ -129,8 +136,15 @@ void init_gpio(void) { * EXTI */ - /*Enable or disable the AHB peripheral clock */ - RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA|RCC_APB1Periph_SPI2|RCC_APB2Periph_SPI1, ENABLE); + /*Enable or disable the APB peripheral clock */ + + + // Enable SPI clocks + RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE); + RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); + + // Enable GPIO clocks + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOB|RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // EMZ TODO get the right ones