Skip to main content
HPate.12
Associate II
February 28, 2023
Solved

Output Capture not working to blink LED on NUCLEO-C031C6

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){ }

}

This topic has been closed for replies.
KnarfB
KnarfBBest answer
Super User
March 1, 2023

add a

LL_TIM_EnableAllOutputs(TIM1);

?

hth

KnarfB

7 replies

S.Ma
Principal
March 1, 2023

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.

HPate.12
HPate.12Author
Associate II
March 1, 2023

Is this using the Low Layer library?

S.Ma
Principal
March 1, 2023

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....

waclawek.jan
Super User
March 1, 2023

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

JW

HPate.12
HPate.12Author
Associate II
March 2, 2023

Thank you, this was it!

KnarfB
KnarfBBest answer
Super User
March 1, 2023

add a

LL_TIM_EnableAllOutputs(TIM1);

?

hth

KnarfB

HPate.12
HPate.12Author
Associate II
March 2, 2023

Thank you, this worked!