芯片:STM32F103ZET6
当USART1接收到数据的时候就会进入中断,然后把接收到的数据通过UART5发出
中间没有数据处理,原汁原味的发送。
我使用的标准库完成的,接下来我将展示我的代码,希望可以帮到你
#include "stm32f10x.h"
#define USART1_DR_Base 0x40013804 // USART1数据寄存器地址
#define UART5_DR_Base 0x40005004 // UART5数据寄存器地址
// USART1初始化函数
void USART1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// 使能USART1和GPIOA的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
// 配置USART1的Tx引脚为复用推挽输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// 配置USART1的Rx引脚为浮空输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATIN