2017-04-18 05:45 AM
In order to configure UART interrupt receive, I put HAL_UART_Receive_IT function in HAL_UART_RxCpltCallback.
but it doesnt work. below is my callback code.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{ uint8_t i; if (huart->Instance == USART2) //current UART { if (Rx_indx==0) {for (i=0;i<RXBUFFERBYTE;i++) aRxBuffer[i]=0;} //clear Rx_Buffer before receiving new data if (Rx_data[0]!=10) //if received data different from ascii 10 { aRxBuffer[Rx_indx++]=Rx_data[0]; //add data to Rx_Buffer } else //if received data = 10 { Rx_indx=0; USART2_RX_STANBY=1;//transfer complete, data is ready to read } if(HAL_UART_Receive_IT(&huart2,Rx_data, 1) != HAL_OK)//activate UART receive interrupt every time { Error_Handler(); } } }The main program has HAL_UART_Receive_IT in beginning part. so i put some character of ASCII and my program reach if(HAL_UART_Receive_IT(&huart2,Rx_data, 1) != HAL_OK) . I checked that HAL_UART_Receive_IT returned HAL_OK then it means preparation of UART receive interrupt.
but the program doenst take interrupt when I send ASCII to MCU.
I have no clue.. anyone who have had same experience??
help me please.
Thank you.
2017-04-18 06:56 AM
Hi i,
You may refer to the UART example of the STM32cube firmware package relevant to the device that you are using.
The example help you in your project to ensure UART transmission and reception with Interrupt.
You can use STM32CubeMx tool which help you to develop the basic configuration of your application and generate an initialization code.
Imen
2017-04-18 09:10 AM
Hi,
1. Make sure the USART2 Global Interrupt is enabled (See NVIC settings in the USART2 Configuration in STM32CubeMx if you are using it).
2. I don't think you need to use HAL_UART_Receive_IT in the Interrupt handler. This call is only necessary one time at initialization time.
Regards,
Alex
2017-04-18 11:05 PM
I executed the same program and it worked but has different problem.
my main while program is below
while (1)
{ if(TIM2_Loop_On==1) { if(USART2_RX_STANBY==1) { sprintf(aTxBuffer,'%s \n',aRxBuffer); if(HAL_UART_Transmit(&huart2, aTxBuffer, TXBUFFERSIZE, 1000)!= HAL_OK) { Error_Handler(); } USART2_RX_STANBY=0; }/*
sprintf(aTxBuffer,'welcome \n');
if(HAL_UART_Transmit(&huart2, (uint8_t*)aTxBuffer, TXBUFFERSIZE, 1000)!= HAL_OK) { Error_Handler(); }*/
TIM2_Loop_On=0; }/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */}
When i executed this program, i can get same character as what i send.
I erased /* */(annotation) then i can get 'welcome' message at a regular interval.
but when i send some character, my program stops.
I guess the problem is when Rx Interrupt and Tx routine happen at the same time, program counter enter the Error_Handler().
so how can i use Rx interrupt and Tx routine together?
Thank you
2017-04-19 12:44 AM
Thank you. guy
1. I enabled USART2 global Interrupt by HAL_UART_Receive_IT in beginning part of my program.
2. I am a little confused of the fact that HAL_UART_Receive_IT or __HAL_USART_ENABLE_IT should be executed to wait for next UART Receive Interrupt whenever UART Receive ends. where can i get a manual related with it??
I will update this post after making sure that HAL_UART_Receive_IT should be executed only one time by some experiment.
2017-10-03 11:06 PM
Could you solve your problem?
What was the version of your HAl library ?
2017-10-03 11:38 PM
Evidence suggests an STM32L0 version of HAL..
I will observe that it's not unduly hard to code very efficient register based IRQ Handlers for (LP)U(S)ART on the L0 parts. The Rx and Tx can definitely occur concurrently.
2017-10-07 03:11 AM
what about STM32f1?
My microcontroller is stm32f103zet6 and sensor continuously sends me data and I receive them via uart. when I try to send data to this sensor without interrupt(using HAL_UART_Transmit()) at some times seems uart peripheral hangs and can not receive data any more. but when I use
HAL_UART_Transmit_IT() which uses interrupt for sending data over uart, it seems that uart doesn't hang any more. why? is it because of that concorrent working with data register?
Isn't any way to send data without interrupt in these situation?
2017-10-07 10:38 AM
>>what about STM32f1?
The register names and status bits are slightly different, but functionally very similar.
>>when I try to send data to this sensor without interrupt(using HAL_UART_Transmit()) at some times seems uart peripheral hangs and can not receive data any more.
Well the function likely blocks for multiple byte times, and the Rx overruns and flags error status, which must be cleared.
>>
Isn't any way to send data without interrupt in these situation?
Yes, but you have to move beyond the Wait for buffer TX, Wait for buffer RX, Repeat mentality. When things are occurring concurrently you can't serialize the operations like this.
What you need is mechanism that doesn't block, for example
while(1) // Polling loop pseudo code
{
if SR.RXNE then InputFifoWrite(DR);
if SR.TXE and OutputFifoNotEmpty() then DR = OutputFifoRead();
PumpProcess();
}
Where you monitor the status, but don't get hung up waiting for a buffer to be completely full, or completely empty. Think of it as juggling with three balls, and two hands, at least one is always in the air, and you drop things if you stop.
2017-10-07 02:00 PM
Turvey.Clive
This reply is to specify that you gave almost the exact same response to me a few days ago.