cancel
Showing results for 
Search instead for 
Did you mean: 

USART Rx interrupt NOT Work

SoHaeng.Lee
Associate II
Posted on October 17, 2017 at 18:03

0690X00000608eIQAQ.png

I tested three devices all day long today.

All devices are connected to the USART, but the incoming interrupt does not work at all.

A program that connects the Lo Ra modules, GPS modules, and wifi modules to USART 1 and outputs the data sent to USART 2.

However, the Rx Interrupt does not work at all.

Attach the project file.

Note: this post was migrated and contained many threaded conversations, some content may be missing.
26 REPLIES 26
Posted on October 18, 2017 at 15:15

Does polling mode work, does RXNE assert? Not going to get interrupts if device doesn't see data.

Does the test app I attached function on the F446?

Check the bit timing on the scope, send an 0x55 data pattern out of the STM32, and check the timing on that.

>>

So I think it's a bug in a library.

While I dislike HAL as much as the next guy, I think something else is amiss here.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 18, 2017 at 16:21

Thank you very much for your advice.

Let's take a closer look at the test. 

Posted on October 18, 2017 at 18:02

Ok. You say it doesn't work, or your don't get interrupts.

You don't have anything in you main loop to see if its still running.

You don't have an error handler for the Uarts.

I am going to bet you end up with something if you add this and a breakpoint

volatile uint32_t usarterror;

void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
usarterror = HAL_UART_GetError(huart);
// see errors on line 207-212 of stm32f4xx_hal_uart.h
_Error_Handler(__FILE__, __LINE__);
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Posted on October 18, 2017 at 18:51

I set up a new cube project for Nucleo-F401RE, doing what you are doing. USART1 was connect to USB2SER adapter. USART2 pins (pa2/pa3) are not connected at the morpho or arduino connectors. They are connected to StLink and the VCP. At first i setup USARTs at 115K

Both ends are connected to terminal apps on PC.

When i send single chars works fine.

Then i sent a file, and got missing charsand errors (overrun) at the error handler.

Works fine, if i add 1ms internal char delay in sending the file.

401 is running at 84MHz. your 446RE might do better at 180MHz with both at 115K.

But, you are using 9600 and 115K. You should have no issue for 9600 device going to 115k forwarding.

When usart2 (device) is set at 9600, there are no errors, and no need for char delays (device forwarded to PC)

Butthe reverse case, with yoursimple symmetric handlers with blocking sends are not going to work, goingthe other way,unlessyou throttle the send (ie single chars with very large inter char delays).

Nothing wrong with HAL libs. They work. I get interrupts. I am using latest cube and F4 HAL.

Here is working code on NUC 401, but it too will fail, going 115K to 9600, if you send without some form of throttling.

/* Includes ------------------------------------------------------------------*/
#include 'main.h'
#include 'stm32f4xx_hal.h'
#include 'usart.h'
#include 'gpio.h'
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
/* Private variables ---------------------------------------------------------*/
uint8_t txbuffer[16] = 'hello

';
uint8_t rxbuffer1[16];
uint8_t txbuffer1[16];
uint8_t rxbuffer2[16];
uint8_t txbuffer2[16];
volatile uint8_t newdata1 = RESET;
volatile uint8_t newdata2 = RESET;
volatile uint32_t usarterror;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
/* USER CODE BEGIN PFP */
/* Private function prototypes -----------------------------------------------*/
/* USER CODE END PFP */
/* USER CODE BEGIN 0 */
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
 if (huart->Instance == USART1)
 {
 newdata1 = SET;
 }
 if (huart->Instance == USART2)
 {
 newdata2 = SET;
 }
}
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart)
{
 usarterror = HAL_UART_GetError(huart);
 // see errors on line 207-212 of stm32f4xx_hal_uart.h
 _Error_Handler(__FILE__, __LINE__);
}
/* USER CODE END 0 */
int main(void)
{
 /* USER CODE BEGIN 1 */
 /* USER CODE END 1 */
 /* MCU Configuration----------------------------------------------------------*/
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 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_GPIO_Init();
 MX_USART2_UART_Init();
 MX_USART6_UART_Init();
 MX_USART1_UART_Init();
 /* USER CODE BEGIN 2 */
 if (HAL_UART_Receive_IT(&huart1, (uint8_t*)rxbuffer1, 1) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
 if (HAL_UART_Receive_IT(&huart2, (uint8_t*)rxbuffer2, 1) != HAL_OK)
 {
 _Error_Handler(__FILE__, __LINE__);
 }
 /* USER CODE END 2 */
 /* Infinite loop */
 /* USER CODE BEGIN WHILE */
 while (1)
 {
 /* USER CODE END WHILE */
 /* USER CODE BEGIN 3 */
 if (newdata1)
 {
 txbuffer2[0] = rxbuffer1[0];
 HAL_UART_Receive_IT(&huart1, (uint8_t*)rxbuffer1, 1);
 HAL_UART_Transmit_IT(&huart2, (uint8_t*)txbuffer2, 1);
 newdata1 = RESET;
 }
 if (newdata2)
 {
 txbuffer1[0] = rxbuffer2[0];
 HAL_UART_Receive_IT(&huart2, (uint8_t*)rxbuffer2, 1);
 HAL_UART_Transmit_IT(&huart1, (uint8_t*)txbuffer1, 1);
 newdata2 = RESET;
 }

 }
 /* USER CODE END 3 */
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Posted on October 18, 2017 at 19:40

Some debugging, and seeing where the code is stuck or non-functional would be enlightening

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Yasin Yelkovan
Associate III
Posted on October 19, 2017 at 15:45

I had a similar problem with USART RX interrupts but could not solve it (

https://community.st.com/0D70X000006SydqSAC

). Than I started to use DMA for USART RX  and now I have no problem yet.
Posted on October 19, 2017 at 14:19

Hi, Clive One

I tested it all day long.

test result is 

1.If the device and the baud rate are between 115200bps, DO NOT enter the Rx Interrupt.

2. If i have 9600bps the speed between devices and boards, enter the Rx Interrupt point.

3. If the size of the data sent at a time is greater than 1K byte, DO NOT enter the Rx Interrupt. (115200, 9600)

4. Only HAL used it.

*Device support 115200.

thanks.

Posted on October 19, 2017 at 15:15

For burst traffic you'd need to build a FIFO buffer that provides enough depth and elasticity to absorb the differential rates between the two ports.

For continuous traffic you'd have to throttle, via flow-control, because the 9600 baud channel is never going to off-load data arriving at 115200 baud quickly enough.

BTW The NEO-6M module you're using looks fake/counterfeit.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 20, 2017 at 03:37

Hi

I tested it all day long.

test result is 

1.If the device and the baud rate are between 115200bps, DO NOT enter the Rx Interrupt.

2. If i have 9600bps the speed between devices and boards, enter the Rx Interrupt point.

3. If the size of the data sent at a time is greater than 1K byte, DO NOT enter the Rx Interrupt. (115200, 9600)

4. Only HAL used it.

*Device support 115200.

thanks.

Posted on October 20, 2017 at 03:38

I attached the sample file I made to your post.