cancel
Showing results for 
Search instead for 
Did you mean: 

UART4 Interrupt

taha_najmee
Associate II
Posted on October 22, 2012 at 03:45

Hello,

I am working on STM32F4Discovery Board. I am trying to make the UART4 connection with interrupt. I have declared all the needed settings but not able to find the problem.

The problem is that it doesn't go to UART4 interrupt routine. I have also changed the HSE_Value to 8MHz. Also I have changed the XTAL value to 8MHz on Keil device configuration.

I have shorted the RX and TX pin of UART4 so whatever is sent can be received.

I would really appreciate if somebody can help me with this. Thanks
5 REPLIES 5
crt2
Associate II
Posted on October 22, 2012 at 11:20

I think you're missing NVIC and USART_TXE enable.

I'm not f4 expert but something like:

NVIC_InitTypeDef nvic;

nvic.NVIC_IRQChannel = USART4_IRQChannel;

nvic.NVIC_IRQChannelPreemptionPriority = 2;

    nvic.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&nvic);

and

USART_ITConfig(USART4, USART_IT_TXE, ENABLE);
taha_najmee
Associate II
Posted on October 22, 2012 at 15:14

Thanks ... I will look into it. Will give you the update soon.

Posted on October 22, 2012 at 15:41

NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the UART4 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
void UART4_IRQHandler(void)
{
if (USART_GetITStatus(UART4, USART_IT_RXNE) == SET)
{
unsigned short received = USART_ReceiveData(UART4);
// ...
}
// Consider also framing/overrun errors
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
taha_najmee
Associate II
Posted on October 22, 2012 at 20:16

Thanks clive1. My interrupt is working now. Although I don't completely understand what is the difference between the pre-emption priority and sub-priority of the IRQ channel.

According to what I read in the misc.h file, does the pre-emption priority mean the priority among the different device interrupts while the sub-priority means the priorities among the particular device interrupt. Like interrupts for RX and TX for UART.

Posted on October 22, 2012 at 21:08

You'll have to weight the interrupts in your own system.

Preemption is about interrupting the interrupts with a higher level. The subpriority is about which gets serviced first when the processor chooses which one to do next.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..