初级会员

- 积分
- 108
- 金钱
- 108
- 注册时间
- 2012-2-19
- 在线时间
- 22 小时
|
5金钱
#include "sys.h"
#include "usart.h"
#include "delay.h"
void uart3_init(u32 pclk1,u32 bound)
{
float temp;
u16 mantissa;
u16 fraction;
temp=(float)(pclk1*1000000)/(bound*16);//得到USARTDIV
mantissa=temp; //得到整数部分
fraction=(temp-mantissa)*16; //得到小数部分
mantissa<<=4;
mantissa+=fraction;
RCC->APB2ENR|=1<<3; //使能PORTB口时钟
// GPIOB->CRH&=0XFFFFFF0F; //IO状态设置
// GPIOB->CRH|=0X00000030; //IO状态设置
GPIOB->CRH&=0XFFFF00FF; //IO状态设置
GPIOB->CRH|=0X00008B00; //IO状态设置
RCC->APB1ENR|=1<<18; //使能串口时钟
RCC->APB1RSTR|=1<<18; //复位串口2
RCC->APB1RSTR&=~(1<<18);//停止复位
//波特率设置
USART3->BRR=mantissa; // 波特率设置
USART3->CR1|=0X200C; //1位停止,无校验位.
}
int main(void)
{
Stm32_Clock_Init(9);//系统时钟设置
delay_init(72); //延时初始化
uart3_init(36,9600);
while(1)
{
USART3->DR=0x51;
while((USART3->SR&0X40)==0);
}
应该没有问题呀
|
|