Пример #1
0
/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* System Clocks Configuration */
  RCC_Configuration();
       
  /* NVIC configuration */
  NVIC_Configuration();

  /* Configure the GPIO ports */
  GPIO_Configuration();

  /* Configure the EXTI Controller */
  EXTI_Configuration();


/* SC_USART configuration ----------------------------------------------------*/
  /* SC_USART configured as follow:
        - Word Length = 9 Bits
        - 0.5 Stop Bit
        - Even parity
        - BaudRate = 12096 baud
        - Hardware flow control disabled (RTS and CTS signals)
        - Tx and Rx enabled
        - USART Clock enabled
        - USART CPOL Low
        - USART CPHA on first edge
        - USART Last Bit Clock Enabled
  */

  /* SC_USART Clock set to 4.5MHz (PCLK1 = 36 MHZ / 8) */
  USART_SetPrescaler(SC_USART, 0x04);
  /* SC_USART Guard Time set to 2 Bit */
  USART_SetGuardTime(SC_USART, 0x2);
  
  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 = 12096;
  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);  

  /* Enable the SC_USART Parity Error Interrupt */
  USART_ITConfig(SC_USART, USART_IT_PE, 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);

  /* Loop while no Smartcard is detected */  
  while(CardInserted == 0)
  {
  }

  /* Read Smartcard ATR response */ 
  for(index = 0; index < 40; index++, Counter = 0)
  {
    while((USART_GetFlagStatus(SC_USART, USART_FLAG_RXNE) == RESET) && (Counter != SC_Receive_Timeout))
    {
      Counter++;
    }

    if(Counter != SC_Receive_Timeout)
    {
      DST_Buffer[index] = USART_ReceiveData(SC_USART);
    }
  }

  /* Decode ATR */
  CardProtocol = SC_decode_Answer2reset(DST_Buffer);

  /* Test if the inserted card is ISO7816-3 T=0 compatible */
  if(CardProtocol == 0)
  {
    /* Inserted card is ISO7816-3 T=0 compatible */
    ATRDecodeStatus = PASSED;
  }
  else 
  { 
    /* Inserted Smartcard is not ISO7816-3 T=0 compatible */
    ATRDecodeStatus = FAILED;
  } 

  while (1)
  {   
  }
}
Пример #2
0
/******************************************************************************
 * USART1 Initialization Code Template
******************************************************************************/
void USART1__Init()
{
    USART_InitTypeDef USART_InitStruct;
    
    #if (STRCMP($modeSelect$, USART_MODE_SYNCHRONOUS) == 1)
    //PUT_A_NEW_LINE_HERE
    USART_ClockInitTypeDef USART_ClockInitStruct;
    #endif
    
    #if (!STRCMP($USARTIntSet$, 0))
    NVIC_InitTypeDef NVIC_InitStructure;
	#endif
	
    //PUT_A_NEW_LINE_HERE
    //
    // Enable peripheral clock of USART1 and GPIOA
    //
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
   
    //PUT_A_NEW_LINE_HERE	
    //
    // USART Config
    //	
    USART_InitStruct.USART_BaudRate = $baudRate$;
    USART_InitStruct.USART_WordLength = $dataBits$;
    USART_InitStruct.USART_StopBits = $stopBits$;
    USART_InitStruct.USART_Parity = $parityBits$;
    USART_InitStruct.USART_Mode = $modeSet$;
    USART_InitStruct.USART_HardwareFlowControl = $HardwareFlowControl$;
    USART_Init(USART1, &USART_InitStruct);  
  
    #if ($guardTime$ != 0)
    //PUT_A_NEW_LINE_HERE	
    //
    // Set Guard Time
    //
    USART_SetGuardTime(USART1, $guardTime$);
    #endif
	
    //PUT_A_NEW_LINE_HERE
    USART_WakeUpConfig(USART1, $WakeUpmethod$);
	
    //PUT_A_NEW_LINE_HERE	
    #if (STRCMP($modeSelect$, USART_MODE_NORMAL) == 1)
    
    #elif (STRCMP($modeSelect$, USART_MODE_IRDA) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    //USART IrDA  Mode Config
    //
    USART_IrDAConfig(USART1, $IrDAModeSel$);
    USART_IrDACmd(USART1, ENABLE);
    
    #elif (STRCMP($modeSelect$, USART_MODE_DMA) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    //USART DMA Mode Config
    //
    USART_DMACmd(USART1, $DMAReq$, ENABLE);
	
    #elif (STRCMP($modeSelect$, USART_MODE_SYNCHRONOUS) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // USART Synchronous Mode Config
    //
    USART_Clock_InitStruct.USART_Clock = USART_CLOCK_ENABLE;
    USART_Clock_InitStruct.USART_CPOL = $synClockPolSet$;
    USART_Clock_InitStruct.USART_CPHA = $synClockPhaseSet$;
    USART_Clock_InitStruct.USART_LastBit = $lastbitenable$;
    USART_ClockInit(USART1, &USART_Clock_InitStruct);
	
    #elif (STRCMP($modeSelect$, USART_MODE_LIN) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // USART LIN Mode Config
    //
    USART_LINBreakDetectLengthConfig(USART1, $LINBreakDetectLen$);
    USART_LINCmd(USART1, ENABLE);
	
    #elif (STRCMP($modeSelect$, USART_MODE_SMARTCARD) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // USART SmartCard Mode Config
    //
    USART_SmartCardCmd(USART1, ENABLE);
    #elif (STRCMP($NACKTrans$, ENABLE) == 1)
    //PUT_A_NEW_LINE_HERE
    USART_SmartCardNACKCmd(USART1, ENABLE);
	
    #elif (STRCMP($modeSelect$, USART_MODE_HALFDUPLEX) == 1)
    //PUT_A_NEW_LINE_HERE
    //
    // USART HalfDuplex Mode Config
    //
    USART_HalfDuplexCmd(USART1, ENABLE);	
    #endif
    
    
    #if (!STRCMP($USARTIntSet$, 0))
    //PUT_A_NEW_LINE_HERE
    //
    // Enable the USART Interrupt Function 
    //
    USART_ITConfig(USART1, $USARTIntSet$, ENABLE);
    NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
    #endif
}