/*************uart5/RS485对外********************/
/* Enable UART clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART5, ENABLE);
/* Connect PXx to USARTx_Tx*/
GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);
/* Connect PXx to USARTx_Rx*/
GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5);
/* Configure USART Tx as alternate function */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Configure USART Rx as alternate function */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOD, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate = 9600;
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(UART5,&USART_InitStructure);
USART_ITConfig(UART5, USART_IT_RXNE, ENABLE);
// USART_ITConfig(UART5, USART_IT_TXE, ENABLE);
// /*---------USART5--DMA1_channel 4 --Stream7--TX configuration *********/
// DMA_DeInit(DMA1_Stream7);
// DMA_InitStructure.DMA_Channel = DMA_Channel_4;
// DMA_InitStructure.DMA_PeripheralBaseAddr = USART5_DR_Addr ;
// DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&UART5PC_Send_Buf;
// DMA_InitStructure.DMA_BufferSize = 128;
// DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
// DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
// DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;
// DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
// DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
// DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
// DMA_InitStructure.DMA_Priority = DMA_Priority_High;
// DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
// DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
// DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
// DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
// DMA_Init(DMA1_Stream7, &DMA_InitStructure);
// /* Enable DMA1_Stream7 */
// DMA_Cmd(DMA1_Stream3, ENABLE);
// /*DMA1 stream1--Tx interrupt enable*/
// DMA_ITConfig(DMA1_Stream7, DMA_IT_TC, ENABLE);
// /* Enable DMA */
// USART_DMACmd(UART5, USART_DMAReq_Tx, ENABLE);
/* Enable USART */
USART_Cmd(UART5, ENABLE);