2010-12-29 02:52 AM
Timer in Slave Reset Mode: prescaler disabled?
2011-05-17 05:19 AM
Hi maverick,
Can you give me the timer config to check it. Hope that I can help you.MCU Lüfter2011-05-17 05:19 AM
Hello,
The initialization code is basically the same than AN: void TIMEOUT_Init(TIM_TypeDef *tim) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_ICInitTypeDef TIM_ICInitStructure; TIM_OCInitTypeDef TIM_OCInitStructure; if (tim == NULL) { return; } /* Stop timer */ TIM_Cmd(tim, DISABLE); /* UEV disabled */ TIM_UpdateDisableConfig(tim, ENABLE); /* Timer base configuration */ TIM_TimeBaseStructure.TIM_Prescaler = 0x1; /* Ignored in Slave Mode */ TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = 65535; /* Maximum period */ TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure); /* Enable One-Pulse mode, so counter stops at UEV */ TIM_SelectOnePulseMode(tim, TIM_OPMode_Single); /* Input Capture Configuration: Channel 1 */ TIM_ICStructInit(&TIM_ICInitStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_1; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0; TIM_ICInit(tim, &TIM_ICInitStructure); /* Output Compare Mode configuration: Channel2 */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable; TIM_OCInitStructure.TIM_Pulse = (uint16_t)0xFFFF; /* Timeout value */ TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC2Init(tim, &TIM_OCInitStructure); /* Timer Input trigger configuration: input connected to TI1 */ TIM_SelectInputTrigger(tim, TIM_TS_TI1FP1); /* Timer configuration in slave reset mode where the timer counter is re-initialized in response to rising edges on the input capture (TI1) */ TIM_SelectSlaveMode(tim, TIM_SlaveMode_Reset); /* Global Interrupt mode */ tim->CR1 &= (~TIM_CR1_URS); /* Update ARR, PSC and CCR shadow regs by setting UG bit in EGR reg */ TIM_GenerateEvent(tim, TIM_EventSource_Update); } Interrupt handler starts the counter when the first byte is received (first rising edge in Rx input) until the counter matchs OC value. The problem is that TIM_Prescaler is ignored in slave mode (as mentioned in the reference manual), so counter frequency is too fast for UART common baudrates. If you could find a workaround to fix this, it will be really appreciated. Thank you.2011-05-17 05:19 AM
Hi maverick,
Where did you fid this ''Reference Manual says that when using slave mode, CK_CNT = CK_PSC.'' ? What I know is that counter prescaler can be used in slave and the capture prescaler can not be used so /* counter prescaler */ TIM_TimeBaseStructure.TIM_Prescaler = the value of your choice but lower than 6535 ; /* Ignored in Slave Mode */ (I think that the comment is not correct) /* capture prescaler */ TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; // can not be TIM_ICPSC_DIV2, TIM_ICPSC_DIV4 ....... the prescaler is already set to 1 so if really the prescaler is ignored in slave mode, it should be 0 and not 1 . BTW, I can't find the software of the application note. Could you send it for me or tell me where I can find it (a link).MCU Lüfter2011-05-17 05:19 AM
Hello!
I'm really sorry for this very late answer, but I've been really busy with another proyect. The AN is here: http://www.st.com/internet/com/SOFTWARE_RESOURCES/SW_COMPONENT/SW_DRIVER/an3109.zip I will try your solution and let you know. Thank you!