本帖最后由 myfaith 于 2010-8-26 10:41 编辑
真的嘞,搞的我很纳闷.这是你家ST的鬼闹的. 如图和程序,上电时候,明明程序中只允许了TC,RXNE中断,其它全部关闭,但是还是会进入中断(TXE不能直接清除,所以进入中断就必定进入TXE服务部分.) 如果不加程序中蓝色部分的延时,则会进入
if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET)
{
USART1_RX_ISR();
}
这里面去,搞不懂呃.
如图,上电时候:
初始化如下:
/* Configure USART Tx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = COM_TX_PIN[COM];
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(COM_TX_PORT[COM], &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Pin = COM_RX_PIN[COM];
GPIO_Init(COM_RX_PORT[COM], &GPIO_InitStructure);
for(uint32_t k =0xff;k>0;k--); //如果不加这,则上电会进入RXNE服务,加上则不会
/* USART configuration */
USART_InitStructure.USART_BaudRate = BAUDRATE;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(COM_USART[COM], USART_InitStruct);
//0:SBK,1:RWU,4:IDLEIE,6:TCIE,7:TXEIE,11:WAKE
USART1->CR1 &= (~((1<<0)|(1<<1)|(1<<4)|(1<<6)|(1<<7)|(1<<11)));
//USART1->CR2 &= (~(1<<6)); //6:LBOIE
USART1->CR2 = 0;
USART1->CR3 = 0;
USART1->CR3 |= (1<<7);//DMA enable transmitter
tmp = USART1->SR;
tmp = USART1->DR;
USART1->SR = 0;
USART1->CR1 |= ((1<<5)|(1<<13)); //RXNEIE,TCIE,UE
// USART1->SR &= ~(1<<5);
/* Enable USART */
USART_Cmd(COM_USART[COM], ENABLE);
//串口中断
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
|