/*********COM 中断*********/
//
void COM3Init(u32 BaudRate)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; // 25M/50/100
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_Init(GPIOB, &GPIO_InitStructure);
USART_InitStructure.USART_BaudRate =BaudRate;// BaudRate; //波特率设置
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(USART3, &USART_InitStructure);
USART_Cmd(USART3, ENABLE);
USART_ClearFlag(USART3, USART_FLAG_TC);
}
/**************************************************************************/
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //嵌套优先级分组为1
NVIC_InitStructure.NVIC_IRQChannel=USART3_IRQn; //嵌套通道为UART5_IRQn
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0; //抢占优先级为0
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; //响应优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; //通道中断使能
NVIC_Init(&NVIC_InitStructure);
}
/**********************************************************************************/
void USART3_IRQHandler(void)
{
if(USART_GetITStatus(USART3,USART_IT_RXNE)!=RESET)//判断为接收中断
{ USART_SendData(USART1,USART_ReceiveData(USART3));//发送收到的数据
/*******
想做个循环缓冲存储
*****/
}
USART_ClearITPendingBit(USART3, USART_IT_RXNE);
}
/*******************************************************************************/
int main(void)
{
CQCom1.WrPos = CQCom1.RdPos;
CQCom3.WrPos = CQCom3.RdPos;
CQCom5.WrPos = CQCom5.RdPos;
LED_Init(); /*LED*************/
COM1Init(115200*2); /****COM1 for keyboad***************/
COM3Init(115200*2); /****COM2 for debug***************/
NVIC_Config();
printf("\n\r Usart1\n\r"); // COM1 report
/******************************************************************/
while(1)
{
LEDOn(LED2);
delay_ms(200);
delay_ms(200);
} //end while
} //end main
|