这是个串口发射程序,
仿真没有问题,
开发板也没有问题,其他的程序能够使用,就是这个程序在电脑上看不到数据
#include<
STM32f10x_gpio.h>
#include<stm32f10x_rcc.h>
#include<stm32f10x_usart.h>
int main()
{
float DIV;
u16 M,F,BRR;
u32 BOUND;
u8 data='A';
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //使能APB2外设的GPIOA的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
GPIOA->CRH = 0X000004B0;
USART1->CR1 |= (1<<13);
USART1->CR1 &= ~(1<<12);
USART1->CR2 &= ~(3<<12);
USART1->CR1 |= (1<<3);
BOUND = 9600;
DIV = (float)(36*1000*1000)/(BOUND*16);
M = DIV;
F = (DIV-M)*16;
BRR = M<<4+F;
USART1->BRR = BRR;
// RCC->APB1RSTR|=1<<18; //复位串口3
// RCC->APB1RSTR&=~(1<<18);//停止复位
for(F=0;F<20;F++)
{
USART1->DR = data;
data++;
while((USART1->SR & (1<<6))==0);
}
}
for(F=0;F<20;F++)
{
USART1->DR = data;
data++;
while((USART1->SR & (1<<6))==0);
}
}
先弄个死循环一直发送,再看看寄存器 ((USART1->SR & (1<<6))==0)是不是应该是((USART1->SR & (1<<7))==0)
E:张晓瑞stm32
一周热门 更多>