#include "uart1.h" uint8_t TxBufferUart[256] = { 0 }; uint8_t RxBufferUart[256] = { 0 }; __IO uint8_t TxCounterUart = 0x00; __IO uint8_t RxCounterUart = 0x00; uint8_t UartSendCount = 0; /******************************************************************************* * Function Name : USART_Configuration * Description : Configure USART1 * Input : None * Output : None * Return : None * Attention : None *******************************************************************************/ void ConfigurationUsart1 ( void ) { #if UART1_SD_def GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; //使能USART1/GPIO 时钟可配置 Wifi_RCC_GPIO_CONFIG(); Wifi_RCC_UART_CONFIG(); /* * USART1_TX -> PA9 , USART1_RX -> PA10 */ GPIO_InitStructure.GPIO_Pin = Wifi_Tx; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init ( Wifi_GPIO, &GPIO_InitStructure ); GPIO_InitStructure.GPIO_Pin = Wifi_Rx; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_Init ( Wifi_GPIO, &GPIO_InitStructure ); USART_InitStructure.USART_BaudRate = Wifi_UART_BAUD; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init ( Wifi_UART, &USART_InitStructure ); //USART_ITConfig ( Wifi_UART, USART_IT_RXNE, ENABLE ); //USART_ITConfig ( Wifi_UART, USART_IT_TXE, DISABLE ); USART_Cmd ( Wifi_UART, ENABLE ); #endif } //系统中断管理 #if 0 void NVIC_ConfigurationUSART1 ( void ) { NVIC_InitTypeDef NVIC_InitStructure; /* Configure the NVIC Preemption Priority Bits */ NVIC_PriorityGroupConfig ( Wifi_NVIC_Group ); /* Enable the USARTy Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = Wifi_NVIC_Interrupt; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = Wifi_NVIC_Pre; NVIC_InitStructure.NVIC_IRQChannelSubPriority = Wifi_NVIC_Sub; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init ( &NVIC_InitStructure ); } #endif void UartSend ( char *buffer, int nBytes ) { // Wait for previous xmt to complete while ( TxCounterUart < UartSendCount ); // Setup next XMT memcpy ( TxBufferUart, buffer, nBytes ); TxCounterUart = 0; UartSendCount = nBytes; USART_ITConfig ( USART1, USART_IT_TXE, ENABLE ); }