/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / Usart2 interrupt

Username:     
Password:     
             

Forum

# 1   2009-04-11 04:06:36 Usart2 interrupt

FR4
Member
Registered: 2008-11-09
Posts: 26

Usart2 interrupt

i want to make use of usart2. After struggling some issues concerning baudrate settings i´m now facing the fact that i can´t get usart2 interrupt to work.

I followed several examples regarding interrupt setup with UTIL_SetIrqHandler

Here´s my code:

Code:

    tHandler OldHandler;

    OldHandler = (tHandler)UTIL_GetIrqHandler( USART2_IRQHandler );
    UTIL_SetIrqHandler(USART2_IRQChannel, (u32)USART2_IRQHandler);

In my understanding UTIL_SetIrqHandler points the interruptvector for usart2 to the desired function. But UTIL_SetIrqHandler doesn´t change the vectortable in ram. I can´t even debug UTIL_SetIrqHandler.

Although OldHandler is declared,  stepping through the code
gives me "not available" message if i want to have a look to the content of OldHandler

If i step through

Code:

void UTIL_SetIrqHandler( int Offs, tHandler pHDL )
    {
#ifdef PRIMER1
    if ( (Offs >= 8) && (Offs<0x100) )
#else
    if ( (Offs >= 8) && (Offs<0x140) ) // KJ20090320 - Changed from 120
#endif
        *(tHandler *)( CIRCLEOS_RAM_BASE + Offs ) = pHDL;
    }

looking at pHDL is not possible. If i add pHDL to the watch window i get "error(3): undefined symbol" ???

Does anybody know what´s going wrong?

The code for setting up usart2:

Code:

void Usart2Init(u16 baudrate)
{
      USART_InitTypeDef USART_InitStructure;
      GPIO_InitTypeDef GPIO_InitStructure;
      NVIC_InitTypeDef NVIC_InitStructure;

      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, DISABLE); 
      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
      /* Enable USART2 clocks */
      RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);

        NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
      /* Enable the USART2 Interrupt */
      NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQChannel;
      NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
      NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
      NVIC_Init(&NVIC_InitStructure);

        /* Configure USART2 Tx (PA.2) as alternate function push-pull */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
      GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* Configure USART2 Rx (PA.3) as input floating */
      GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
      GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
      GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
      GPIO_Init(GPIOA, &GPIO_InitStructure);
     
      /* USART2 configuration ------------------------------------------------------*/
      /* USART2 configured as follow:
            - BaudRate = 9600 baud 
            - Word Length = 8 Bits
            - One Stop Bit
            - No parity
            - Hardware flow control disabled (RTS and CTS signals)
            - Receive and transmit enabled
            - USART Clock disabled
            - USART CPOL: Clock is active low
            - USART CPHA: Data is captured on the second edge
            - USART LastBit: The clock pulse of the last data bit is not output to
                             the SCLK pin
      */
      USART_InitStructure.USART_BaudRate = 9600;
      USART_InitStructure.USART_WordLength = USART_WordLength_8b;
      USART_InitStructure.USART_StopBits = USART_StopBits_1;
      USART_InitStructure.USART_Parity = USART_Parity_No ;
      USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
      USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
      USART_Init(USART2, &USART_InitStructure);

      /* Write to USART BRR */
      USART2->BRR = 0x782;
      
     
      /* Enable USART2 Receive interrupt */
      USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);

     
      /* Enable the USART2 */
      USART_Cmd(USART2, ENABLE);
 
}

Offline

 

# 2   2009-04-12 20:06:36 Usart2 interrupt

sjoerd
Member
From: Stad aan het Haringvliet
Registered: 2008-09-04
Posts: 65

Re: Usart2 interrupt

As far as I can see you should use address 0xD8 for the USART2 interrupts (see page 96, STM32F10x ref manual).



Code:

tHandler OldHandler;

void MyUsart2Handler(void)
{
  // do something
}

void InitIrq
{
   OldHandler = (tHandler)UTIL_GetIrqHandler( 0xD8 );
    UTIL_SetIrqHandler(0xD8, MyUsart2Handler);
}

Offline

 

Board footer