cancel
Showing results for 
Search instead for 
Did you mean: 

Why is UART5 Receive Interrupt in ST32F405 UART5 not working after I send data from UART5 TX

FLast.5
Associate II

I am using STM32F405 UART5 to receive data using interrupt.I generated base code using STM CubeMX.

The problem is when I don't transmit data from UART5 TX, the UART5 receiver works fine. But if I send data from UART5 TX, the first 2-3 bytes voltage drops to ~1V so the microcontroller does not recognize it and I am unable to receive the first 3 bytes.

When I do not use interrupt and use polling method, there is no problem.

I am sending and receiving data from PC through FTDI4232 USB-TTL converter to STM32F405 board.

The code is shown below. This is a Main Application part whose address starts from 0x8008000.

I have a separate bootloader program from which the program jumps to Main Application program. Does the jumping from Bootloader part to Application part impact the UART5 receiver.

Here are my setting for the Main Application program:

static void MX_UART5_Init(void)
{ 
    huart5.Instance = UART5;
    huart5.Init.BaudRate = 115200;
    huart5.Init.WordLength = UART_WORDLENGTH_8B;
    huart5.Init.StopBits = UART_STOPBITS_1;
    huart5.Init.Parity = UART_PARITY_NONE;
    huart5.Init.Mode = UART_MODE_TX_RX;
    huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart5.Init.OverSampling = UART_OVERSAMPLING_16;	
    if (HAL_UART_Init(&huart5) != HAL_OK)
    {
           Error_Handler();
    } 
}

My Main Application code and UART5 interrupt is as follows :

int main(void)
{
        HAL_Init();
 
       /* USER CODE BEGIN Init */
 
       /* USER CODE END Init */
 
       /* Configure the system clock */
	SystemClock_Config();
	
     /* USER CODE BEGIN SysInit */
     /* USER CODE END SysInit */
 
     /* Initialize all configured peripherals */
     MX_UART5_Init();	// interrupt priority 0
     MX_GPIO_Init();	
     MX_I2C1_Init();
     MX_RTC_Init();
     MX_SPI1_Init();
     MX_TIM1_Init();
     //MX_TIM2_Init();
     MX_UART4_Init();	// no interrupt
  
     MX_TIM3_Init();	// not used
     HAL_UART_Receive_IT(&huart5, &uart5_rx, 1);
     HAL_TIM_Base_Start(&htim1);
    
     while (1)
     {
         HAL_Delay(1);
     }
}
 
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{	
        if (huart->Instance == UART5)
        {
              HAL_UART_Transmit(&huart5, (uint8_t *)&uart5_rx, 1, 10);
              //HAL_UART_Transmit(&huart4, (uint8_t *)&uart5_rx, 1, 10);	
              HAL_UART_Receive_IT(&huart5, &uart5_rx, 1);		
        }
}

I have set UART interrupt preemption priority to 0 and Sub priority to 0.

The UART5 receive data waveform after I transmit from UART5 TX is below : 0693W00000VOmRlQAL.jpgTTL connection setting.

0693W00000VOsLtQAL.jpgI connected them to FTDI directly through TTL interface and through RS232 interface. But I get same behaviour in both of them.

The TX/RX cross connection is verified because I have transmitted and received bytes simply. And the ground connection in all of the boards are also common.

0693W00000VOsLyQAL.jpg

4 REPLIES 4

Looks to be ​a hardware side issue.

How exactly do you have this​ wired up? What board?

Common Grounds?

Cross connected or shorted to a secondary pin?​

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

My connections are shown above. Hope they answer your questions. The TX and RX are crossed accordingly and the systems have common ground.

Even I thought it to be hardware issue, but after checking with USB-TTL converter directly and connecting through RS232 converter in between as shown in figure above, I have suspicion in interrupt receiver.

My connections are shown above. Hope they answer your questions. The TX and RX are crossed accordingly and the systems have common ground.

Even I thought it to be hardware issue, but after checking with USB-TTL converter directly and connecting through RS232 converter in between as shown in figure above, I have suspicion in interrupt receiver.

Karl Yamashita
Lead III

It looks like you're trying to echo back what you received. Don't use HAL_UART_Transmit() from within an interrupt. Instead save each character received to a ring buffer using an In Pointer.

Then in your main loop you check the received ring buffer to see if you have new character(s). If you want to echo those new characters, the best thing to do is to save each character in a transmit ring buffer.

Then when trying to transmit each character if you don't get HAL_OK, then you don't increment your Out pointer yet. When you loop back around then you can try transmitting that same character again. If successful, you then increment you Out pointer so it points to the next character which is sent on the next loop..

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.