cancel
Showing results for 
Search instead for 
Did you mean: 

USART doesnot go into interrupt service routine

mehmet.karakaya
Associate III
Posted on September 04, 2010 at 19:36

USART doesnot go into interrupt service routine

12 REPLIES 12
mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:05

this is init for the LED

  /* Configure the GPIO_LED pin */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

----------------------------

I set up the clocks for USART and GPIO befor init.ing them  

I didnot see any code in the example

for setting the NVIC Vector Table Address ?

I simply run below code

----------------------------------------

void NVIC_Configuration(void)

{

  NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

  /* Enable the USARTx Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

}  what I found strange is

how I ''getintvector '' and setintvector'' in STM32 ?

just writing this below code is enough ?

--------------------------------

void USART1_IRQHandler(void)

{

  if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

  {

    /* Read one byte from the receive data register */

    TxBuffer = (USART_ReceiveData(USART1));

    GPIOA->ODR ^= GPIO_Pin_1;

  }

  if(USART_GetITStatus(USART1, USART_IT_TXE) != RESET)

  {  

    /* Write one byte to the transmit data register */

    USART_SendData(USART1, TxBuffer);

  }

}

---------------------

this ISR must echo back the received character

but it doesnot

this is another clue that it doesnt enter ISR

Posted on May 17, 2011 at 14:05

>> where might I be wrong ?

We'll it's not clear from your cut-n-paste job,  but you certainly need to set up the clocks to USART1 and GPIOA *BEFORE* you program the  peripherals.

Presumably you're also setting the NVIC Vector Table Address? or perhaps not,. Try looking at the example code ST supplies for exactly this task, ''USART\HyperTerminal_Interrupt'', as least in V2

You're initializing the GPIO pin for the LED somewhere else?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lipin
Associate II
Posted on May 17, 2011 at 14:05

Hi,

Your code looks more or less ok. Few things I have noticed. I see thatyou have habit of not filling all structure fields I would advise you to do so.

There is no USART enable command (USART_Cmd(USART1,ENABLE)).

Interrupt definitions/names are in startup files (.s). Writing properfunction name is enough. Use debugger to check if uC is entering interrupts donot relay on assumptions.

Greetings

Thomas

mehmet.karakaya
Associate III
Posted on May 17, 2011 at 14:05

'' There is no USART enable command (USART_Cmd(USART1,ENABLE)). ''

 

I added this line and it worked

thank you very much 
nanayakkaraan
Associate II
Posted on May 17, 2011 at 14:05

Hello,

I am struggling to make interrpts work on a STM32L152 on IAr environment.

Can karakaya please explain me what are the interrupt files you included in your project?

Thank you.

Posted on May 17, 2011 at 14:05

I am struggling to make interrupts work on a STM32L152 on IAR environment.

ST nominally parks the interrupt handlers in stm32f10x_it.c file in their projects.

If the handler you want does not exist (ie not instantiated) in the C file, it is weakly defined in the library source, the assembler file is startup\iar\startup_stm32f10x_??.s based on the part family you are using.

To make it work you need to put a wrapper/handler in the C file (stm32f10x_it.c, or main.c), and implement to body of the handler.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
nanayakkaraan
Associate II
Posted on May 17, 2011 at 14:05

Hello,

Thanks for replying. But it will be helpful to me if you can be further elaborative.

Since I am using STM32L152 I can i still use stm32f10x_it.c?

Instead i used stm32l1xx_it.h, stm32l1xx_it.c and startup_stm32l1xx_md.s found from examples provided by ST.

Since i need TIM4 interrupts relevant changes were done in stm32l1xx_it.h and stm32l1xx_it.c.

TIM4 is already defined in .s file.

I have copied all three files into working directory and included stm32l1xx_it.h in main file.

but interrupt still does not work.

Any suggestions or instructions on this matter is highly appreciated.

Thank you.

lowpowermcu
Associate II
Posted on May 17, 2011 at 14:05

Hi ANN,

To use interrupts, check the following points:

- enable interrupt source in the peripheral

- configure the interrupt handler for the peripheral

For TIM4, you should have something like this

  NVIC_InitTypeDef NVIC_InitStructure;

  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);

  /* Enable the USARTx Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

MCU Lüfter,

 
Posted on May 17, 2011 at 14:05

Can you provide a download link, or zip up, the firmware library and example files for the STM32L1xx. Poking around with Google and ST's site haven't yielded what I'm looking for.

Yes, you will have to tailor code to the specific family you are using, most everyone is using the STM32F series, hence the most code/projects are tailored that way.

It would probably be easier to use the library than trying to manually program the registers at the bit level.

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