Exemple #1
0
__interrupt void UART1_RX_IRQHandler(void)
{ 

  if(UART1_GetITStatus(UART1_IT_RXNE )!= RESET)  
  {
    UART1_ReceiveData8();
  }
}
Exemple #2
0
/*******************************************************************************
 * 名称: UART1_ReceiveByte
 * 功能: UART1接收一个字符
 * 形参: 无
 * 返回: 接收到的字符
 * 说明: 无 
 ******************************************************************************/
u8 UART1_ReceiveByte(void)
{
	u8 USART1_RX_BUF; 
	
	/* 等待接收完成 */
	while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
	  	;
	
	USART1_RX_BUF = UART1_ReceiveData8();
	
	return  USART1_RX_BUF;
}
Exemple #3
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
   /*High speed internal clock prescaler: 1*/
   CLK_HSIPrescalerConfig(CLK_PRESCALER_HSIDIV1);

   /* UART1 configuration -------------------------------------------------------*/
   /* UART1 configured as follow:
          - Word Length = 8 Bits
          - 1 Stop Bit
          - No parity
          - BaudRate = 9600 baud
          - UART1 Clock enabled
          - Polarity Low
          - Phase Middle
          - Last Bit enabled
          - Receive and transmit enabled
   */
  UART1_DeInit();
  
  UART1_Init((uint32_t)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, 
              (UART1_SyncMode_TypeDef)(UART1_SYNCMODE_CLOCK_ENABLE | UART1_SYNCMODE_CPOL_LOW |UART1_SYNCMODE_CPHA_MIDDLE |UART1_SYNCMODE_LASTBIT_ENABLE),
              UART1_MODE_TXRX_ENABLE);
  UART1_Cmd(DISABLE);

  /* SPI configuration */
  SPI_DeInit();
  /* Initialize SPI in Slave mode  */
  SPI_Init(SPI_FIRSTBIT_LSB, SPI_BAUDRATEPRESCALER_2, SPI_MODE_SLAVE, SPI_CLOCKPOLARITY_LOW,
           SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,(uint8_t)0x07);

  /* Enable the UART1*/
  UART1_Cmd(ENABLE);
  
	Delay(0xFFF);
  
	/* Enable the SPI*/
  SPI_Cmd(ENABLE);
  
    while (NbrOfDataToRead--)
    {
        /* Wait until end of transmit */
        while (SPI_GetFlagStatus(SPI_FLAG_TXE)== RESET)
        {
        }
        /* Write one byte in the SPI Transmit Data Register */
        SPI_SendData(TxBuffer2[TxCounter]);
        /* Write one byte in the UART1 Transmit Data Register */
        UART1_SendData8(TxBuffer1[TxCounter++]);
        /* Wait until end of transmit */
        while (UART1_GetFlagStatus(UART1_FLAG_TXE) == RESET)
        {
        }
        /* Wait the byte is entirely received by UART1 */
        while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer1 */
        RxBuffer1[RxCounter] = UART1_ReceiveData8();
        /* Wait the byte is entirely received by SPI */
        while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET)
        {
        }
        /* Store the received byte in the RxBuffer2 */
        RxBuffer2[RxCounter++] = SPI_ReceiveData();
    }

    /* Check the received data with the sent ones */
    TransferStatus1 = Buffercmp(TxBuffer1, RxBuffer2, TxBufferSize1);
    /* TransferStatus = PASSED, if the data transmitted from UART1 and received by SPI are the same */
    /* TransferStatus = FAILED, if the data transmitted from UART1 and received by SPI are different */
    TransferStatus2 = Buffercmp(TxBuffer2, RxBuffer1, TxBufferSize2);
    /* TransferStatus = PASSED, if the data transmitted from SPI and received by UART1 are the same */
    /* TransferStatus = FAILED, if the data transmitted from SPI and received by UART11 are different */

    while (1);
}
Exemple #4
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)
  {}
}
Exemple #5
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    /* Configures the Multiplexer on the evalboard to select the IrDA*/
    Multiplexer_EvalBoard_Config();

    /* Initialize I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN, GPIO_MODE_OUT_PP_HIGH_FAST);

    UART1_DeInit();
    /* UART1 configuration ----------------------------------------------------*/
    /* UART1 configured as follow:
          - Word Length = 8 Bits
          - One Stop Bit
          - No parity
          - BaudRate = 9600 baud
          - Tx and Rx enabled
          - UART1 Clock disabled
    */
    UART1_Init((u32)9600, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);

		/* Set Prescaler*/
    UART1_SetPrescaler(0x1);

    UART1_IrDAConfig(UART1_IRDAMODE_NORMAL);

    UART1_IrDACmd(ENABLE);
    while (1)
    {
        /* Wait until a byte is received */
        while (UART1_GetFlagStatus(UART1_FLAG_RXNE) == RESET)
        {
        }
        /* Read the received byte */
        ReceivedData = UART1_ReceiveData8();

        switch (ReceivedData)
        {
            /* Led connected to PH.0 (LED4) toggle */
        case UP:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_0);
            break;
            /* Led connected to PH.1 (LED3) toggle */
        case DOWN:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_1);
            break;
            /* Led connected to PH.2 (LED2) toggle */
        case LEFT:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_2);
            break;
            /* Led connected to PH.3 (LED1) toggle */
        case RIGHT:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_3);
            break;

        case SEL:
            GPIO_WriteReverse(GPIOH, GPIO_PIN_0|GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1);
            break;
        default:
            break;
        }
    }

}
__interrupt void UART1_RX_IRQHandler(void)
{
    unsigned char rxdbuft;
    if(UART1_GetITStatus(UART1_IT_RXNE )!= RESET)  //*接收中断(
    {
        rxdbuft=UART1_ReceiveData8();//*(USART1->DR);读取接收到的数据,当读完数据后自动取消RXNE的中断标志位
        comrecive1.comtime=0;
        switch (comrecive1.compra)
        {
        case 0:
            if(rxdbuft==0xfe) comrecive1.compra=1;
            break;
        case 1:
            if(rxdbuft>15)   comrecive1.compra=0;
            else
            {
                comrecive1.comlong= rxdbuft-1;
                comrecive1.compra=2;
                comrecive1.cominlong=0;
                comrecive1.comcrc=rxdbuft;

            }
            break;
        case 2:
            comrecive1.comdata[comrecive1.cominlong]=rxdbuft;
            if(++comrecive1.cominlong>= comrecive1.comlong)
            {

                if(comrecive1.comcrc == comrecive1.comdata[comrecive1.cominlong-1]);//(comrecive1.comdata[comrecive1.cominlong-2]<<1)) //   if( rxdbuft==0x43)
                {
                    if(comrecive1.comdata[2]==1)//取传感器信息
                    {
                        uart_send_cmd[0] = 0xfe;
                        uart_send_cmd[1] = 0x07;
                        uart_send_cmd[2] = 0x00;
                        uart_send_cmd[3] = 0x02;
                        uart_send_cmd[4] =0x01;
                        uart_send_cmd[5] =23;//配置块个数
                        uart_send_cmd[6] =48; // 传感器检测位置点
                        uart_send_cmd[7] =sum_verify(&uart_send_cmd[1],6);
                        uart_send_cmd[8] =0x45;
                        uart_send_length_bk=9;
                        uart_event=1;
                        uart_busy=1;
                    }
                    if(comrecive1.comdata[2]==2)//接收状态
                    {
                        uart_event=1;

                    }
                    if(comrecive1.comdata[2]==3)//接收处方
                    {
                        uart_send_cmd[0] = 0xfe;
                        uart_send_cmd[1] = 0x07;
                        uart_send_cmd[2] = 0x00;
                        uart_send_cmd[3] = 0x02;
                        uart_send_cmd[4] =0x03;
                        uart_send_cmd[5] =1;//
                        uart_send_cmd[6] =sum_verify(&uart_send_cmd[1],5);
                        uart_send_cmd[7] =0x45;
                        uart_send_length_bk=8;
                        uart_event=1;
                        uart_busy=1;

                    }
                }
                comrecive1.compra=0;

            }
            else    comrecive1.comcrc +=rxdbuft;
            break;
        default:
            break;
        }


    }
}