题目:
.完成串口收发一个字符,上传CSDN,实验现象截图
.完成串口收发一个字符串,上传CSDN,实验现象截图
头文件
#ifndef __UART4_H__
#define __UART4_H__
#include "stm32mp1xx_rcc.h"
#include "stm32mp1xx_gpio.h"
#include "stm32mp1xx_uart.h"
//初始化函数
void hal_uart_init();
//发送一个字符
void put_char(const char str);
//接收一个字符
char get_char();
//发送一个字符串
void put_string(const char *str);
//接收一个字符串
char *get_string();
#endif
源文件
#include "uart4.h"
void hal_uart_init()
{
RCC->MP_AHB4ENSETR |= (0x1 << 1); // RCC->MP_AHB4ENSETR[1]=1
RCC->MP_AHB4ENSETR |= (0x1 << 6); // RCC->MP_AHB4ENSETR[6]=1
RCC->MP_APB1ENSETR |= (0x1 << 16); // RCC->MP_APB1ENSETR[16]=1
//GPIO 相关寄存器初始化
GPIOB->MODER &= (~(0x3 << 4));
GPIOB->MODER |= (0x2 << 4);GPIOG->MODER &=(~(0x3 << 22));
GPIOG->MODER |=(0x2 << 22);GPIOB->AFRL &= (~(0xf << 8));
GPIOB->AFRL |= (0x8 << 8);GPIOB->AFRH &= (~(0xf << 12));
GPIOB->AFRH |= (0x6 << 12);
if (USART4->CR1 & (0x1 << 0))
{
USART4->CR1 &= (~(0x1 << 0));
}USART4->CR1 &= (~(0x1 <