我想知道我想知道USART2初始化设置的时候有什么特殊的设置吗?为什么我和USART1相同的设置可是USART的STR寄存器中的REA一直不置位,导致我一直不能接收。。。初始化程序如下:
void USART2_init(void)
{
NVIC_InitPara NVIC_InitStructure;
/* Enable the USARTx Interrupt */
NVIC_InitStructure.NVIC_IRQ = USART2_IRQn; //ÖжÏÀàÐÍ
NVIC_InitStructure.NVIC_IRQPreemptPriority = 0; //ÖжÏÓÅÏȼ¶
NVIC_InitStructure.NVIC_IRQSubPriority = 0; //
NVIC_InitStructure.NVIC_IRQEnable = ENABLE;
NVIC_Init(&NVIC_InitStructure);
RCC_AHBPeriphClock_Enable( RCC_AHBPERIPH_GPIOA , ENABLE ); //ʹÄÜGPIOAʱÖÓ
RCC_APB1PeriphClock_Enable( RCC_APB1PERIPH_USART2, ENABLE ); /* Enable USART1 APB clock */
// GPIO_DeInit( GPIOA ); //UART1 ÅäÖÃ
{/*************** usart2 ¶Ë¿ÚÉèÖÃ*****************/
GPIO_InitPara GPIO_InitStructure1;
GPIO_PinAFConfig( GPIOA , GPIO_PINSOURCE2, GPIO_AF_1 );
GPIO_PinAFConfig( GPIOA , GPIO_PINSOURCE3, GPIO_AF_1 ); /** usart1 **/
GPIO_InitStructure1.GPIO_Pin = GPIO_PIN_2 | GPIO_PIN_3;
GPIO_InitStructure1.GPIO_Mode = GPIO_MODE_AF;
GPIO_InitStructure1.GPIO_Speed = GPIO_SPEED_50MHZ;
GPIO_InitStructure1.GPIO_OType = GPIO_OTYPE_PP;
GPIO_InitStructure1.GPIO_PuPd = GPIO_PUPD_NOPULL;
GPIO_Init( GPIOA , &GPIO_InitStructure1);
}
{
USART_InitPara USART_InitStructure;
USART_DeInit( USART2 );
USART_InitStructure.USART_BRR = 115200;
USART_InitStructure.USART_WL = USART_WL_8B;
USART_InitStructure.USART_STBits = USART_STBITS_1;
USART_InitStructure.USART_Parity = USART_PARITY_RESET;
USART_InitStructure.USART_HardwareFlowControl = USART_HARDWAREFLOWCONTROL_NONE; //Ó²¼þ¿ØÖÆÎÞ
USART_InitStructure.USART_RxorTx = USART_RXORTX_RX | USART_RXORTX_TX;
USART_Init(USART2, &USART_InitStructure);
}
USART_Enable(USART2, ENABLE);
}
|