小杨同学

stm32 串口
#include <string.h> #include "stdio.h" ...
扫描右侧二维码阅读全文
18
2021/04

stm32 串口

#include <string.h>
#include "stdio.h"
    
//****printf 重定义*****//
#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif
// printf("hello!你好!\r\n");
PUTCHAR_PROTOTYPE
{
    HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);//注意把&huart1改为自己的stm32使用的串口号
    return ch;
}

函数流程图:
HAL_UART_Receive_IT(中断接收函数) ->
USART2_IRQHandler(void)(中断服务函数) ->
HAL_UART_IRQHandler(UART_HandleTypeDef *huart)(中断处理函数) ->
UART_Receive_IT(UART_HandleTypeDef *huart) (接收函数) ->
HAL_UART_RxCpltCallback(huart);(中断回调函数)

在这里插入图片描述

imgimg

Last modification:April 18th, 2021 at 08:29 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment