2017-01-19 04:51 PM
I want to get UART Interrupted data to vary LED blinking speed.
For example,If I send 1 then speed 100ms or send 2 then speed 200ms.
I made a cod using CubeMX and Interrupting with just pressing ''Enter'' works perfect(Not sending any data)
(I pressed ''Enter'' 3 times in Line Sender)
but If I send some character like below, It iterrupts just one time and never interrupt again with my further interrupt action.
Here is my Code.
First of al,l I am getting Terminal ''printf''output into Serial usingcode below in function ''HAL_UART_MspDeInit''in usart.c.
/* USER CODE BEGIN 1 */
#ifdef __GNUC__
/* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf set to 'Yes') calls __io_putchar() */
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
* @brief Retargets the C library printf function to the USART.
* @param None
* @retval None
*/
PUTCHAR_PROTOTYPE{
/* Place your implementation of fputc here */
/* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */ HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
return ch; }
/* USER CODE END 1 */
in my main.c
while (1)
{
HAL_Dealy(100);
printf(''Hello!\r\n'');
}
in stm32f7xx_it.c
viod USART1_IRQHandler(void)
{
/* USER CODE BEGIN USART1_IRQn 0 */
if ((_HAL_UART_GET_FLAG(&huart1, UART_FLAG_RXNE) != RESET) && (__HAL_UART_GET_IT_SOURCE(&hurat1, UART_IT_RXNE) != RESET)
{
printf(''I will Interrupt You!!!\r\n'');
}
__HAL_UART_CLEAR_PEFLAG(&huart1);
/* USER CODE END USART1_IRQn 0 */
HAL_UART_IRQHandler(&huart1);
}
Do you have any idea what went wrong here?
#stm32f746-uart #stm32f746-discovery #uart #stm32f746-cubemx2017-01-19 05:10 PM
it is not good practice to do anything inside interrupts...
maybe save a byte, increment a counter, set a flag... thats it... under 10uS would be best...
so in the user code area of the interrupt routine,
set a flag....
to say UsartInterruptHasFired = true;
set a GLOBAL variable in main.c
above main();
bool UsartInterruptHasFired;
in main, above while (1)
UsartInterruptHasFired = false;
within the main foreground loop under while(1)
if (UsartInterruptHasFired ){
UsartInterruptHasFired = false;
printf('I will Interrupt You!!!\r\n');
}
that is the best way.
Printf will probably take at least 1mS, if your baud rate is above 9600, you will lose bytes.
you will lose bytes if you use printf within the interrupt.
while the interrupt is busy doing the printf, it cannot receive any other bytes.