#include "uart4.h"
void uart4_init()
{
//使能GPIO
RCC->MP_AHB4ENSETR |=(0x1<<1);
RCC->MP_AHB4ENSETR |=(0x1<<6);
//使能UART4
RCC->MP_APB1ENSETR |=(0x1<<16) ;
//GPIO MODER设置 复用模式设置
GPIOB->MODER |=(0x2<<4);
GPIOG->MODER |=(0x2<<22);
GPIOB->AFRH |=(0x8<<8);
GPIOG->AFRH |=(0x6<<12);
//UART设置
//UE
USART4->CR1 &=(~(0x1));
//8位数据位
USART4->CR1 &=(~(0x1<<12));
USART4->CR1 &=(~(0x1<<28));
//采样设置
USART4->CR1 &=(~(0x1<<15));
//校验位设置
USART4->CR1 &=(~(0x3<<10));
//数据发送 接收 使能uart4
USART4->CR1 |=(0x1<<3);
USART4->CR1 |=(0x1<<2);
USART4->CR1 |=(0x1<<0);
//停止位 时钟不分蘋
USART4->CR2 &=(~(0x3<<12));
USART4->PRESC &=(~(0xF));
//波特率设置
USART4->BRR =0x22B;
}
//消息接收
char msr_recv()
{
char a;
while(!(USART4->ISR &(0x1<<5)));
a=USART4->RDR;
return a;
}
void putchar(char a)
{
while(!(USART4->ISR&(0x1<<7)));
USART4->TDR=a;
while(!(USART4->ISR&(0x1<<6)));
}