1. usart6.c

#include "usart6.h"


void My_USART6_Init(USART_TypeDef* USARTx,u32 bound)
{
	GPIO_InitTypeDef     GPIO_InitStructure;
	USART_InitTypeDef   USART_InitStructure;
	NVIC_InitTypeDef     NVIC_InitStructure;
	
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6,ENABLE);
		
	//GPIO
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
	GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
		
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7; 
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
	GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_Init(GPIOC,&GPIO_InitStructure);
			
	//USART
	USART_InitStructure.USART_BaudRate = bound;
	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(USARTx,&USART_InitStructure);
	

	
	//NVIC
	NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
	NVIC_Init(&NVIC_InitStructure);
	
		
	USART_DMACmd(USARTx, USART_DMAReq_Rx, ENABLE);	
	USART_DMACmd(USARTx, USART_DMAReq_Tx, ENABLE);	
	USART_ITConfig(USARTx, USART_IT_IDLE, ENABLE); 
	
	USART_Cmd(USARTx,ENABLE);	

}

2.usart6.h

#ifndef  __USART6_H
#define  __USART6_H
#include "sys.h"


void My_USART6_Init(USART_TypeDef* USARTx,u32 bound);


#endif


08-30 11:00