用扫描枪扫描数据把数据发给STM32F1,但是现在STM32芯片我用示波器能看到RX管脚有数据来,不能进入中断。不知道哪里出了问题,希望有熟悉的帮我看看下面是串口初始化程序:
void Usart1_init(uint32_t pclk,uint32_t bound)
{
float temp;
uint16_t mantissa,fraction;
/*---------------------------------------------*/
temp = (float)(pclk*1000000)/(bound*16);
mantissa = temp;
fraction = (temp-mantissa)*16;
mantissa<<= 4;
mantissa += fraction;
/*---------------------------------------------*/
RCC->APB2ENR |= 1u<<14;
RCC->APB2ENR|=1<<14; //ʹÄÜ´®¿ÚʱÖÓ
RCC->APB2RSTR |= 1u<<14;
RCC->APB2RSTR &= ~(1u<<14);
/*---------------------------------------------*/
USART1->BRR = mantissa;
USART1->CR1 = 0x200c;
USART1->CR2 = 0x00;
USART1->CR3 = 0x00;
/*---------------------------------------------*/
//USART1->CR1 |= 1u<<8;
USART1->CR1 |= 1u<<5;
/*---------------------------------------------*/
NVIC->IP[37] = 0x70;
NVIC->ISER[1] = (uint32_t)0x01<<5;
// NVIC->ICER[1] = (uint32_t)0x01<<5;
}
下面是中断程序:
void USART1_IRQHandler(void)
{
volatile uint8_t revdata;
/*---------------------------------------------*/
revdata = USART1->SR;
revdata = USART1->DR;
//USART1->SR = 0;
if(USART1->SR&(1<<5))
{
if(SMQ_flag==1)
{
SMQReceive(revdata);
}
else
{
YtReceive(revdata);
}
}
} |