Skip to main content
�?Ars
Associate
September 27, 2018
Question

STM32F722CV - USART1 RX Interrupt not working.

  • September 27, 2018
  • 8 replies
  • 1648 views

Hello, I am trying to communicate MCU with using USART1 but interrupt never triggered in MCU.

First I am using some definitions. Here is definitions for USART1.

#define USART1_PINS_PORT		GPIOA
#define USART1_RX_PIN			GPIO_PIN_10
#define USART1_TX_PIN			GPIO_PIN_9
#define USART1_ALTERNATE_FUNC		GPIO_AF7_USART1
#define USART1_GPIO_CLK_ENABLE()	__HAL_RCC_GPIOA_CLK_ENABLE()
#define USART1_CLK_ENABLE()			__HAL_RCC_USART1_CLK_ENABLE()
#define USART1_IRQ_NUM			USART1_IRQn
 
UART_HandleTypeDef USART1_Handle; /* Put USART to asynchronous mode */

My init function is :

void ml45_uart_init(void)
{
	USART1_Handle.Instance = USART1;
	USART1_Handle.Init.BaudRate = 115200;
	USART1_Handle.Init.Mode = USART_MODE_TX_RX;
	USART1_Handle.Init.WordLength = USART_WORDLENGTH_8B;
	USART1_Handle.Init.StopBits = USART_STOPBITS_1;
	USART1_Handle.Init.Parity = USART_PARITY_NONE;
	USART1_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
	USART1_Handle.Init.OverSampling = UART_OVERSAMPLING_16;
	USART1_Handle.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
	USART1_Handle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; 
	
	if ( HAL_UART_DeInit(&USART1_Handle) != HAL_OK )
	{
		while ( 1 )
		{
			/* UART INITIALIZATION FAILED */
		}
	}
	
	if ( HAL_UART_Init(&USART1_Handle) != HAL_OK )
	{
		while ( 1 )
		{
			/* UART INITIALIZATION FAILED */
		}
	}
}

And here is my msp init and msp deinit function :

void HAL_UART_MspInit(UART_HandleTypeDef *husart)
{
	/* Enable Peripherals */
	USART1_CLK_ENABLE();
	USART1_GPIO_CLK_ENABLE();
	
	GPIO_InitTypeDef GPIO_InitStructure;
	
	/* Init RX TX Pin */
	GPIO_InitStructure.Pin = USART1_TX_PIN | USART1_RX_PIN;
	GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
	GPIO_InitStructure.Pull = GPIO_NOPULL;
	GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
	GPIO_InitStructure.Alternate = USART1_ALTERNATE_FUNC;
	HAL_GPIO_Init(USART1_PINS_PORT, &GPIO_InitStructure);
 
	
	/* Arrange interrupt priority then enable it for USART1 */
	__HAL_USART_ENABLE_IT(husart, USART_IT_RXNE);
	__HAL_USART_CLEAR_IT(husart, USART_IT_TXE);
	HAL_NVIC_SetPriority(USART1_IRQ_NUM, 0, 1);
	HAL_NVIC_EnableIRQ(USART1_IRQ_NUM);
}
 
/**
 * @brief UART MSP De-Initialization
 * This function frees the hardware resources used in this example:
 * - Disable the Peripheral's clock
 * - Revert GPIO and NVIC configuration to their default state
 * @param huart: UART handle pointer
 * @retval None
 */
void HAL_UART_MspDeInit(UART_HandleTypeDef *husart)
{
	(void)husart;
	
	__HAL_RCC_USART1_FORCE_RESET();
	__HAL_RCC_USART1_RELEASE_RESET();
	
	HAL_GPIO_DeInit(USART1_PINS_PORT, USART1_RX_PIN);
	HAL_GPIO_DeInit(USART1_PINS_PORT, USART1_TX_PIN);
	
	HAL_NVIC_DisableIRQ(USART1_IRQ_NUM);
}

And lastly here is my interrupt routine :

void USART1_IRQHandler(void)
{
	volatile uint32_t ISR_shadow = USART1_Handle.Instance->ISR;
}

I put debug point in USART1_IRQHandler. Program can not reach at this point.

I am sure with the sending side of USART. This part is working.

So What is mcu's problem ? Is mine initialization code is wrong ?

Thanks for answers.

    This topic has been closed for replies.

    8 replies

    Tesla DeLorean
    Guru
    September 27, 2018

    Perhaps it doesn't actually receive anything? Does it work in polled mode? Can you see RXNE asserting, or does the USART indicate an error state, like parity, noise or framing that you need to clear?

    If you enable the TXE interrupt, does it enter then?

    Using C++ or a .cpp file name? could be a name mangling issue.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    �?Ars
    �?ArsAuthor
    Associate
    September 27, 2018

    Thanks for your response,

    When I call HAL_UART_Transmit_IT after initialize the uart, ISR is working.

    But when I track the TX signal from scope. There is not any TX signal.

    So What can be wrong in this situation ?

    Thanks again.

    Tesla DeLorean
    Guru
    September 27, 2018

    The IRQ handler would need to call the HAL routines to service the callbacks.

    Sorry not familiar with your board/design

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    �?Ars
    �?ArsAuthor
    Associate
    September 27, 2018

    Okay, lastly,

    I change all settings for using USART6.

    When I do this, everything is okay. So Is there any difference between USART6 and USART1 ?

    Tesla DeLorean
    Guru
    September 27, 2018

    >>So Is there any difference between USART6 and USART1 ?

    How it is wired on the board, and aspects of the design you haven't shared?

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    �?Ars
    �?ArsAuthor
    Associate
    September 27, 2018

    PA9 is used for TX pin and PA10 is used for RX pin. Then these pins is connected to connector.

    Tesla DeLorean
    Guru
    September 27, 2018

    Ok, I can see USART1 PA9/PA10 from your code example, what about the USART6 you're asking for a comparison against?

    Is this an ST board, or one designed/built by yourself?

    Can you provide a schematic?

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    �?Ars
    �?ArsAuthor
    Associate
    September 28, 2018

    I am using STM32F746 Discovery kit for test. For USART1, I removed R64 and R133 for using USART1 pins. Then I connect Usb to serial chip to this pins with GND.

    Here is its schematics :

    https://www.st.com/content/ccc/resource/technical/document/user_manual/f0/14/c1/b9/95/6d/40/4d/DM00190424.pdf/files/DM00190424.pdf/jcr:content/translations/en.DM00190424.pdf