0
\$\begingroup\$

After get ATR and send PTS, I tried send APDU, but response always the same as APDU which has been sent.
I tried to change the frequency for USART (clock) and baud rate, after I tried to change PTS value for ETU and T=0, but always same result.

enter image description here

Schematic:
enter image description here

Answer from Smart Card:
enter image description here

main code:

int main(void)
{
    /* USER CODE BEGIN 1 */

    /* USER CODE END 1 */

    /* MCU Configuration--------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
    HAL_Init();

    /* USER CODE BEGIN Init */
    // uint8_t res2[8] ={0x80,0xCA,0x9F,0x17,0x00};
    /* USER CODE END Init */

    /* Configure the system clock */
    SystemClock_Config();

    /* USER CODE BEGIN SysInit */

    /* USER CODE END SysInit */

    /* Initialize all configured peripherals */
    MX_GPIO_Init();
    MX_USART2_UART_Init();
    MX_USART1_SMARTCARD_Init();
    /* USER CODE BEGIN 2 */
    /* USER CODE END 2 */
    uint8_t response[50];
    /* Infinite loop */
    /* USER CODE BEGIN WHILE */
    HAL_StatusTypeDef convention;
    uint8_t h = 97;
    uint8_t first_request[10] = {0xA0,0xA4 ,0x00 ,0x00,0x02,0x00,0x00,0x00,0x00,0x00};
    uint8_t second[4] = {0x7F,0x00,0x00,0x00};
    uint8_t second2[5] = {0x00,0xB0,0x00,0x00,0x07};
    for(int i=0;i<50;i++)
    {
        response[i] = 0x00;
    }
    uint8_t response2[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
    uint8_t send[6] = {0xFF, 0x00,0xFF,0x00,0x00,0x00};

    HAL_UART_Receive_IT(&huart2, response,1);

    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, 0);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 0);
    HAL_Delay(100);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_13, 1);

    //  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_14, 1);
    HAL_Delay(15);
    HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, 1);
    HAL_SMARTCARD_Receive(&hsc1, response, 30, 100);
    HAL_UART_Transmit(&huart2, response, 24, 100);
    for(int i=0;i<50;i++)
    {
        response[i] = 0x00;
    }
    HAL_Delay(20);
    HAL_UART_Transmit(&huart2, send, 6, 100);
    HAL_SMARTCARD_Transmit(&hsc1, send, 4,100);
    HAL_SMARTCARD_Receive(&hsc1, response, 30, 100);
    HAL_UART_Transmit(&huart2, response, 8, 100);

    HAL_UART_Transmit(&huart2, first_request, 8, 100);
    for(int i=0;i<50;i++)
    {
        response[i] = 0x00;
    }
    HAL_SMARTCARD_Transmit(&hsc1, first_request, 5,100);
    HAL_SMARTCARD_Receive(&hsc1, response, 30, 100);
    HAL_UART_Transmit(&huart2, response, 5, 100);
    HAL_SMARTCARD_Transmit(&hsc1, second, 2,100);
    HAL_SMARTCARD_Receive(&hsc1, response2, 30, 100);
    HAL_UART_Transmit(&huart2, second, 4, 100);
    HAL_UART_Transmit(&huart2,response2,5,100);
    while (1)
    {

    }
    /* USER CODE END 3 */
}
\$\endgroup\$
4
  • \$\begingroup\$ So what kind of hardware and connections you have between STM32 and the smart card? \$\endgroup\$
    – Justme
    Feb 22 at 14:45
  • \$\begingroup\$ stm32 it direct connection to smart card, PA9(USART1_TX) and PA8(USART_CK) soldered to I/O(7-pin) and CLK(3-pin) from smart card and send/recive hex value via HAL_SMARTCARD_Transmit()/HAL_SMARTCARD_Receive() \$\endgroup\$
    – SAP4K
    Feb 22 at 16:14
  • \$\begingroup\$ So no power supply for the card? No pull-up for open-drain bi-dir comms? Show the schematics, the problem may not even be in the code. \$\endgroup\$
    – Justme
    Feb 22 at 16:39
  • \$\begingroup\$ I edited my question, PB12 and PB13 will be set on high level. after i get ATR from smart card. If you need other details, please ask me. \$\endgroup\$
    – SAP4K
    Feb 22 at 17:30

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.