# HG changeset patch # User Ethan Zonca # Date 2014-07-10 22:32:10 # Node ID 299800126735e764732fa4679c5e4695c6e7c167 # Parent 4e72955028d82132392b849d5b6f08945e538153 Now using GPIO library and generated gpio config, fixes for SPI, etc diff --git a/libraries/oleddrv/bsp.h b/libraries/oleddrv/bsp.h --- a/libraries/oleddrv/bsp.h +++ b/libraries/oleddrv/bsp.h @@ -25,26 +25,27 @@ D1/Data 3 4 D0/Clk RD (Float) */ -#define SSD_Clk GPIOA,GPIO_Pin_5 -#define SSD_Data GPIOA,GPIO_Pin_7 +//#define SSD_Clk GPIOA,GPIO_Pin_5 +//#define SSD_Data GPIOA,GPIO_Pin_7 #define SSD_Reset GPIOB,GPIO_Pin_2 #define SSD_A0 GPIOB,GPIO_Pin_10 #define SSD_CS GPIOB,GPIO_Pin_1 -#define SSD_Clk_Low() GPIOA->BRR = GPIO_Pin_5 -#define SSD_Clk_High() GPIOA->ODR |= GPIO_Pin_5 -#define SSD_Data_Low() GPIOA->BRR = GPIO_Pin_7 -#define SSD_Data_High() GPIOA->ODR |= GPIO_Pin_7 -#define SSD_Reset_Low() GPIOB->BRR = GPIO_Pin_2 -#define SSD_Reset_High() GPIOB->ODR |= GPIO_Pin_2 -#define SSD_A0_Low() GPIOB->BRR = GPIO_Pin_10 -#define SSD_A0_High() GPIOB->ODR |= GPIO_Pin_10 -#define SSD_CS_Low() GPIOB->BRR = GPIO_Pin_1 -#define SSD_CS_High() GPIOB->ODR |= GPIO_Pin_1 +//#define SSD_Clk_Low() GPIO_ResetBits(GPIOA, GPIO_Pin_3) +//#define SSD_Clk_High() GPIO_SetBits(GPIOA, GPIO_Pin_5) +//#define SSD_Data_Low() GPIO_ResetBits(GPIOA, GPIO_Pin_7) +//#define SSD_Data_High() GPIO_SetBits(GPIOA, GPIO_Pin_7) +#define SSD_Reset_Low() GPIO_ResetBits(GPIOB, GPIO_Pin_2) +#define SSD_Reset_High() GPIO_SetBits(GPIOB, GPIO_Pin_2) +#define SSD_A0_Low() GPIO_ResetBits(GPIOB, GPIO_Pin_10) +#define SSD_A0_High() GPIO_SetBits(GPIOB, GPIO_Pin_10) +#define SSD_CS_Low() GPIO_ResetBits(GPIOB, GPIO_Pin_1) +#define SSD_CS_High() GPIO_SetBits(GPIOB, GPIO_Pin_1) // Use stdperiph -#define SPI_SendByte(data) SPI_I2S_SendData(SPI1, data); //SPI1->DR = (data) -#define SPI_Wait() while(!(SPI1->SR&SPI_I2S_FLAG_TXE));while(SPI1->SR&SPI_I2S_FLAG_BSY); #define SSD1303_FPS 50 +#define SPI_SendByte(data) SPI_I2S_SendData(SPI1,data) +#define SPI_Wait() while(!(SPI1->SR&SPI_I2S_FLAG_TXE));while(SPI1->SR&SPI_I2S_FLAG_BSY); +#define SSD1303_FPS 50 #define IsLedOn() (!(GPIOA->ODR & GPIO_Pin_8)) #define LED_ON() GPIOA->BRR = GPIO_Pin_8 #define LED_OFF() GPIOA->BSRR = GPIO_Pin_8 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 diff --git a/ssd1306.c b/ssd1306.c --- a/ssd1306.c +++ b/ssd1306.c @@ -81,13 +81,10 @@ void WriteData(unsigned char data) void SSD1303_Init(void) { - /* Initialize SPI2 */ - // TODO - /* Generate a reset */ SSD_Reset_Low(); - uint32_t i ; - for(i=5000;--i;); + uint32_t i; + for(i=5000; i>1; i--) SSD_Reset_High(); /************************************************* @@ -95,6 +92,7 @@ void SSD1303_Init(void) *************************************************/ // Lower Column Address WriteCommand(0x00); /* Set Lower Column Address */ + GPIO_SetBits(GPIOA,GPIO_Pin_15); // High Column Address WriteCommand(0x10); /* Set Higher Column Address*/ // Display Start Line @@ -121,7 +119,8 @@ void SSD1303_Init(void) // Set DC-DC WriteCommand(0xAD); /* Set DC-DC */ WriteCommand(0x8B); /* 8B=ON, 8A=Off */ - + + // Display ON/OFF WriteCommand(0xAE); /* AF=ON , AE=OFF*/ // Display Offset