2020-09-01 11:13 AM
Hi, i need to receive serial data as ISR. i have 3 USART module. this is my test code. this is work fine. but some time suddenly stop the firing ISR routing of receiving event .when i call this line after stop the modem RX ISR function
HAL_UART_Receive_DMA(&huart4, buff_modem_ISR, 1);
again code is work fine.
what will the issue. cant we write 3 separate ISR_RX_COMPLETE function?
Greetings
uint8_t buff_deb_ISR[10];
uint8_t buff_modem_ISR[10];
uint8_t buff_gps_ISR[10];
void init_modem(uint16_t baud ){
huart4.Instance = UART4;
huart4.Init.BaudRate = baud;
huart4.Init.WordLength = UART_WORDLENGTH_8B;
huart4.Init.StopBits = UART_STOPBITS_1;
huart4.Init.Parity = UART_PARITY_NONE;
huart4.Init.Mode = UART_MODE_TX_RX;
huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart4.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart4) != HAL_OK)
{
printf("usrat 4 error\r\n");
// Error_Handler();
}
}
/**
* @brief USART1 Initialization Function
* @param None
* @retval None
*/
void init_gps(uint16_t baud )
{
/* USER CODE BEGIN USART1_Init 0 */
/* USER CODE END USART1_Init 0 */
/* USER CODE BEGIN USART1_Init 1 */
/* USER CODE END USART1_Init 1 */
huart1.Instance = USART1;
huart1.Init.BaudRate = baud;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
// Error_Handler();
}
/* USER CODE BEGIN USART1_Init 2 */
/* USER CODE END USART1_Init 2 */
}
/**
* @brief USART2 Initialization Function
* @param None
* @retval None
*/
void init_debug(uint16_t baud )
{
/* USER CODE BEGIN USART2_Init 0 */
/* USER CODE END USART2_Init 0 */
/* USER CODE BEGIN USART2_Init 1 */
/* USER CODE END USART2_Init 1 */
huart2.Instance = USART2;
huart2.Init.BaudRate = baud;
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();
}
/* USER CODE BEGIN USART2_Init 2 */
/* USER CODE END USART2_Init 2 */
}
/**
* Enable DMA controller clock
*/
void DMA_init(void)
{
/* DMA controller clock enable */
__HAL_RCC_DMA1_CLK_ENABLE();
__HAL_RCC_DMA2_CLK_ENABLE();
/* DMA interrupt init */
/* DMA1_Channel2_IRQn interrupt configuration */ //timer
HAL_NVIC_SetPriority(DMA1_Channel2_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA1_Channel2_IRQn);
/* DMA1_Channel5_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel5_IRQn, 0, 0); //usart1
HAL_NVIC_EnableIRQ(DMA1_Channel5_IRQn);
/* DMA1_Channel6_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 0, 0); //usart2
HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
/* DMA2_Channel3_IRQn interrupt configuration */
HAL_NVIC_SetPriority(DMA2_Channel3_IRQn, 0, 0);//usart4
HAL_NVIC_EnableIRQ(DMA2_Channel3_IRQn);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance==USART1) {
//do
printf("gps %c",buff_gps_ISR[0]);
}
else if(huart->Instance==USART2) {
//do
printf("debug %c",buff_deb_ISR[0]);
}
else if(huart->Instance==UART4) {
//do
printf("modem %c",buff_modem_ISR[0]);
}
}
void main(){
DMA_init();
init_modem(9600);
init_gps(2400);
init_debug(9600);
HAL_UART_Receive_DMA(&huart4, buff_modem_ISR, 1);
HAL_UART_Receive_DMA(&huart1,buff_gps_ISR, 1);
HAL_UART_Receive_DMA(&huart2,buff_deb_ISR, 1);
while(1);
2020-09-01 11:28 AM
>>what will the issue. cant we write 3 separate ISR_RX_COMPLETE function?
If you want to use the HAL/Callback methods, HAL_UART_RxCpltCallback() will need to decompose and dispatch individual routines.
The hardware is capable of doing dispatch/service directly in the IRQ Handler.
>>but some time suddenly stop the firing ISR routing of receiving event.
a) Don't do multi-character printf() or delays in the callback, it is occurring under interrupt context.
b) Dispatch a new HAL_UART_Receive_DMA(), to restart for a new character, or batch of.