2012-10-21 06:45 PM
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. Thanks2012-10-22 02:20 AM
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);2012-10-22 06:14 AM
Thanks ... I will look into it. Will give you the update soon.
2012-10-22 06:41 AM
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
}
2012-10-22 11:16 AM
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.2012-10-22 12:08 PM
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.