01 | /* USER CODE BEGIN 1 */ |
02 | #ifdef __GNUC__ |
03 | /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf |
04 | set to 'Yes') calls __io_putchar() */ |
05 | #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) |
06 | #else |
07 | #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) |
08 | #endif /* __GNUC__ */ |
09 | /** |
10 | * @brief Retargets the C library printf function to the USART. |
11 | * @param None |
12 | * @retval None |
13 | */ |
14 | PUTCHAR_PROTOTYPE |
15 | { |
16 | /* Place your implementation of fputc here */ |
17 | /* e.g. write a character to the EVAL_COM1 and Loop until the end of transmission */ |
18 | HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF); |
19 |
20 | return ch; |
21 | } |
22 | /* USER CODE END 1 */ |
01 | /* USER CODE BEGIN 2 */ |
02 | printf("\n\r UART Printf Example: retarget the C library printf function to the UART\n\r"); |
03 | /* USER CODE END 2 */ |
04 |
05 | /* Infinite loop */ |
06 | /* USER CODE BEGIN WHILE */ |
07 | while (1) |
08 | { |
09 | /* USER CODE END WHILE */ |
10 |
11 | /* USER CODE BEGIN 3 */ |
12 | printf("\n\r welcome to www.waveshere.com !!!\n\r"); |
13 | HAL_Delay(1000); |
14 | } |
15 | /* USER CODE END 3 */ |
1 | /* Private variables ---------------------------------------------------------*/ |
2 |
3 | /* USER CODE BEGIN PV */ |
4 | /* Private variables ---------------------------------------------------------*/ |
5 | uint8_t aTxStartMessage[] = "\r\n****UART-Hyperterminal communication based on IT ****\r\nEnter 10 characters using keyboard :\r\n"; |
6 |
7 | /* Buffer used for reception */ |
8 | uint8_t aRxBuffer[20]; |
9 | /* USER CODE END PV */ |
1 | /* USER CODE BEGIN 2 */ |
2 | HAL_UART_Transmit_IT(&huart1, (uint8_t *)aTxStartMessage, sizeof(aTxStartMessage)); |
3 | HAL_UART_Receive_IT(&huart1, (uint8_t *)aRxBuffer, 10); |
4 | /* USER CODE END 2 */ |
01 | /* USER CODE BEGIN 4 */ |
02 | /** |
03 | * @brief Rx Transfer completed callbacks |
04 | * @param huart: uart handle |
05 | * @retval None |
06 | */ |
07 | void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) |
08 | { |
09 | /* Prevent unused argument(s) compilation warning */ |
10 | UNUSED(huart); |
11 |
12 | /* NOTE : This function should not be modified, when the callback is needed, |
13 | the HAL_UART_RxCpltCallback can be implemented in the user file |
14 | */ |
15 | HAL_UART_Transmit(&huart1, (uint8_t *)aRxBuffer, 10,0xFFFF); |
16 | } |
17 | /* USER CODE END 4 */ |
欢迎光临 (http://www.51hei.com/bbs/) | Powered by Discuz! X3.1 |