2014-09-11 08:24 AM
Dear Friends,
Hi,I want to get an interrupt by receiving each character on UART port. How can I use HAL_UART_Receive_IT() and HAL_UART_RxCpltCallback() functions? When I call HAL_UART_Receive_IT() function its call USART1_IRQHandler I want to know is it a
correct approach
to call HAL_UART_Receive_IT() function before each receiving character?
Thanks. #stm32cube-interrupt-uart
2014-09-12 09:47 AM
Hi Mohajer,
In fact, the HAL_UART_Receive_IT() API is designed to receive n byte in interrupt mode with (n: “Size� parameter). It's is called under UART IRQ for each byte received and the user callback HAL_UART_RxCpltCallback() is only executed at the end of the whole receive process, just after disabling the UART receive interrupt and receiving the last data.You just need to call this UART API: HAL_UART_IRQHandler() under the defined UART IRQ (USART1_IRQHandler) within the stm32fxxx.c file. (For more details please refer to the UART_Hyperterminal_IT example).
If you want get a callback HAL_UART_RxCpltCallback() for each character, in this case, you have to call the HAL_UART_Receive_IT() function (w/ Size parameter = 1) before each receiving character.
Hope that can help you, to have insight into the UART receive in interrupt mode.Regards.2014-09-13 07:16 AM
Hi Heisenberg,
Thank you for your good reply. I have enabled UART global interrupt. By using debugger the function void USART1_IRQHandler(void){...} won't be called. When I use HAL_UART_Receive_IT() in a loop I can receive characters and function void USART1_IRQHandler(void){...} will be called. The function void USART1_IRQHandler(void){...} is supposed to be called through receiving each character, but it didn't. Would you please help me to solve the problem? Also, where can I find UART_Hyperterminal_IT example? Regards.2014-09-16 05:45 PM
Hi
What I did to achieve this was to modify HAL_UART.C -> UART_Receive_IT() to add a weak callback for every byte. This way you can max out the size and be able to interrogate each byte without reloading the peripheral after every byte received (saving processor time). You can then do whatever you need if you detect a certain character. snippet: if(--huart->RxXferCount == 0) { __HAL_UART_DISABLE_IT(huart, UART_IT_RXNE); /* Check if a transmit process is ongoing or not */ if(huart->State == HAL_UART_STATE_BUSY_TX_RX) { huart->State = HAL_UART_STATE_BUSY_TX; } else { /* Disable the UART Parity Error Interrupt */ __HAL_UART_DISABLE_IT(huart, UART_IT_PE); /* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */ __HAL_UART_DISABLE_IT(huart, UART_IT_ERR); huart->State = HAL_UART_STATE_READY; } HAL_UART_RxCpltCallback(huart); } else { HAL_UART_RxByteCallback(huart); } return HAL_OK; } else { return HAL_BUSY; }2014-09-28 05:01 AM
Hi JasonP,
Thank you for your post. But the main problem is that interrupt never gets generated when I send data to the MCU. Maybe this is a bug in the STM32cube!2014-10-07 01:06 AM
Hi all,
After discussion with our development team, it turned out that this implementation is not adequate as the interruption sub-routine is polling the status register during the 2 last characters period.We have already the limitation in the STM32Cube HAL bugs list, and it will be fixed in next releases of F4. Please continue submitting your valuable feedback.Regards,Heisenberg.2015-01-01 08:38 AM
Hi Developers!
A sample solution: Step1. Add this code in main function before while(1): __HAL_UART_ENABLE_IT(&huart1, UART_IT_RXNE); HAL_NVIC_SetPriority(USART1_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART1_IRQn); Step2. Add this code in stm32f1xx_it.c: uint8_t ich; void USART1_IRQHandler(void) { ich = USART1->DR; HAL_UART_Transmit(&huart1, &ich,sizeof(ich), HAL_MAX_DELAY); }2015-07-31 03:24 AM
Hi Mohajer,
I think you have not enabled interrupt correctly so use following line after the USART initialization.__HAL_UART_ENABLE_IT(&UartHandle, UART_IT_RXNE); HAL_NVIC_SetPriority(USART1_IRQn, 3, 0); HAL_NVIC_EnableIRQ(USART1_IRQn);I hope it will resolve your problem2015-12-14 01:21 AM
Hi all,
I am using a STM32F415RG and I am trying to make the uart reception based on interrupts work (HAL_UART_Receive_IT). It's my first experience with fw development and though there are many examples available online I have always problems because in these examples are used homemade functions whose description is missing, or it isn't specified in which file the code should be written, or some things are taken for granted.I am looking for a basic tutorial/example with a step by step explanation of what I should do to make HAL_UART_Receive_IT work and how I should configure interrupts. Do you know such an example/tutorial? Could you kindly help me? Thank you!2015-12-14 09:15 AM
Hi Cel,
Are you aware of the examples that come bundled with the HAL library download? For example using the processor/board I'm working with it would be found inE:\STM32Cube_FW_F4_V1.5.0\Projects\STM32F429I-Discovery\Examples\UART\UART_TwoBoards_ComITThese use the HAL library and all of the configuration is typically in main.cIf you install the libraries via STM32CubeMX then you will have to figure out where MX stores the downloaded libraries. That seems to be listed in MX in the Help -> Updater Settings'' window.