/** * @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); }
/********************************************** 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 ); }
//串口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); }
static void init_usart1(void) { UART1_DeInit(); /* 波特率 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_ITConfig(UART1_IT_RXNE_OR, ENABLE); // UART1_ClearITPendingBit(UART1_IT_RXNE); // 清理中断标志位 }
/******************************************************************************* * 名称: 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); }
/** * @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); UART1_DeInit(); /* UART1 configuration ------------------------------------------------------*/ /* UART1 configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Receive and transmit enabled - UART1 Clock disabled */ /* Configure UART1 */ UART1_Init((u32)115200, UART1_WORDLENGTH_8D, UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE); /* Output a message on Hyperterminal using printf function */ printf("\n\rUART1 Example :Retarget the C library printf function to the UART1\n\r"); while (1); }
/** * @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); }
/** * @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) {} }
/** * @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; } } }