GPIO_InitTypeDef GPIO_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_APB2PeriphClockCmd(SC_USART_GPIO_CLK | RCC_APB2Periph_AFIO, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3,ENABLE);
/* Configure USART CK pin as alternate function push-pull */
GPIO_InitStructure.GPIO_Pin = SC_USART_PIN_CK;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(SC_USART_GPIO, &GPIO_InitStructure);
/* Configure USART Tx pin as alternate function open-drain */
GPIO_InitStructure.GPIO_Pin = SC_USART_PIN_TX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(SC_USART_GPIO, &GPIO_InitStructure);
/* Configure Smartcard Reset pin */
GPIO_InitStructure.GPIO_Pin = SC_PIN_RESET;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(SC_PIN_RESET_GPIO, &GPIO_InitStructure);
USART_SetPrescaler(SC_USART, 0x05);
USART_SetGuardTime(SC_USART, 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_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_Init(SC_USART, &USART_InitStructure);
USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
USART_ClockInit(SC_USART,&USART_ClockInitStructure);
/* Enable the SC_USART Parity Error Interrupt */
USART_ITConfig(SC_USART, USART_IT_PE, ENABLE);
/* Enable the SC_USART Framing Error Interrupt */
USART_ITConfig(SC_USART, USART_IT_ERR, ENABLE);
/* Enable SC_USART */
USART_Cmd(SC_USART, ENABLE);
/* Enable the NACK Transmission */
USART_SmartCardNACKCmd(SC_USART, ENABLE);
/* Enable the Smartcard Interface */
USART_SmartCardCmd(SC_USART, ENABLE);
这个是我的初始化, gpio口的
|