2020-11-01 06:53 PM
I am using STM32 F767zi MC and I want to communicate with RS485 encoder.
This is my code which has written in stm32f7xx_it.c. When executing this code, it can be seen that encoder and MC communicating continuously (observed using oscilloscope). But my problem is when executing this code, infinity loop inside my main loop is blocked. Could you please help me to solve this matter?
Thank you.
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_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 1/16, 1/16);
if(__HAL_UART_GET_IT(&huart2, UART_IT_TXE)==SET){
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, 1); //DE ON
USART2->TDR = TxBuf[0];
__HAL_UART_ENABLE_IT(&huart2, UART_IT_TC);
__HAL_UART_DISABLE_IT(&huart2, UART_IT_TXE);
while(__HAL_UART_GET_IT(&huart2, UART_IT_TC)!=SET)
;
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_4, 0); //DE OFF
int j=0;
while(j<3){
if(__HAL_UART_GET_IT(&huart2, UART_IT_RXNE)==SET){
RxBuf[j] = USART2->RDR;
j++;
}
}
__HAL_UART_DISABLE_IT(&huart2, UART_IT_TC);
__HAL_UART_CLEAR_FLAG(&huart2, UART_FLAG_TC);
__HAL_UART_DISABLE_IT(&huart2, UART_IT_RXNE);
}
/* USER CODE END USART2_IRQn 1 */
}
2020-11-02 06:03 AM
You're performing blocking operations from within the interrupt, preventing the mcu from making any progress in the main loop.
2020-11-03 12:46 AM
Thank you for the reply. Is it because of the while loops that the blocking mode perform?
2020-11-03 05:35 AM