Chinaunix首页 | 论坛 | 博客
  • 博客访问: 121724
  • 博文数量: 29
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2014-12-18 18:29
文章分类

全部博文(29)

文章存档

2016年(1)

2015年(24)

2014年(4)

我的朋友

分类: 嵌入式

2015-08-15 09:10:14

void Usart1_Test()
{

int bound=9600;


GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
USART_ClockInitTypeDef  USART_ClockInitStructure;


RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //??usart2 ??
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //??GPIOA??



GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);


//USART_DeInit(USART1);  //????2


#if 1
//USART_ClockInitTypeDef  USART_ClockInitStructure;
USART_ClockInitStructure.USART_Clock = USART_Clock_Disable;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_2Edge;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Disable;


/* Configure the USART2 synchronous paramters */
USART_ClockInit(USART1, &USART_ClockInitStructure);
#endif
//USART2_TX   PA2
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA.2
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; //40M
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //??????
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure); //???GPIOA.2


//USART2_RX  PA.3
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
//GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//????被这坑了一天
//GPIO_InitStructure.GPIO_PuPd= GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);  //???PA.3


//USART2 ???
USART_InitStructure.USART_BaudRate = bound;//??????9600
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//???8?????
USART_InitStructure.USART_StopBits = USART_StopBits_1; // 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(USART1, &USART_InitStructure);// ?????
// EN_USART1_RX  //????
//Usart2 NVIC ??
#if 1
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2 ;// ????? 3
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4; //???? 3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ ????
NVIC_Init(&NVIC_InitStructure); // ??? VIC???
#endif


 
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);//????
//USART_ITConfig(USART1, USART_IT_PE, ENABLE);
//USART_ITConfig(USART1, USART_IT_ERR, ENABLE);

USART_Cmd(USART1, ENABLE);                    //????

}
阅读(1596) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~