程序UART1可以,不知道,为什么UART2就是不行,发送能进入发送中断,PA2和PA3就是没有数据出来
#define WR_UART_viIsr USART2_IRQHandler
#define WR_USART USART2
void WR_UART_vInit(void)
{
// GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/*
* USART2_TX -> PA2 , USART2_RX -> PA3
*/
/* Enable GPIOA clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2 ,ENABLE);
/*
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
*/
/* GPIO configuration for USART2 signals */
/* (1) Select AF mode (10) on PA2 and PA3 */
/* (2) AF1 for USART2 signals */
GPIOA->MODER = (GPIOA->MODER & ~(GPIO_MODER_MODER2|GPIO_MODER_MODER3))\
| (GPIO_MODER_MODER2_1 | GPIO_MODER_MODER3_1); /* (1) */
GPIOA->AFR[1] = (GPIOA->AFR[1] &~ (GPIO_AFRL_AFRL2 | GPIO_AFRL_AFRL3))\
| (1 << (2 * 4)) | (1 << (3 * 4)); /* (2) */
USART_InitStructure.USART_BaudRate = 9600;
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(WR_USART, &USART_InitStructure);
USART_ClearFlag(WR_USART,USART_FLAG_TC);
USART_ITConfig(WR_USART, USART_IT_RXNE, ENABLE);
USART_ITConfig(WR_USART, USART_IT_TXE, DISABLE);
WR_NVIC_Configuration();
USART_Cmd(WR_USART, ENABLE);
}
void WR_UART_viIsr(void) //interrupt 4 using 2 /* use registerbank 2 for interrupt */
{
if((WR_USART->ISR & USART_FLAG_RXNE) != (uint16_t)RESET)
{
WR_USART->ISR = (UInt16)~USART_FLAG_RXNE;
if(WR_RxIsFull())
{
RxSetOverFlow();
}
else
{
WR_Rx_Buf[WR_RxTail] = (UInt8)(WR_USART->RDR & (uint16_t)0x01FF);
WR_RxTail = RxNextPosit(WR_RxTail);
}
}
if((WR_USART->ISR & USART_FLAG_TXE) != (UInt16)RESET)
{
WR_USART->ISR = (UInt16)~USART_FLAG_TXE;
if(WR_TxHasData())
{
WR_USART->TDR = (WR_Tx_Buf[WR_TxHead] & (UInt16)0x01FF);
WR_TxHead = TxNextPosit(WR_TxHead);
TxResetIdle();
}
else
{
TxSetIdle();
USART_ITConfig(WR_USART, USART_IT_TXE, DISABLE);
}
}
//Òç³ö´¦Àí
if(USART_GetFlagStatus(WR_USART,USART_FLAG_ORE) != (UInt16)RESET)
{
USART_ClearFlag(WR_USART,USART_FLAG_ORE);
USART_ReceiveData(WR_USART);
}
}
UInt8 WR_send( UInt8 *ptr, UInt8 size )
{
//WR_UART_EnTx();
USART_ClearFlag(WR_USART,USART_FLAG_TC);
// if size is 0, means ptr is a null terminated string, caller wants me to find size by myself
if ( size == 0 )
{
while ( *(ptr++) ) size++;
ptr -= (size+1); // go back to original start position
}
if ( size == 0 )
{
return 0;
}
for( ;size--; )
{
WR_Tx_Buf[ WR_TxTail ] = *(ptr++);
WR_TxTail = TxNextPosit( WR_TxTail );
}
USART_ITConfig(WR_USART, USART_IT_TXE, ENABLE);
return 1;
}
WR_send( DataField, len );
总是有发送数据进入UART2中断,就是PA2没有数据出来
|