2015-12-17 12:23 AM
Hi,
I'm using uVision5 on windows7 to build and flash download but doing the experiment on Linux machine.(because UART COM port doesn't work on my win7 PC. I think this is a driver problem.). I've slightly modified the Uart_printf project so that the program prints something and receives commands from the console and prints it back. Below is the main() program.============ in main.c ===============char Rx_indx, Rx_data[2], Rx_Buffer[100], Transfer_cplt;UART_HandleTypeDef UartHandle;char buffer[100];int len;void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){ uint8_t i; if (huart->Instance == USART2) // current UART { if (Rx_indx==0) {for (i=0;i<100;i++) Rx_Buffer[i] = 0; } if (Rx_data[0] != 13) // if not enter { Rx_Buffer[Rx_indx++] = Rx_data[0]; // add data to Rx_Buffer } else { Rx_indx = 0; Transfer_cplt=1; // transfer complete, data is ready to be read } HAL_UART_Receive_IT(&UartHandle, (uint8_t *)Rx_data, 1); // reactivate }}int main(void){ HAL_Init(); SystemClock_Config(); -- set USART2 ... HAL_UART_Receive_IT(&UartHandle, (uint8_t *)Rx_data, 1); printf(''hello, World!\r\n''); while (1) { if (Transfer_cplt) { sprintf(buffer, ''%s\r\n'', Rx_Buffer); len = strlen(buffer); HAL_UART_Transmit(&UartHandle, (uint8_t *)buffer, len, 1000); Transfer_cplt = 0; } } while (1) { }}======= in stm32f4xx_it.c ================void SysTick_Handler(void){ HAL_IncTick(); HAL_SYSTICK_IRQHandler();}void USART2_IRQHandler(void){ printf(''USART2_IRQHandler called\n\r''); <==== !!! not work without this line. HAL_UART_IRQHandler(&UartHandle);}
========== end of code =========Below is the execution result when I have the ''USART2_IRQHandler called'' print in the USART2_IRQHandler(void) function.hello, World!USART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledabcdUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledefghUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledxyzghello, World!USART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledUSART2_IRQHandler calledabcdBut if I remove the print (''USART2_IRQHandler called'') the print-back is not shown. What is wrong with the code?