Skip to main content
Visitor II
January 31, 2020
Question

UART0 Interrupt Handler not working properly on STR912FAW44

  • January 31, 2020
  • 1 reply
  • 962 views

Hello,

I am trying to use receive interrupts for UART0 on STR912FAW44 (STR9-Dongle STEVAL-IFD001V2)

The problem is that first few characters trasmitted to MCU don't raise receive interrupt. Then a fifth or sixth character throws receive interrupt and UART0_IRQHandler is executed (first of all trasmitted characters is echoed back to terminal). But then the MCU freezes after executing the handler. What am I doing wrong?

The code:

#include <91x_lib.h>
 
void SCU_init(void)
{	
 // Enable the UART0 Clock
 SCU_APBPeriphClockConfig(__UART0, ENABLE);
 
 // Enable the GPIO3 Clock
 SCU_APBPeriphClockConfig(__GPIO3, ENABLE);
	
 // Enable the VIC clock
 SCU_AHBPeriphClockConfig(__VIC, ENABLE);
}
 
void uart_init(void)
{
	GPIO_InitTypeDef rx_pin = (GPIO_InitTypeDef) {
		.GPIO_Pin = GPIO_Pin_0,
		.GPIO_Direction = GPIO_PinInput,
		.GPIO_Type = GPIO_Type_PushPull,
		.GPIO_IPInputConnected = GPIO_IPInputConnected_Enable,
	 .GPIO_Alternate = GPIO_InputAlt1
	};
	
	GPIO_InitTypeDef tx_pin = (GPIO_InitTypeDef) {
		.GPIO_Pin = GPIO_Pin_4,
		.GPIO_Direction = GPIO_PinOutput,
		.GPIO_Type = GPIO_Type_PushPull,
	 .GPIO_Alternate = GPIO_OutputAlt3
	};
	
	GPIO_Init(GPIO3, &rx_pin);
	GPIO_Init(GPIO3, &tx_pin);
	
	UART_InitTypeDef init_struct = (UART_InitTypeDef) {
		.UART_WordLength = UART_WordLength_8D,
		.UART_StopBits = UART_StopBits_1,
		.UART_Parity = UART_Parity_No,
		.UART_BaudRate = 57600,
		.UART_HardwareFlowControl = UART_HardwareFlowControl_None,
		.UART_Mode = UART_Mode_Tx_Rx,
		.UART_FIFO = UART_FIFO_Enable,
		.UART_TxFIFOLevel = UART_FIFOLevel_1_2,
		.UART_RxFIFOLevel = UART_FIFOLevel_1_2
	};
	
	UART_DeInit(UART0);
	UART_Init(UART0, &init_struct);
	
	VIC_DeInit();
 VIC_Config(UART0_ITLine, VIC_IRQ, 0);
 VIC_ITCmd(UART0_ITLine, ENABLE);
	
	UART_ITConfig(UART0, UART_IT_Receive, ENABLE);
	
 UART_Cmd(UART0, ENABLE);
}
 
void UART0_IRQHandler(void)
{
	UART_SendData(UART0, UART_ReceiveData(UART0)); // ECHO
	UART_ClearITPendingBit(UART0, UART_IT_Receive);
}
 
int main(void)
{
	SCU_init();
	uart_init();
	
	while (1) {
		// Do nothing
	}
}

Thank you very much.

    This topic has been closed for replies.

    1 reply

    Graduate II
    January 31, 2020

    >>The problem is that first few characters transmitted to MCU don't raise receive interrupt.

    Perhaps don't use the FIFO then? Or change the thresholds to meet your expectations.

    Visitor II
    January 31, 2020

    Thanks for advice. When I use UART_FIFO_Disable, it raises the receive interrupt immediately after fist character sent (I propably misunderstood the FIFO concept).

    But, after echoing the received character back to terminal, the MCU still keeps freezing. It just executes UART0_IRQHandler and then everything gets stuck... What can I do about that?