Ejemplo n.º 1
0
/**
  * @brief  Configure UART1 for the communication with HyperTerminal
  * @param  None
  * @retval None
  */
static void UART1_Config(void)
{
  /* EVAL COM (UART) configuration -----------------------------------------*/
  /* USART configured as follow:
        - BaudRate = 115200 baud  
        - Word Length = 8 Bits
        - One Stop Bit
        - Odd parity
        - Receive and transmit enabled
        - UART Clock disabled
  */
  UART1_Init((uint32_t)115200, UART1_WORDLENGTH_8D,UART1_STOPBITS_1, UART1_PARITY_ODD,
                   UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

  /* Enable the UART Receive interrupt: this interrupt is generated when the UART
    receive data register is not empty */
  UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
  
  /* Enable the UART Transmit complete interrupt: this interrupt is generated 
     when the UART transmit Shift Register is empty */
  UART1_ITConfig(UART1_IT_TXE, ENABLE);

  /* Enable UART */
  UART1_Cmd(ENABLE);
  
    /* Enable general interrupts */
  enableInterrupts();
}
Ejemplo n.º 2
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    /*High speed internal clock prescaler: 1*/
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Enable general interrupts */
    enableInterrupts();

    /* Deinitializes the UART1 and UART3 peripheral */
    UART1_DeInit();
    UART3_DeInit();
    /* UART1 and UART3 configuration -------------------------------------------------*/
    /* UART1 and UART3 configured as follow:
          - BaudRate = 9600 baud  
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - Receive and transmit enabled
          - UART1 Clock disabled
     */
    /* Configure the UART1 */
    UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

    /* Configure the UART3 */
 		UART3_Init((u32)9600, UART3_WORDLENGTH_8D, UART3_STOPBITS_1, UART3_PARITY_NO, UART3_MODE_TXRX_ENABLE);

    /* Enable UART3 Receive and UART1 Transmit interrupt */

    UART3_ITConfig(UART3_IT_RXNE_OR, ENABLE);
    UART1_ITConfig(UART1_IT_TXE, ENABLE);

    /* Wait until end of transmission from UART1 to UART3 */
    while (GetVar_RxCounter2() < GetVar_NbrOfDataToTransfer1())
    {
    }
    /* Enable UART1 Receive and UART3 Transmit interrupt */
    UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
    UART3_ITConfig(UART3_IT_TXE, ENABLE);
    /* Wait until end of transmission from UART3 to UART1 */
    while (GetVar_RxCounter1() < GetVar_NbrOfDataToTransfer2())
    {
    }

    /* Check the received data with the send ones */
    TransferStatus1 = Buffercmp(TxBuffer2, RxBuffer1, RxBufferSize1);
    /* TransferStatus1 = PASSED, if the data transmitted from UART3 and
       received by UART1 are the same */
    /* TransferStatus1 = FAILED, if the data transmitted from UART3 and
       received by UART1 are different */
    TransferStatus2 = Buffercmp(TxBuffer1, RxBuffer2, RxBufferSize2);
    /* TransferStatus2 = PASSED, if the data transmitted from UART1 and
       received by UART3 are the same */
    /* TransferStatus2 = FAILED, if the data transmitted from UART1 and
       received by UART3 are different */

    while (1);
}
Ejemplo n.º 3
0
void uart_send_str (unsigned char *SendData)
{
    uart_send=SendData;
    uart_send_length=uart_send_length_bk ;                    // Enable USCI_A0 TX interrupt
    UART1_SendData8(*uart_send);
    UART1_ITConfig(UART1_IT_TC,ENABLE  );
}
Ejemplo n.º 4
0
void USART1_INIT(void)
{
//	UART1_DeInit();
	UART1_Init(9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1,UART1_PARITY_NO,UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE );  
	UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);//UART1_IT_RXNE_OR    
	UART1->CR1 &= (uint8_t)(~UART1_CR1_UARTD); 
//	UART1_Cmd(ENABLE);  
	UART1_ClearFlag(UART1_FLAG_RXNE);
}
Ejemplo n.º 5
0
//串口UART1初始化
void Init_UART(void)
{
  //默认初始化
  UART1_DeInit();       
  //设置波特率9600 8位数据 1位停止位 无校验  外部时钟不可用 模式接收发送
  UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
  //设置接收寄存器溢出中断
  UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
}
Ejemplo n.º 6
0
/**********************************************
UART1  configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Receive and transmit enabled
-  Receive interrupt
- UART1 Clock disabled
*********************************************/
void Uart_Init(void)
{
    UART1_DeInit();
    UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, \
               UART1_PARITY_NO , UART1_SYNCMODE_CLOCK_DISABLE , UART1_MODE_TXRX_ENABLE);
    UART1_ITConfig(UART1_IT_RXNE_OR,ENABLE  );
    UART1_Cmd(ENABLE );

}
Ejemplo n.º 7
0
__interrupt void UART1_TX_IRQHandler(void)
{
    if(UART1->SR&BIT6)
    {
        if(--uart_send_length>0)   UART1_SendData8(*(++uart_send));
        else
        {
            UART1_ITConfig(UART1_IT_TC,DISABLE);                       // Disable USCI_A0 TX interrupt
            uart_busy=0;
        }
    }
}
Ejemplo n.º 8
0
/*******************************************************************************
 * 名称: Uart_Init
 * 功能: UART1初始化操作
 * 形参: 无
 * 返回: 无
 * 说明: 无 
 ******************************************************************************/
void Uart1_Init(void)
{
    UART1_DeInit();		/* 将寄存器的值复位 */
	
	/*
	 * 将UART1配置为:
	 * 波特率 = 115200
	 * 数据位 = 8
	 * 1位停止位
	 * 无校验位
	 * 使能接收和发送
	 * 使能接收中断
	 */
    UART1_Init((u32)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, \
    	UART1_PARITY_NO , UART1_SYNCMODE_CLOCK_DISABLE , UART1_MODE_TXRX_ENABLE);
    UART1_ITConfig(UART1_IT_RXNE_OR, ENABLE);
    UART1_Cmd(ENABLE);
}
Ejemplo n.º 9
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
    uint32_t i = 0;
    /* Configure the multiplexer on the evalboard to select the smartCard*/
    Multiplexer_EvalBoard_Config();

    /* Configure the GPIO ports */
    GPIO_Config();
    
    /*High speed internal clock prescaler: 1*/
    CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

    /* Enable general interrupts */
    enableInterrupts();

    UART1_DeInit();
    /* UART1 configuration -------------------------------------------------------*/
    /* UART1 configured as follow:
          - Word Length = 9 Bits
          - 1.5 Stop Bit
          - Even parity
          - BaudRate = 10752 baud
          - Receive and transmit enabled
          - UART1 Clock enabled
    */
  UART1_Init((uint32_t)10752, UART1_WORDLENGTH_9D, UART1_STOPBITS_1_5, UART1_PARITY_EVEN,
              UART1_SYNCMODE_CLOCK_ENABLE, UART1_MODE_TXRX_ENABLE);

    /* UART1 Clock set to 4MHz (frequence master 16 MHZ / 4) */
    UART1_SetPrescaler(0x02);

    /* UART1 Guard Time set to  Bit */
    UART1_SetGuardTime(0x2);

    /* Enable the UART1 Parity Error Interrupt */
    UART1_ITConfig(UART1_IT_PE, ENABLE);

    /* Enable the NACK Transmission */
    UART1_SmartCardNACKCmd(ENABLE);

    /* Enable the Smart Card Interface */
    UART1_SmartCardCmd(ENABLE);

    /* Loop while no smart card is detected */
    while ((GPIO_ReadInputData(GPIOE)& 0x01) == 0x00)
    {
    }
    
    /* PG7 - SmartCard_/CMDVCC: low */
    GPIO_WriteLow(GPIOG, GPIO_PIN_7);  

    /* release SmartCard_RESET signal */
    GPIO_WriteLow(GPIOG, GPIO_PIN_5);  

    for (i = 0; i < 6000; i++)
    {
    }
    /* set SmartCard_RESET signal */
    GPIO_WriteHigh(GPIOG, GPIO_PIN_5);  


    /* Read Smart Card ATR response */
    for (index = 0; index < 40; index++)
    {
        Counter = 0;
        while ((UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET) && (Counter != SC_Receive_Timeout))
        {
            Counter++;
        }

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

    /* 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 smart card is not ISO7816-3 T=0 compatible */
        ATRDecodeStatus = FAILED;
    }

    while (1)
  {}
}