cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 Discovery Timer Reset problem

chaitanya
Associate II
Posted on February 08, 2015 at 17:25

Hi,

I'm STM32F4-Discovery board and am trying to log GPS data into uSD card. I've configured the DMA and am able to view the data in the card. But, the data has gaps which was expected as the DMA interrupt is count based.

To avoid this I'm using Timer 2 to detect any transitions on the Rx line and configured the timer to reset mode. I want the transition on the line to reset the timer and start the count. Only on no activity, the timer would overflow and generate an interrupt.  Basically, some kind of time out interrupt.

However, the timer overflows and continuously generates the Update interrupt even when there is not activity on the line.

Here is the code I've used... Can you help where I went wrong.. Thanx in advance

void GPS_Gap_Timer_Config(void)

{

        

        GPIO_InitTypeDef                GPIO_InitStructure;

        TIM_TimeBaseInitTypeDef         TIMER_InitStructure;

        TIM_ICInitTypeDef               TIM_ICInitStruct;

        NVIC_InitTypeDef                NVIC_InitStructure;

        

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

 

        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA , ENABLE);

        // PA8 = TIMER2_CHANNEL-1

        GPIO_PinAFConfig(GPIOA, GPIO_PinSource15,  GPIO_AF_TIM2);

 

        // Configure Port-A

        GPIO_InitStructure.GPIO_Pin     = GPIO_Pin_15;

        GPIO_InitStructure.GPIO_Mode    = GPIO_Mode_AF;

        GPIO_InitStructure.GPIO_Speed   = GPIO_Speed_100MHz;

        GPIO_InitStructure.GPIO_OType   = GPIO_OType_PP;

        GPIO_InitStructure.GPIO_PuPd    = GPIO_PuPd_NOPULL;

        GPIO_Init(GPIOA, &GPIO_InitStructure);

        

        TIM_InternalClockConfig(TIM2);                                  //      Choose Internal Clock for Timer2

        

        TIMER_InitStructure.TIM_CounterMode     = TIM_CounterMode_Up;   //      Choose Up Mode Count

        TIMER_InitStructure.TIM_ClockDivision   = TIM_CKD_DIV4 ;        //      36MHz / 4 = 9MHz

        TIMER_InitStructure.TIM_Period          = 55000;

        TIMER_InitStructure.TIM_Prescaler       = 0;                    //      36MHz

        TIM_TimeBaseInit(TIM2, &TIMER_InitStructure);

                

        TIM_ICInitStruct.TIM_Channel            = TIM_Channel_1;

        TIM_ICInitStruct.TIM_ICPolarity         = TIM_ICPolarity_Rising;  

        TIM_ICInitStruct.TIM_ICSelection        = TIM_ICSelection_DirectTI;  

        TIM_ICInitStruct.TIM_ICPrescaler        = TIM_ICPSC_DIV1;  

        TIM_ICInitStruct.TIM_ICFilter           = 0;  

                

        TIM_ICInit(TIM2, &TIM_ICInitStruct);

        TIM_UpdateRequestConfig(TIM2, TIM_UpdateSource_Regular);

        

        TIM_SelectInputTrigger(TIM2, TIM_TS_TI1F_ED);

        TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Reset);

        TIM_ClearITPendingBit(TIM2,TIM_IT_Update);

                

        TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

        TIM_ITConfig(TIM2, TIM_IT_Trigger, DISABLE);

                

        NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;

        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

        NVIC_Init(&NVIC_InitStructure);

           

        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

        

    

        TIM_Cmd(TIM2, ENABLE);

}

3 REPLIES 3
Posted on February 08, 2015 at 17:43

So what speed is the bus clock, and what speed is the time base? What is the time out?

This does sets a filter speed, it's not a prescaler for the timer

TIMER_InitStructure.TIM_ClockDivision   = TIM_CKD_DIV4 ;

Wouldn't the reset perhaps cause an update interrupt?

You could use the CCx instead of the Update, still it's likely to hit if you have a short period and the counter wraps. Could you not use the 32-bit range of the counter?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
chaitanya
Associate II
Posted on February 09, 2015 at 05:38

Thanks a lot for the reply...

True... I realised later that it is supposed to generate the update interrupt because the timer is configured in reset mode... So it'll reset on trigger.. otherwise its running and would generate an update on overflow...

The time is suffecient because data is 115200bps and I've given about 10 bytes gap... I think I'll have to enable update interrupt only after triggering once...

I'll try with 32-bit and revert back on the status...

Posted on February 09, 2015 at 07:42

I'm not sure what you mean by gaps. Missing data?

GPS devices tend to output data in bursts at the top-of-second, this might be half a dozen NMEA sentences, but likely less than 11520 characters which a full second of solid data might provide.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..