2020-04-11 08:39 AM
I want pass UART_HandleTypeDef *my_huart at function HAL_UART_Transmit and and mange the response with interrupt. The code is show below but doesn't work. Can you help me?
//This is myfile.c
void myfunc(UART_HandleTypeDef *my_huart)
{
char command[] = "AT\r\n";
HAL_UART_Transmit(my_huart, (uint8_t *)command, sizeof(command)-1, HAL_MAX_DELAY);
}
//In the main
myfunc(&huart1);
//out of main and not call in the main
void USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
if(((USART1 -> SR) & (1<<5)) == (1<<5))
{
memset(buffer,0,sizeof(buffer));
HAL_UART_Receive(&huart1, (uint8_t *)buffer, sizeof(buffer)-1, HAL_MAX_DELAY);
HAL_UART_Transmit(&huart2, (uint8_t*)buffer, strlen(buffer) , HAL_MAX_DELAY);
USART1 -> SR &= ~(1<<5);
}
}
2020-04-11 08:51 AM
Ok, don't call blocking functions in the IRQ handler. You shouldn't need to clear the SR, this will occur by actions you take with the DR
Pointer passing in first function seems correct. I'd probably create a string send function and use strlen(), and then use that function rather than have duplicative code.
The IRQ Handler should call the HAL IRQ routine, which in turn calls your call back function.
Use the interrupt form HAL_UART_Transmit_IT()
2020-04-11 09:35 AM
Hi @Community member ,
don't call blocking functions in the IRQ handler -> I don't have call HAL_UART_Receive(&huart1,..) and HAL_UART_Transmit(&huart2,..), how should I read the data? Do I have to read directly from the register?
These other points are not clear to me:
The IRQ Handler should call the HAL IRQ routine, which in turn calls your call back function.
Use the interrupt form HAL_UART_Transmit_IT()
2020-04-11 09:45 AM
You can't spend multiple bytes times within the IRQ, you must be brief and leave.
You should perhaps create your own buffers and service those in the IRQ Handler, or call back.
Try reviewing some UART IRQ examples and follow the anticipated flow