#include <USART3.h>
#include <stdio.h>
//重定义fputc函数
int fputc(int ch, FILE *f)
{
while((USART3->SR&0X40)==0);//循环发送,直到发送完毕
USART3->DR = (u8) ch;
return ch;
}
void USART3_Init(u32 bound)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
//开始GPIO和复用功能时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO,ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
//PB10->TX 配置为复用推挽式输出
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//PB11->RX 配置为浮空输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStr

该博客介绍了如何配置和初始化USART3接口,以便通过串口3与矩阵键盘进行通信。作者重定义了fputc函数以确保数据正确发送,并展示了在检测到按键按下时如何通过USART3输出按键编号。
最低0.47元/天 解锁文章
3776

被折叠的 条评论
为什么被折叠?



