cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F0308 Discovery Demo - extra LED to IO PC10

kalista
Associate
Posted on March 22, 2014 at 13:29

Hi,

I am pretty new in STM products and now I start playing with the evaluation Kit. I am trying to modify the STM32F0308 Discovery Demo which makes blinking the user Leds LED3 and LED4. The blinking speed can be changed by pressing the user button. It works fine however now I would like to extend this demo for another Led called LED5. I just followed the demo code and add new lines for input PC10. I copied some of the parts of modified code below. I would expected that the IO PC10 would have the same  value as the user LEDs LED3,4 which can be accesibla also via PC8,9. Nevertheless, the PC10 is still low and even LED4 does not blink.

Can anyone help me with this rather simple question ?

//-----------------------------------------STM32F0308_discovery.h------------------------

typedef enum 

/** @defgroup STM32F0308_DISCOVERY_LOW_LEVEL_Exported_Types

  * @{

  */

typedef enum 

{

  LED3 = 0,

  LED4 = 1,

  LED5 = 1 

} Led_TypeDef;

/** @addtogroup STM32F0308_DISCOVERY_LOW_LEVEL_LED

  * @{

  */

&sharpdefine LEDn                             3

// 2 before

  

&sharpdefine LED3_PIN                         GPIO_Pin_9

&sharpdefine LED3_GPIO_PORT                   GPIOC

&sharpdefine LED3_GPIO_CLK                    RCC_AHBPeriph_GPIOC

  

&sharpdefine LED4_PIN                         GPIO_Pin_8

&sharpdefine LED4_GPIO_PORT                   GPIOC

&sharpdefine LED4_GPIO_CLK                    RCC_AHBPeriph_GPIOC

// another LED pin

&sharpdefine LED5_PIN                         GPIO_Pin_10

&sharpdefine LED5_GPIO_PORT                   GPIOC

&sharpdefine LED5_GPIO_CLK                    RCC_AHBPeriph_GPIOC

//-----------------------------------------STM32F0308_discovery.c------------------------

/** @defgroup STM32F0308_DISCOVERY_LOW_LEVEL_Private_Variables

  * @{

  */ 

GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT, LED4_GPIO_PORT, LED5_GPIO_PORT};

const uint16_t GPIO_PIN[LEDn] = {LED3_PIN, LED4_PIN, LED5_PIN};

const uint32_t GPIO_CLK[LEDn] = {LED3_GPIO_CLK, LED4_GPIO_CLK, LED5_GPIO_CLK};

//-----------------------------------------main.c------------------------

int main(void)

{

  RCC_ClocksTypeDef RCC_Clocks;

  

  /* Configure LED3 and LED4 on STM32F0308-Discovery */

  STM_EVAL_LEDInit(LED3);

  STM_EVAL_LEDInit(LED4);

  STM_EVAL_LEDInit(LED5);

  

  /* Initialize User_Button on STM32F0308-Discovery */

  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);

  

  /* SysTick end of count event each 1ms */

  RCC_GetClocksFreq(&RCC_Clocks);

  SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);

   

  /* Initiate Blink Speed variable */ 

  BlinkSpeed = 1;

  

  while(1)

  {  

    /* Check if the user button is pressed */

    if(STM_EVAL_PBGetState(BUTTON_USER)== SET)

    {

      /* BlinkSpeed: 1 -> 2 -> 0, then re-cycle */

      /* Turn on LD4 Blue LED during 1s each time User button is pressed */

      STM_EVAL_LEDOn(LED3);

      STM_EVAL_LEDOn(LED4);

      STM_EVAL_LEDOn(LED5);

      

      /* wait for 1s */

      Delay(1000);

      

      /* Turn off LD4 Blue LED after 1s each time User button is pressed */

      STM_EVAL_LEDOff(LED3);

      STM_EVAL_LEDOff(LED4);

      STM_EVAL_LEDOff(LED5);

      

      /* Increment the blink speed counter */

      BlinkSpeed++;

      

      /* Default value for blink speed counter */

      if(BlinkSpeed == 3)

      {  

        BlinkSpeed = 0;

      }

    }

    

    /* Test on blink speed */

    if(BlinkSpeed == 2)

    {

      

      /* LED3 toggles each 100 ms */

      STM_EVAL_LEDToggle(LED3);

      STM_EVAL_LEDToggle(LED4);

      STM_EVAL_LEDToggle(LED5);

      

      /* maintain LED3 status for 100ms */

      Delay(100);

    }

    else if(BlinkSpeed == 1)

    {

      /* LED3 toggles each 200 ms */

      STM_EVAL_LEDToggle(LED3);

      STM_EVAL_LEDToggle(LED4);

      STM_EVAL_LEDToggle(LED5);

      

      /* maintain LED3 status for 200ms */

      Delay(200);

    }

    else

    {  

      /* LED3 Off */

      STM_EVAL_LEDOff(LED3);

      STM_EVAL_LEDOff(LED4);

      STM_EVAL_LEDOff(LED5);

    }

  }

}

#pc10
2 REPLIES 2
Posted on March 22, 2014 at 15:26

Something wrong right here:

typedef enum 

{

  LED3 = 0,

  LED4 = 1,

LED5 = 1 

} Led_TypeDef;

Posted on March 22, 2014 at 15:30

Also, rather than

typedef enum 

{

  LED3 = 0,

  LED4 = 1,

} Led_TypeDef;

#define LEDn                            

2

You might consider:

 typedef enum 

{

  LED3 = 0,

  LED4 = 1,

  LEDn

} Led_TypeDef;

Which would save you have to ensure that the enum and the #define keep in step...