说明一点,所用的SAM卡可以上很快的时钟,在其它CPU上测试过。
USART_SetPrescaler(SC_USART, 0x05);
只能设置成5分频,其它任何分频都无法正常通讯,无论是提高还是减小。我想提高智能卡的通讯时钟,加快和SAM卡通讯速度。下面是初始化的代码,看看改了USART_SetPrescaler(SC_USART, 0x05);(里面的0x05) 还需要设置哪里才行?
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(SC_USART_CLK, 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);
//
// /* Configure Smartcard 3/5V pin */
// GPIO_InitStructure.GPIO_Pin = SC_PIN_3_5V;
// GPIO_Init(SC_PIN_3_5V_GPIO, &GPIO_InitStructure);
//
// /* Configure Smartcard CMDVCC pin */
// GPIO_InitStructure.GPIO_Pin = SC_PIN_CMDVCC;
// GPIO_Init(SC_PIN_CMDVCC_GPIO, &GPIO_InitStructure);
/* Enable USART IRQ */
NVIC_InitStructure.NVIC_IRQChannel = SC_USART_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_Init(&NVIC_InitStructure);
/* USART Clock set to 3.6 MHz (PCLK1 (36 MHZ) / 10) */
USART_SetPrescaler(SC_USART, 0x05);
/* USART Guard Time set to 16 Bit */
// USART_SetGuardTime(SC_USART, 16);
USART_SetGuardTime(SC_USART, 4);//5 //保护时间值 (Guard time value)
USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
USART_ClockInit(SC_USART, &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 9677;
USART_InitStructure.USART_WordLength = USART_WordLength_9b;
USART_InitStructure.USART_StopBits = USART_StopBits_1_5;//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_ITConfig(SC_USART, USART_IT_PE, ENABLE);
USART_ITConfig(SC_USART, USART_IT_ERR, ENABLE);
USART_Cmd(SC_USART, ENABLE);
USART_SmartCardNACKCmd(SC_USART, ENABLE);
USART_SmartCardCmd(SC_USART, ENABLE);