cancel
Showing results for 
Search instead for 
Did you mean: 

Output Capture not working to blink LED on NUCLEO-C031C6

HPate.12
Associate II

I am trying to implement output capture using the LL APIs but cannot get it to blink the LED every one second on the NUCLEO board, however, I cannot get it to blink at all. Is there a register I missed?

Here is my code:

#include "stm32c0xx_ll_bus.h"

#include "stm32c0xx_ll_gpio.h"

#include "stm32c0xx_ll_tim.h"

/*---------------------------------------------------------------------------------------------------------------------------------------------------*/

void LED_PA5_init(void)

{

   LL_IOP_GRP1_EnableClock (LL_IOP_GRP1_PERIPH_GPIOA); //for LED PA5

   LL_GPIO_SetPinMode (GPIOA, LL_GPIO_PIN_5, LL_GPIO_MODE_ALTERNATE);

   LL_GPIO_SetAFPin_0_7 (GPIOA, LL_GPIO_PIN_5, LL_GPIO_AF_5); //AF5 is TIM1_CH1 for PA5

}

void Timer1_1Hz_OC_init(void) //1 Hz = 1 cycle/s = 1 s delay

{

   LL_APB2_GRP1_EnableClock (LL_APB2_GRP1_PERIPH_TIM1);

   LL_TIM_SetPrescaler (TIM1, 1200-1); //12000000/1200 = 10000 Hz

   LL_TIM_OC_SetMode (TIM1, LL_TIM_CHANNEL_CH1, LL_TIM_OCMODE_TOGGLE);

   LL_TIM_CC_EnableChannel (TIM1, LL_TIM_CHANNEL_CH1);

   LL_TIM_SetAutoReload (TIM1, 10000-1); //10000/10000 = 1 Hz

   LL_TIM_SetCounter (TIM1, 0);

   LL_TIM_EnableCounter (TIM1);

}

/*---------------------------------------------------------------------------------------------------------------------------------------------------*/

int main(void)

{

   LED_PA5_init();

   Timer1_1Hz_OC_init();

   while (1){ }

}

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

add a

LL_TIM_EnableAllOutputs(TIM1);

?

hth

KnarfB

View solution in original post

7 REPLIES 7
S.Ma
Principal

Here is in LED.C the STM32C0316-DK user LED blinking AND dimming.

Dimming is using the Timer Compare in PWM mode with Percent to Log transfer function, the blinking is based on Systick 1 msec interrupt with RAM counter to have blinking on/off/repeat time implemented.

Is this using the Low Layer library?

TIM1 is Advanced Timer, it needs to have TIMx_BDTR.MOE set.

JW

KnarfB
Principal III

add a

LL_TIM_EnableAllOutputs(TIM1);

?

hth

KnarfB

For GPIO it uses mostly LL. The code is mostly using HAL for timer related functions.

The GPIO Driver is based on my itterative experience to balance performance, memory footprint and intuitive code. Grab just what you need, concept, ideas, clues....

Thank you, this was it!

Thank you, this worked!