新手入门
- 积分
- 29
- 金钱
- 29
- 注册时间
- 2015-11-9
- 在线时间
- 1 小时
|
5金钱
我是STM32初学者,想从寄存器版本开始学 ,这是我自己敲的关于串口实验的串口配置函数,可是不管怎么调,都接收不到数据,确切的说连串口中断都没有进去(我用LED的亮灭 来判断的)不知道是哪儿出了问题 还望大家可以帮助一下。(没有考虑操作系统)
#include "usart.h"
#include "led.h"
void uart_init(u32 plck2,u32 bound)
{
float temp;
u16 mantissa;
u16 fraction;
temp=(plck2*1000000)/(bound*16);
mantissa=temp;
fraction=(temp-mantissa)*16;
mantissa=mantissa<<4;
mantissa=mantissa+fraction;
RCC->APB2ENR|=1<<2;
RCC->APB2ENR|=1<<14;
GPIOA->CRH&=0XFFFFF00F;
GPIOA->CRH|=0X000008B0;
RCC->APB2RSTR|=1<<14;
RCC->APB2RSTR|=0<<14;
USART1->BRR=mantissa;
USART1->CR1|=0X200C;
#if EN_USART1_RX
USART1->CR1|=1<<8;
USART1->CR1|=1<<5;
MY_NVIC_Init(3,3,USART1_IRQn,2);
#endif
}
void USART1_IRQHandler(void)
{
u8 res;
LED0=0;
if(USART1->SR&(1<<5))
{
LED1=0;
res=USART1->DR;
USART1->DR=res;
}
}
|
|