A detailed explanation of the problem of receiving interrupts in the USART module

Problem Description:

When using the USART for serial communication, I only turned on the receiving interrupt and set the preemption priority to the lowest level. The receiving interrupt to the previous priority handles more things and may take up to 2ms. When I use 9600 baud rate to send data to the next machine, the speed is very fast, that is, always press the return send! The problem came out. In less than one minute, the communication did not respond. The USART configuration code is as follows:

Void uart_config(void)

{

USART_InitTypeDef USART_InitStructure;

USART_InitStructure.USART_BaudRate = UART_GetBaud(BaudRate);

USART_InitStructure.USART_WordLength = USART_WordLength_8b;

USART_InitStructure.USART_StopBits = USART_StopBits_1;

USART_InitStructure.USART_Parity = USART_Parity_No;

USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

USART_InitStructure.USART_Clock = USART_Clock_Disable;

USART_InitStructure.USART_CPOL = USART_CPOL_Low;

USART_InitStructure.USART_CPHA = USART_CPHA_2Edge;

USART_InitStructure.USART_LastBit = USART_LastBit_Enable;

/* Configure USART1 */

USART_Init(USART1, &USART_InitStructure);

/* Enable USART1 receive interrupt */

USART_ITConfig (USART1, USART_IT_RXNE, ENABLE);

/* Enable the USART1 */

USART_Cmd(USART1, ENABLE);

}

analyse problem:

1. Why is there no news?

Through emulator simulation, it was found that the program has been entering the receive interrupt. Since I did not use the interrupt to send, the program dies in the receive interrupt and no data is sent to the computer. Receive interrupt code as follows:

Void UART_Receive(void)

{

//Processing last communication, received data is not processed

If(bRecieveOK)

{

If(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

USART_ClearITPendingBit(USART1, USART_IT_RXNE);

Return;//processing receive data,don't receive again

}

If(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

{

If(MoudBusExpir == 0)

{

ucRcePtr = 0;

MoudBusExpir = 20;//50ms

}

Else

MoudBusExpir = 20;

/* Read one byte from the receive data register */

ucRS485Buff[ucRcePtr++] = USART_ReceiveData(USART1);

/* Clear the USART1 Receive interrupt */

USART_ClearITPendingBit(USART1, USART_IT_RXNE);

}

}

2. Why does it continue to receive interrupts?

After the breakpoint was found (USART_GetITStatus(USART1, USART_IT_RXNE)==RESET, that is to say no data was received and also interrupted, and in the USART configuration I only opened the receive interrupt! No data should be sent over it should not be possible to enter Interrupted!

3. What interrupted the response?

I want to use the function (USART_GetITStatus() to read out all the interrupt statuses, but failed. All USART_IT_XXX interrupt statuses are RESET! This means that without interrupts, I will enter this interrupt service routine!?

4. Find information

STM32F10x Microcontroller Reference Manual (December 10th, 2009) P541 found the following instructions:

A detailed explanation of the problem of receiving interrupts in the USART module

That is, as long as the receive interrupt is turned on, that is, RXNEIE is set to 1, the ORE interrupt is automatically turned on.

However, USART_GetITStatus(USART1, USART_IT_ORE) == RESET! ! ! !

The USART_GetITStatus(USART1, USART_IT_RXNE) function was found and it was found that the ORE interrupt was only read when the USART_IT_ERR interrupt was enabled.

Here to point out this BUG: ORE interrupt generated, but USART_GetITStatus () function can not read this interrupt is SET!

5. Clear the ORE interrupt flag

Since it is found what the interrupt, then the corresponding interrupt flag cleared, it should be OK?

USART_ClearITPendingBit(USART1, USART_IT_ORE);

However, the result is no effect! Immediately after clearing, read the ORE interrupt status, USART_GetITStatus(USART1, USART_IT_ORE)==RESET. The program still ran dead in the receive interrupt. Then use another function USART_GetFlagStatus(USART1, USART_FLAG_ORE) = SET, the original ORE flag has not been cleared.

6. Problem solving

Why can't I clear it? Headache, and then find information, found, as shown in the P523 page as follows:

A detailed explanation of the problem of receiving interrupts in the USART module

Receive interrupt program was changed to:

Void UART_Receive(void)

{

If (USART_GetFlagStatus(USART1, USART_FLAG_ORE) != RESET)//NOTE! Cannot be judged using if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

{

USART_ReceiveData(USART1);

}

//Processing last communication, received data is not processed

If(bRecieveOK)

{

If(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

USART_ClearITPendingBit(USART1, USART_IT_RXNE);

Return;//processing receive data,don't receive again

}

If(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)

{

If(MoudBusExpir == 0)

{

ucRcePtr = 0;

MoudBusExpir = 20;//50ms

}

Else

MoudBusExpir = 20;

/* Read one byte from the receive data register */

ucRS485Buff[ucRcePtr++] = USART_ReceiveData(USART1);

/* Clear the USART1 Receive interrupt */

USART_ClearITPendingBit(USART1, USART_IT_RXNE);

}

}

to sum up:

Note the problem:

1.USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); Enable receive interrupt, then ORE interrupt is also enabled.

2.ORE interrupt can only be read using USART_GetFlagStatus(USART1, USART_FLAG_ORE) (when USART_IT_ERR interrupt is not enabled)

BUG Recommendation: 1. Can the USART_GetITStatus() function handle USART_IT_ORE interrupts in the STM32 library? That is, as long as I open the receive interrupt, then if there is an ORE interrupt, I can read it using USART_GetITStatus(USART1, USART_IT_ORE).

Miscellaneous: At the same time when looking for data, we found that the STM32F10x microcontroller reference manual (December 10th, 2009, version 10) had an error in Chinese translation P538, as shown below:

A detailed explanation of the problem of receiving interrupts in the USART module

English P696 as shown below:

A detailed explanation of the problem of receiving interrupts in the USART module

Education Tablet

As a mobile multi-purpose platform, tablet computers also provide many possibilities for mobile teaching. The touch-based learning & entertainment teaching platform allows children to efficiently improve their academic performance in a relaxed and pleasant atmosphere. Such tablet computers generally integrate two learning sections of various courses and systematic learning functions. Generally, it includes multi-disciplinary high-quality teaching resources. The education tablet has the following main functions: it has the functions of touch screen input, text editing, picture editing, data storage, data management, wired and wireless Internet access that ordinary tablet computers have; Management functions, search methods support manual search, query by keyword, query by time; text and pictures can be scanned and converted into documents to save.

Education Tablet,learning tablet,leaning machine,New learning tablet

Jingjiang Gisen Technology Co.,Ltd , https://www.gisengroup.com