2017-08-06 09:48 AM
STM32L476-Nucleo board, with jumper wire from PA7 to PA0. Attempting to learn PWM Input Capture.
GPIOA->AFR[0]: 0x20007701 00100000000000000111011100000001
PIN 0: TIM2_CH1 PIN 1: - PIN 2: USART2_TX PIN 3: USART2_RX PIN 4: - PIN 5: - PIN 6: - PIN 7: TIM3_CH2TIM3 free running, no prescaler, ARR 0x7FFF, pulse 0x15.
HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_1); HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_2);yields
TIM2->CCER: 0x00000020 00000000000000000000000000100000
CC1E : Capture disabled CC1P/NP: Non-inverted/rising edge CC2E : Capture disabled CC2P/NP: Non-inverted/both edges CC3E : OC1 is not active (OCx=0, OCx_EN=0) CC3P/NP: OC1 active high CC4E : OC1 is not active (OCx=0, OCx_EN=0) CC4P/NP: OC1 active highand
TIM2->CCR1: 0x00000000 00000000000000000000000000000000
TIM2->CCR2: 0x00000000 00000000000000000000000000000000but, after initialization, if I
*(uint32_t*)&TIM2->CCER |= (TIM_CCER_CC1E | TIM_CCER_CC2E);
I get
TIM2->CCER: 0x00000031 00000000000000000000000000110001
CC1E : Capture enabled CC1P/NP: Non-inverted/rising edge CC2E : Capture enabled CC2P/NP: Non-inverted/both edges CC3E : OC1 is not active (OCx=0, OCx_EN=0) CC3P/NP: OC1 active high CC4E : OC1 is not active (OCx=0, OCx_EN=0) CC4P/NP: OC1 active highand
TIM2->CCR1: 0x00007FFE 00000000000000000111111111111110
TIM2->CCR2: 0x00007FE9 00000000000000000111111111101001which, coincidentally, is the duty cycle of the pulse output on TIM3.
it would seem that either i am doing something wrong, or TIM_CCxChannelCmd(); is.
STM32CubeMX 4.22.0 and STM32Cube_FW_L4_V1.8.1
ARR of TIM2 may vary from .ioc file. otherwise, everything is as-generated.
Solved! Go to Solution.
2017-08-06 05:07 PM
Hello again.
this code must not be inside HAL_TIM_Base_MspInit(..)
//HAL_TIM_Base_Start_IT(tim_baseHandle);
HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_1); HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_2);HAL_TIM_Base_MspInit(..) , called by HAL_TIM_Base_Init() inside the MX_TIM2_Init(void)!!
So this code tries to start IC with interrupts before general timers initialization!!
Theese functions may called after initialisation of TIM2 (MX_TIM2_Init(void)).
2017-08-06 11:11 AM
Hello!!
you called this
HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_1);
HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_2);You use the pointer 'tim_baseHandle'.
Is this handle initialised and in global scope?
Is tim_baseHandle->Instance equal to TIM2?
2017-08-06 01:23 PM
2017-08-06 05:07 PM
Hello again.
this code must not be inside HAL_TIM_Base_MspInit(..)
//HAL_TIM_Base_Start_IT(tim_baseHandle);
HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_1); HAL_TIM_IC_Start_IT(tim_baseHandle, TIM_CHANNEL_2);HAL_TIM_Base_MspInit(..) , called by HAL_TIM_Base_Init() inside the MX_TIM2_Init(void)!!
So this code tries to start IC with interrupts before general timers initialization!!
Theese functions may called after initialisation of TIM2 (MX_TIM2_Init(void)).
2017-08-06 05:32 PM
starting the IC from main.c instead of tim.c made the difference. love your posts. you bring the tech hard!