2019-11-27 09:05 PM
Hi All,
I config UART on interrupt, after receving data on UART simple sending data at that time hard fault occur.
UART enabling code
MX_GPIO_Init();
MX_DMA_Init();
MX_USART2_UART_Init();
MX_RTC_Init();
MX_SPI3_Init();
MX_TIM2_Init();
MX_TIM15_Init();
MX_TIM1_Init();
MX_TIM4_Init();
MX_TIM8_Init();
/* USER CODE BEGIN 2 */
__HAL_UART_ENABLE_IT(&huart2,UART_IT_RXNE);
UART handler
void USART2_IRQHandler(void)
{
/* USER CODE BEGIN USART2_IRQn 0 */
/* USER CODE END USART2_IRQn 0 */
HAL_UART_IRQHandler(&huart2);
/* USER CODE BEGIN USART2_IRQn 1 */
HAL_UART_Receive_IT(&huart2,rx_data,14);
/* USER CODE END USART2_IRQn 1 */
}
Hal is not proving variable length string on interupt So I make them fix length of string.
Once I get the data after that sending data via
HAL_UART_Transmit(&huart2, response,11,200);
After that... If any once has any suggetion let me know or also tell me how to debug hard fault or any exceptions.
Thanks in advance
2019-11-27 09:44 PM
Check what HAL_UART_Receive_IT() actually does. Don't guess.
2019-11-27 09:50 PM
@turboscrew Receive an amount of data in interrupt mode. is there anything specific you want to tell tell me because I didn't get your point
2019-11-28 10:08 PM
It doesn't quit do what you expected?
HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size)
{
/* Check that a Rx process is not already ongoing */
if (huart->RxState == HAL_UART_STATE_READY)
{
if ((pData == NULL) || (Size == 0U))
{
return HAL_ERROR;
}
/* Process Locked */
__HAL_LOCK(huart);
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;
}
else
{
return HAL_BUSY;
}
}
/**
2019-11-29 08:39 PM
Thanks for you support.
I found the issue.... this because my logic is not working as I expected. or I can say issue in my logic which is leads to a hard fault.