cancel
Showing results for 
Search instead for 
Did you mean: 

external clock mode problem

mahmoud boroumand
Associate III
Posted on October 22, 2017 at 07:26

Hello.I use stm32f107vct6 and use this code for external mode for timer 3 

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3 ,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure);

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_TimeBaseStructure.TIM_Period = 1;

TIM_TimeBaseStructure.TIM_Prescaler = 25;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

TIM_SelectInputTrigger(TIM3, TIM_TS_TI1FP1);

TIM_TIxExternalClockConfig (TIM3, TIM_TS_TI1FP1, TIM_ICPolarity_Rising, 0) ;

TIM_SelectSlaveMode(TIM3, TIM_SlaveMode_External1);

TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

NVIC_InitTypeDef NVIC_InitStructure;

/* Enable the TIM1 global Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

TIM_Cmd(TIM3,ENABLE);

It work correctly but now i want use stm32f103c8 and i use exactly this code but it's not work(change internal pulse ) .whats different between them?

how  can i fix this problem?

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on October 22, 2017 at 15:44

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;

Consider using GPIO_Mode_IN_FLOATING for an INPUT

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

View solution in original post

5 REPLIES 5
Szymon PANECKI
Senior III
Posted on October 22, 2017 at 10:56

Hello Mahmoud Boroumand,

Looking at the part numbers, which you mentioned, it seems that you skipped one sign in their names:

  • Regarding stm32f07vct6, there is a missing sing between 7 and v, so it should be something like 

    stm32f07

    ?

    vct6
  • Regarding stm32f03c8, situation is similar, so there is a missing sing between 3 and c - stm32f03

    ?

    c8

Could you please double check the devices, which you use and provide here their full names? This can help to answer your question.

Regards

Szymon
Posted on October 22, 2017 at 11:07

Hello 

sorry

stm32f103c8

and 

stm32f107vct6

Posted on October 22, 2017 at 13:28

Period = 1 ?? Not going to count very much

Clocking code in system_stm32f1xx.c going to differ between 103 and 107 series parts, check input clock, PLL settings.

Consider using PA8 as MCO to probe internal clocks.

Double check pin utilization in data sheets for two parts.

Not Working? What type of input is being applied, and what happens in the work vs not-working case? What are the register settings in TIM3 when you dump out or view in debugger?

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on October 22, 2017 at 15:30

Hello I have to change  my timer to timer 1  and this is my code 

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 ,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO, ENABLE);

// GPIO_PinRemapConfig(GPIO_FullRemap_TIM3,ENABLE);

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure);

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_TimeBaseStructure.TIM_Period = 1;

TIM_TimeBaseStructure.TIM_Prescaler = 25;

TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseStructure.TIM_RepetitionCounter=0;

TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

TIM_ARRPreloadConfig(TIM1,ENABLE);

TIM_SelectInputTrigger(TIM1, TIM_TS_TI1FP1);

TIM_TIxExternalClockConfig (TIM1, TIM_TS_TI1FP1, TIM_ICPolarity_BothEdge, 0) ;

TIM_SelectSlaveMode(TIM1, TIM_SlaveMode_External1);

TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);

NVIC_InitTypeDef NVIC_InitStructure;

/* Enable the TIM1 global Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

TIM_Cmd(TIM1,ENABLE);

when i conncet pulse to pin a 8 the pulse change .  

please help me.how can i fix it?

0690X00000603yKQAQ.jpg0690X000006044vQAA.jpg

before connect to pin a 8

0690X000006044wQAA.jpg

after connect to pin a 8

0690X000006041iQAA.jpg
Posted on October 22, 2017 at 15:44

GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;

Consider using GPIO_Mode_IN_FLOATING for an INPUT

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..