/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Interrupt not triggering!

Username:     
Password:     
             

Forum

# 1   2011-04-10 20:43:59 Interrupt not triggering!

nerf2901
New member
Registered: 2011-03-02
Posts: 9

Interrupt not triggering!

Hi Primer2 community,

We are currently developing a project on Primer2 which is using the USART port (USART2 to be more specific) to receive data from an Xbee module... We implemented a circular buffer to stock temporarily our received packet without losing any data.

We are using the interrupt feature of the USART2 by setting the NVIC.

void NVIC_config(void)
{
    NVIC_InitTypeDef NVIC_InitStructure;

    // Init NVIC
    /* Configure the NVIC Preemption Priority Bits */
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
 
    NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority  = 1;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);

    // Systick priority (not sure if we need that)
    NVIC_SystemHandlerPriorityConfig( SystemHandler_SysTick, 3, 3 );  //6,6
}

And then we call the handler for this type of interruption...

USART2_IRQHandler = 0xD8

   // Install new IRQ handler
   OldHandler = (tHandler)UTIL_GetIrqHandler( USART2_IRQHandler );
   UTIL_SetIrqHandler(USART2_IRQHandler, (tHandler)USART2_Handler);  //pointing out the handler

So, the handler/interrupt function is...

void USART2_Handler(void)
{
    FlagStatus rx_status = USART_GetITStatus(USART2, USART_IT_RXNE);
    FlagStatus tx_status = USART_GetITStatus(USART2, USART_IT_TXE);

    // interrupt was for receive (RXNE)
    if(rx_status != RESET)
    {
        unsigned char RxData;
        u8 tmphead;

        /* Read one byte from the receive data register */
        RxData = USART_ReceiveData(USART2);              //Read the received data   

        tmphead = (USART_RxHead + 1) & USART_RX_BUFFER_MASK; //Calculate buffer index
           
        if (tmphead == USART_RxTail)
        {
            /* ERROR! Receive buffer overflow */
            /* data will get lost !!! */
            USART_RxOverflow = TRUE;
        } else {
            USART_RxBuf[USART_RxHead] = RxData; // Store received data in buffer
            USART_RxOverflow = FALSE;
        }
   
        USART_RxHead = tmphead;    // Store new index
}

Now, our problem is that when we execute the program in step by step debug mode everything seems to work correctly, but when we run the entire application continuously, it never enters in our if condition:

if(rx_status != RESET)

We absolutely have no idea why?

And we have a function that returns the newest character received each time an interrupt occurs... But it seems that we are stuck in our while loop, because we never enter our if condition of our interrupt handler, which is kind of weird....

unsigned char USART_ReceiveChar( void )
{
    u8 tmptail;
    u8 buffer;

    //see if we have any data
    while ( USART_RxHead == USART_RxTail );
       
    tmptail = (USART_RxTail + 1) & USART_RX_BUFFER_MASK;

    buffer = USART_RxBuf[USART_RxTail];
   
    USART_RxTail = tmptail;               
     
   return buffer;
}

Thank you!

Offline

 

# 2   2011-04-10 21:20:23 Interrupt not triggering!

nerf2901
New member
Registered: 2011-03-02
Posts: 9

Re: Interrupt not triggering!

By the way, we already tried to get the current character received from the USART interruption and its working correctly (RxData)... But as soon as we try to put that value in the buffer and use that buffer in another function nothing works...

Offline

 

# 3   2011-04-11 06:51:39 Interrupt not triggering!

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Interrupt not triggering!

There is some other posts on this subject, like http://www.stm32circle.com/forum/viewtopic.php?id=1160, or http://www.stm32circle.com/forum/viewto … 6170#p6170, and examples in the project list.

Last edited by yrt (2011-04-11 06:54:42)

Offline

 

# 4   2011-04-11 17:57:05 Interrupt not triggering!

nerf2901
New member
Registered: 2011-03-02
Posts: 9

Re: Interrupt not triggering!

Could it be a problem with my current version of ride7 or my Circle OS?

I tried to understand and implement different code (from the forum). I'm really lost. Make two days, I am on this problem and I just can't figure it out.

But the way I coded my thing seems to be the same as everyone.

And like I said, I am able to receive bytes if I directly put my function (like a readPacket(build my frame, byte received) into the interrupt handler. But as soon as I implement my circular buffer my while loop seems to be more prioritary then the interrupt... And the interrupt can't be called since we are stuck...

I have looked over usart2 simple example and I have basically the same thing... The only thing different is that I have to comment those ligns of code

    // disable TIM2 functionality since it interferes with USART2
    //RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM2, DISABLE );
    //TIM_Cmd( TIM2, DISABLE );
    //TIM_ITConfig( TIM2, TIM_IT_Update, DISABLE );
    //TIM_DeInit(TIM2);

else I have a build failed (undefined symbol... !!!!! FLASH IS FULL!!!!!!)

Offline

 

# 5   2011-04-12 06:50:41 Interrupt not triggering!

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Interrupt not triggering!

As said in the posts I talked about before, it seems that the problem is the TIM2 interrupt with the highest priority. Anyone has found the real cause, but a workaround exists. I suggest you to add this function "TIM_Cmd( TIM2, DISABLE );" during the init of your application and "TIM_Cmd( TIM2, ENABLE );" when you leave the hand to the CircleOS.

For the build issue, what are the undefined symbols ?
For the "flash is full" message, verify that the project option "LD linker/General/Removed unused section" is ON.
Else, if your application is really too big, modify the length in the "Cicrle_app.ld" link script file :
  FLASH (rx) : ORIGIN = 0x8006000, $1
and
_eflash = 0x8006000 + $1 -1; .

Offline

 

# 6   2011-04-12 14:43:06 Interrupt not triggering!

nerf2901
New member
Registered: 2011-03-02
Posts: 9

Re: Interrupt not triggering!

I tried all that... except LD linker... changed that and it seems to compile... But I am still stuck in that while loop... And I made a error handling for my ITstatus and I receive some weird Hex (those are suppose only to be 1 or 0) and it seems I always get something new... hahaha

I have a second question... what do you mean by "leave the hand to the circleOS...?

I call it in my init obviously, but do I call in my api_handler too... or in the specific function?

Offline

 

# 7   2011-04-12 17:06:16 Interrupt not triggering!

nerf2901
New member
Registered: 2011-03-02
Posts: 9

Re: Interrupt not triggering!

This is insane! Now, I said **** that ****. I directly put my readPacket in my interruption function... seems to work so far....

BUT NOW, I have to do the same thing for the transmission...

This is getting FRUSTRATING as HELL!

Offline

 

# 8   2011-04-12 19:41:18 Interrupt not triggering!

ntrf.zns
Member
From: Belgorod, Russia
Registered: 2009-11-01
Posts: 134

Re: Interrupt not triggering!

to yrt: Why Timer 2 is used in circle os in the first place? As far as i can see it's just there to scan MEMS accelerometer. But MEMS data is not stable anyway so why bother?

Considering all the trouble Timer 2 is causing to many projects i have a question: Is there any other reason to keep Timer2 other than questionable gain of MEMS accuracy?

Offline

 

# 9   2011-04-13 09:22:32 Interrupt not triggering!

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: Interrupt not triggering!

At the origin, the TIM2 for the MEMS was been implemented for MEMS accuracy, and I agree is causing trouble !

But now, it is possible to call the MEMS handler by the scheduler, instead of the TIM2 IT.
For that, suppress the call to the  "TIM_Configuration();" in the main, and set the macro "MEMS_SPEC_MNGT" to 0  in "circle_platform.h"

Offline

 

Board footer