2022-01-14 06:16 PM
Hi
I want to use a program i made before with the new IDE 1.8. It should reveive som data with the UART2 until EOL is received.
It works on time and after it throws an interrupt (loops in the void USART2_IRQHandler(void)) but doesn't call the HAL_UART_RxCpltCallback anymore.
I think I tried everything, here some parts of the code:
int main(void)
{
...
HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1); //activate UART receive interrupt every time
HAL_NVIC_SetPriority(USART2_IRQn, 3, 0);
HAL_NVIC_EnableIRQ(USART2_IRQn);
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
}
while (1)
{
if (Transfer_cplt > 0)// Daten vorhanden
{
... do someting with receive data
}
}
static void MX_UART2_UART_Init(void)
{
huart2.Instance = USART2;
huart2.Init.BaudRate = 19200;
huart2.Init.WordLength = UART_WORDLENGTH_8B;
huart2.Init.StopBits = UART_STOPBITS_1;
huart2.Init.Parity = UART_PARITY_NONE;
huart2.Init.Mode = UART_MODE_TX_RX;
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart2) != HAL_OK)
{
Error_Handler();
}
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
int i;
int Rx_indx=0;
if (huart->Instance == USART2) //KS UART
{
__HAL_UART_DISABLE_IT(&huart2, UART_IT_RXNE);
for(i = 0;i<=sizeof(Rx_data);i++)
{
if (Rx_data[0] == 10 || Rx_data[0] == 13)
{
break;
}
RxBuffer[i]= toupper(Rx_data[0]); //add data to Rx_Buffer
HAL_UART_Receive(&huart2,(uint8_t*) Rx_data, 1,10);
}
Transfer_cplt=1;//transfer complete, data is ready to read
}
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1);
}
Any Idea'?
Solved! Go to Solution.
2022-01-17 01:10 PM
Ok - i found the problem.
It was a memory location fail (initalize more then the size)- and this resets the UART Setings (it occures after the first receive) an after this my UART->Init was 0 - and maybe other flags too.
Now i know all the uart bit's :)
Thanks all
Wolfgang
2022-01-15 06:13 AM
> it throws an interrupt (loops in the void USART2_IRQHandler(void)) but doesn't call the
> HAL_UART_RxCpltCallback anymore.
Maybe consequence of UART error, e.g. overflow. Have a look at USART_SR.
JW
2022-01-15 12:29 PM
Code is a bit of a mess. Calling blocking receive in RX receive complete interrupt, then back to IT. Checking past end of buffer. Comparing only first byte.
2022-01-17 03:14 AM
Hi TDK
it's working fine. I receive the first Byte with interrupt, then i poll the next "single" bytes until a CR or LF arrives.
RxBuffer[i]= toupper(Rx_data[0]); adds the last byte in loop.
This is not the problem ;)
2022-01-17 06:30 AM
Hi Jan
when it works correct the firts time i get an error- but i think its because of the breakpoint (UART_Error_Callback is called). The Registers look like this:
SR = 0xf8
CR1 = 0x212c
CR3 = 0x1
In the next run no error ocures when the HAL_UART_IRQHandler(UART_HandleTypeDef *huart) is startet. The flags set in this way:
SR is set to 0x20008000
CR1 = 0x8002191
CR3 = 0x800219d
/* If no error occurs */
errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE)); == 0
if (errorflags == RESET)
{
/* UART in mode Receiver -------------------------------------------------*/
if (((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) // this condition is false
{
UART_Receive_IT(huart);
return;
}
}
it looks like the SR and CR1 is not set to the USART_SR_RXNE Value, but anyhow the interrupt is thrown!?
The problem is - I have no idea where or when the bits are set
Has anyone an other idea?
Thanks in advance
Wolfgang
2022-01-17 06:43 AM
If you observe UART registers in debugger, that clears its flags, among others also RXNE.
JW
2022-01-17 07:30 AM
I tried it without debugger too, but its the same effect.
It looks like an unknown UART interrupt is thrown all the time.
I tried the Release Version, it hangs in the same way.
Is this part of my Callback ok?
__HAL_UART_ENABLE_IT(&huart2, UART_IT_RXNE);
HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1);
Wolfgang
2022-01-17 09:49 AM
> UART_Error_Callback is called
If the error callback is triggered, read the reason for the error in the ErrorCode variable and correct.
RXNE interrupt is enabled within HAL_UART_Receive_IT, no need to duplicate it.
Monitor return status of HAL_* functions to verify they return HAL_OK.
2022-01-17 11:26 AM
Hi TDK
the HAL_OK comes with 0 (without breakpoint in the interrupt-Routine)
But my problem is, that the HAL_UART_RxCpltCallback in my Main is only called one time. After this the Receive- Interrupt is reconized, but the callback is never called again.
I watched what was happen after the first receive is complete:
after my:
HAL_Ret = HAL_UART_Receive_IT(&huart2, (uint8_t *)Rx_data, 1);
it comes to finaly to
HAL_StatusTypeDef UART_Start_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
huart->pRxBuffPtr = pData;
huart->RxXferSize = Size;
huart->RxXferCount = Size;
huart->ErrorCode = HAL_UART_ERROR_NONE;
huart->RxState = HAL_UART_STATE_BUSY_RX;
/* Process Unlocked */
__HAL_UNLOCK(huart);
/* Enable the UART Parity Error Interrupt */
__HAL_UART_ENABLE_IT(huart, UART_IT_PE);
/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
__HAL_UART_ENABLE_IT(huart, UART_IT_ERR);
/* Enable the UART Data Register not empty Interrupt */
__HAL_UART_ENABLE_IT(huart, UART_IT_RXNE);
return HAL_OK;
}
I wonder why is the huart->RxState = HAL_UART_STATE_BUSY_RX; ????
should it not be HAL_UART_STATE_READY?
Wolfgang
2022-01-17 01:10 PM
Ok - i found the problem.
It was a memory location fail (initalize more then the size)- and this resets the UART Setings (it occures after the first receive) an after this my UART->Init was 0 - and maybe other flags too.
Now i know all the uart bit's :)
Thanks all
Wolfgang