2023-02-28 03:28 PM
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){ }
}
Solved! Go to Solution.
2023-03-01 07:09 AM
2023-02-28 08:37 PM
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.
2023-03-01 06:56 AM
Is this using the Low Layer library?
2023-03-01 07:00 AM
TIM1 is Advanced Timer, it needs to have TIMx_BDTR.MOE set.
JW
2023-03-01 07:09 AM
add a
LL_TIM_EnableAllOutputs(TIM1);
?
hth
KnarfB
2023-03-01 08:32 AM
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....
2023-03-02 10:47 AM
Thank you, this was it!
2023-03-02 10:47 AM
Thank you, this worked!