STM32 F767Zi RS485 interrupt code blocks main() loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-01 6: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 */
}
- Labels:
-
Interrupt
-
STM32F7 Series
-
UART-USART
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-02 6:03 AM
You're performing blocking operations from within the interrupt, preventing the mcu from making any progress in the main loop.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-03 12:46 AM
Thank you for the reply. Is it because of the while loops that the blocking mode perform?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-11-03 5:35 AM
