本帖最后由 lonkyzhang 于 2022-4-20 18:09 编辑
在官方库中没有smartcard的例程,我照着ST的方法写了一下初始化,使能了时钟,PB14 的RST复位信号用示波器可以看到,但PB12的CLK对应管脚一直没有时钟信号,一直是低电平。使用的GD32F303RCT6
代码如下,请教各位大神!感谢!
unsigned char Init_Card_Slot(unsigned char Init_Psam_Slot(unsigned char *Atr )
{
rcu_periph_clock_enable(RCU_GPIOB);
rcu_periph_clock_enable(RCU_USART2);
gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_13);//VCC PB13
gpio_init(GPIOB, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_14);//RST PB14
gpio_init(GPIOB, GPIO_MODE_AF_OD, GPIO_OSPEED_50MHZ, GPIO_PIN_10);//IO PB10 USART2 TX
gpio_init(GPIOB, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, GPIO_PIN_12);//CLK PB12 USART2 CK
gpio_bit_set(GPIOB, GPIO_PIN_13);//VCC = 1
//关闭失能
usart_deinit(USART2);
usart_disable(USART2);
usart_synchronous_clock_disable(USART2);
usart_transmit_config(USART2,USART_TRANSMIT_DISABLE);
usart_receive_config(USART2,USART_RECEIVE_DISABLE);
usart_hardware_flow_rts_config(USART2,USART_RTS_DISABLE);
usart_hardware_flow_cts_config(USART2,USART_CTS_DISABLE);
//配置传输格式
usart_word_length_set(USART2,USART_WL_9BIT);
usart_stop_bit_set(USART2,USART_STB_1_5BIT);
usart_parity_config(USART2,USART_PM_EVEN);
usart_transmit_config(USART2,USART_TRANSMIT_ENABLE);
usart_receive_config(USART2,USART_RECEIVE_ENABLE);
usart_synchronous_clock_config(USART2,USART_CLEN_NONE,USART_CPH_1CK,USART_CPL_LOW);
usart_baudrate_set(USART2,9600);
usart_guard_time_config(USART2,0x00);
//其他模式失能
usart_lin_mode_disable(USART2);
usart_halfduplex_disable(USART2);
usart_irda_mode_disable(USART2);
//开启USART2
usart_enable(USART2);
gpio_bit_reset(GPIOB, GPIO_PIN_14);//RST = 0
usart_smartcard_mode_nack_disable(USART2);
usart_smartcard_mode_enable(USART2);//使能智能卡模式
usart_synchronous_clock_enable(USART2);//使能时钟
usart_smartcard_autoretry_config(USART2,0);//不需要重发
delay_1ms(4);
gpio_bit_set(GPIOB, GPIO_PIN_14);//RST = 1
SMARTCARD_ATR_Receive(USART2,Atr,&len,300);
return len;
}
|