cancel
Showing results for 
Search instead for 
Did you mean: 

Shouldn't HAL_TIM_IC_Start_IT() set TIMx->CCER?

john doe
Lead
Posted on August 06, 2017 at 18:48

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_CH2

TIM3 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 high

and

TIM2->CCR1:     0x00000000    00000000000000000000000000000000

TIM2->CCR2:     0x00000000    00000000000000000000000000000000

but, 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 high

and

TIM2->CCR1:     0x00007FFE    00000000000000000111111111111110

TIM2->CCR2:     0x00007FE9    00000000000000000111111111101001

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

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on August 07, 2017 at 00:07

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

View solution in original post

4 REPLIES 4
Posted on August 06, 2017 at 20:11

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?

Posted on August 06, 2017 at 20:23

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6fR&d=%2Fa%2F0X0000000bsm%2F7zwSnJbP7.AXzinYFbuBM_blkSRas3n5zRbpwQVM2Jk&asPdf=false
Posted on August 07, 2017 at 00:07

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

Posted on August 07, 2017 at 00:32

starting the IC from main.c instead of tim.c made the difference. love your posts. you bring the tech hard!