我将USART2的模式配置成智能卡模式来与智能卡通信,用示波器检测到USART2_CK脚(PA4)无任何输出,请问在智能卡模式中,它是不是应该输出智能卡的时钟信号呀?怎么配置才正确呢?以下为配置代码,请用过的大侠帮忙: /******************************************************************************* * Function Name : SC_Init * Description : Initializes all peripheral used for Smartcard interface. * Input : None * Output : None * Return : None *******************************************************************************/ static void SC_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; /* Enable GPIOA, GPIOB and AFIO clocks */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE); /* Enable USART2 clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); /* Configure USART2 CK(PA.4) as alternate function push-pull */ GPIO_InitStructure.GPIO_Pin = SC_CLK; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Configure USART2 Tx (PA.2) as alternate function open-drain */ GPIO_InitStructure.GPIO_Pin = SC_IO; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD; GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure Smartcard Reset */ GPIO_InitStructure.GPIO_Pin = SC_RESET; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure Smartcard VCC */ GPIO_InitStructure.GPIO_Pin = SC_VCC; GPIO_Init(GPIOA, &GPIO_InitStructure); /* USART2 configuration ------------------------------------------------------*/
/* USART Clock set to 3.6 MHz (PCLK1 (36 MHZ) / 10) */ USART_SetPrescaler(USART2, 0x05); /* USART Guard Time set to 16 Bit */ //在智能卡中需要该功能,当保护时间过去后,发送完成标志才被置起。 USART_SetGuardTime(USART2, 16); USART_StructInit(&USART_InitStructure); USART_InitStructure.USART_BaudRate = 9677; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_1_5; USART_InitStructure.USART_Parity = USART_Parity_Even; USART_InitStructure.USART_Clock = USART_Clock_Enable; USART_Init(USART2, &USART_InitStructure);
/* Enable the USART2 Parity Error Interrupt */ USART_ITConfig(USART2, USART_IT_PE, ENABLE);
/* Enable the USART2 Framing Error Interrupt */ USART_ITConfig(USART2, USART_IT_ERR, ENABLE);
/* Enable USART2 */ USART_Cmd(USART2, ENABLE);
/* Enable the NACK Transmission */ USART_SmartCardNACKCmd(USART2, ENABLE);
/* Enable the Smartcard Interface */ USART_SmartCardCmd(USART2, ENABLE);
SC_Reset(Bit_RESET); //复位脚置低电平 SC_PowerCmd(ENABLE);
} |