ST意法半导体
直播中

vinww特烦恼

8年用户 1130经验值
擅长:存储技术
私信 关注
[问答]

如何将STM32F4与智能卡ISO7816连接起来?

大家好你们好。我的任务是将 STM32F4 发现板与智能卡 ISO7816 连接起来。我不使用接口 ST8024CDR 仅通过图像中指定的方案直接挂钩支付:
我尝试将 Cubex 项目改编为 STM32F1xx-EVAL。ATR 接收不工作。示波器显示地图上的 I/O 端口类似于锯齿信号,但更平坦(在三个不同的地图上是不同的)。所以我想它仍然是 ATR。

UART和频率的配置:
  • void SystemClock_Config(void)
  • {
  •   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  •   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  •   /** Configure the main internal regulator output voltage
  •   */
  •   __HAL_RCC_PWR_CLK_ENABLE();
  •   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  •   /** Initializes the CPU, AHB and APB busses clocks
  •   */
  •   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  •   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  •   RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
  •   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  •   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  •   RCC_OscInitStruct.PLL.PLLM = 8;
  •   RCC_OscInitStruct.PLL.PLLN = 168;
  •   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  •   RCC_OscInitStruct.PLL.PLLQ = 4;
  •   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  •   {
  •     Error_Handler();
  •   }
  •   /** Initializes the CPU, AHB and APB busses clocks
  •   */
  •   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  •                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  •   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  •   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  •   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  •   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  •   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  •   {
  •     Error_Handler();
  •   }
  • }
  • static void MX_USART1_SMARTCARD_Init(void){
  •   /* USER CODE BEGIN USART1_Init 0 */
  •         __HAL_RCC_USART1_CLK_ENABLE();
  •   /* USER CODE END USART1_Init 0 */
  •   /* USER CODE BEGIN USART1_Init 1 */
  •         /* USART Clock set to 3,5 MHz (PCLK2 (84 MHz) / 24) */
  •   /* USER CODE END USART1_Init 1 */
  •   SmartCardHandle.Instance = USART1;
  •   SmartCardHandle.Init.BaudRate = 9408;         /* Starting baudrate = 3,5MHz / 372etu */
  •   SmartCardHandle.Init.WordLength = SMARTCARD_WORDLENGTH_9B;
  •   SmartCardHandle.Init.StopBits = SMARTCARD_STOPBITS_1_5;
  •   SmartCardHandle.Init.Parity = SMARTCARD_PARITY_EVEN;
  •   SmartCardHandle.Init.Mode = SMARTCARD_MODE_TX_RX;
  •   SmartCardHandle.Init.CLKPolarity = SMARTCARD_POLARITY_LOW;
  •   SmartCardHandle.Init.CLKPhase = SMARTCARD_PHASE_1EDGE;
  •   SmartCardHandle.Init.CLKLastBit = SMARTCARD_LASTBIT_DISABLE;
  •   SmartCardHandle.Init.Prescaler = 12;
  •   SmartCardHandle.Init.GuardTime = 16;
  •   SmartCardHandle.Init.NACKState = SMARTCARD_NACK_DISABLE;
  •   if (HAL_SMARTCARD_Init(&SmartCardHandle) != HAL_OK)
  •   {
  •     Error_Handler();
  •   }
  •         __HAL_SMARTCARD_ENABLE(&SmartCardHandle);
  •   /* USER CODE BEGIN USART1_Init 2 */
  •         HAL_SMARTCARD_Init(&SmartCardHandle);
  •         SC_RESET(GPIO_PIN_SET);
  •   /* USER CODE END USART1_Init 2 */
  • }
  • void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef* hsmartcard)
  • {
  •   GPIO_InitTypeDef GPIO_InitStruct = {0};
  •   if(hsmartcard->Instance==USART1)
  •   {
  •   /* USER CODE BEGIN USART1_MspInit 0 */
  •   /* USER CODE END USART1_MspInit 0 */
  •     /* Peripheral clock enable */
  •     __HAL_RCC_USART1_CLK_ENABLE();
  •     __HAL_RCC_GPIOA_CLK_ENABLE();
  •     /**USART1 GPIO Configuration
  •     PA8     ------> USART1_CK
  •     PA9     ------> USART1_TX
  •     */
  •     GPIO_InitStruct.Pin = GPIO_PIN_8;
  •     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
  •     GPIO_InitStruct.Pull = GPIO_PULLUP;
  •     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  •     GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  •     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  •     GPIO_InitStruct.Pin = GPIO_PIN_9;
  •     GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
  •     GPIO_InitStruct.Pull = GPIO_PULLUP;
  •     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
  •     GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
  •     HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  •     /* USART1 interrupt Init */
  •     HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
  •     HAL_NVIC_EnableIRQ(USART1_IRQn);
  •   /* USER CODE BEGIN USART1_MspInit 1 */
  •   /* USER CODE END USART1_MspInit 1 */
  •   }
  • }
尝试直接阅读:
  • HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_RESET);
  • HAL_Delay(500);
  • HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
  • convention=HAL_SMARTCARD_Receive(&SmartCardHandle, atr_buff, atr_size, 500);
  • HAL_Delay(12);
  • /* Insert delay of 20ms for signal stabilization */
  • HAL_GPIO_WritePin(GPIOD, GPIO_PIN_15, GPIO_PIN_SET);
  • HAL_Delay(300);
PD15 - 重置。
我总是得到零。可能是什么问题呢?




回帖(1)

杨林

2022-12-15 11:51:41
我使用 USART3 而不是 USART1,一切都被认为是成功的。
举报

更多回帖

发帖
×
20
完善资料,
赚取积分