void SCU_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; TIM_InitTypeDef TIM_InitStructure; UART_InitTypeDef UART_InitStructure; /* SYSTEM CLOCK Configuration ------------------------------------------------*/ //CPU = 25MHZ SCU_MCLKSourceConfig(SCU_MCLK_OSC); SCU_RCLKDivisorConfig(SCU_RCLK_Div8); SCU_HCLKDivisorConfig(SCU_HCLK_Div1); SCU_PCLKDivisorConfig(SCU_PCLK_Div1); SCU_BRCLKDivisorConfig(SCU_BRCLK_Div2); //24MHZ //PLL = 96MHz SCU_PLLCmd(DISABLE); SCU_PLLFactorsConfig(0xC0,0x19,0x2); SCU_PLLCmd(ENABLE); //CPU = 96MHZ SCU_MCLKSourceConfig(SCU_MCLK_PLL);
/* SYSTEM interrupt controller Configuration ------------------------------------------------*/ SCU_AHBPeriphClockConfig(__VIC, ENABLE); SCU_APBPeriphReset(__VIC,DISABLE); VIC_DeInit(); /* TIMER Configuration -------------------------------------------------------*/ /* TIM0 Deinitialization */ #if 1//定时器开关 TIM_DeInit(TIM0); // Enable TIM0 clocks SCU_APBPeriphClockConfig(__TIM01, ENABLE); // Release TIM0 reset SCU_APBPeriphReset(__TIM01,DISABLE); // TIM Configuration in Output Compare Timing Mode period 100us TIM_InitStructure.TIM_Mode = TIM_OCM_CHANNEL_1; // OUTPUT COMPARE CHANNEL 1 Mode TIM_InitStructure.TIM_OC1_Modes = TIM_TIMING; // OCMP1 pin is disabled TIM_InitStructure.TIM_Clock_Source = TIM_CLK_APB; // assign PCLK to TIM_Clk TIM_InitStructure.TIM_Prescaler = 12 - 1; // 1us resolution TIM_InitStructure.TIM_Pulse_Length_1 = 1000; // 1 ms period TIM_Init(TIM0, &TIM_InitStructure); // VIC configuration VIC_Config(TIM0_ITLine, VIC_IRQ, TIM0_ITLine); //VIC_Config(TIM0_ITLine, VIC_IRQ, 0); VIC_ITCmd(TIM0_ITLine, ENABLE); /* Clear TIM0 ISR registers */ TIM_ClearFlag(TIM0, TIM_FLAG_OC1| TIM_FLAG_OC2| TIM_FLAG_TO|TIM_FLAG_IC1|TIM_FLAG_IC2); /* Enable TIM0 IC1 interrupt */ TIM_ITConfig(TIM0, TIM_IT_OC1, ENABLE); /* Start the counter of TIM0 */ TIM_CounterCmd(TIM0, TIM_START); #endif /* GPIO Configuration --------------------------------------------------------*/ SCU_APBPeriphClockConfig(__GPIO3, ENABLE); /* Enable the clock for GPIO3 */ GPIO_DeInit(GPIO3); /* GPIO3 Deinitialization */ SCU_APBPeriphClockConfig(__GPIO5, ENABLE); /* Enable the clock for GPIO5 */ GPIO_DeInit(GPIO5); GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;//GPIO_Pin_0 |GPIO_Pin_4; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_Alternate=GPIO_OutputAlt1; GPIO_Init (GPIO3, &GPIO_InitStructure); /*Gonfigure UART0_Rx pin GPIO5.1*/ GPIO_InitStructure.GPIO_Direction = GPIO_PinInput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_IPConnected = GPIO_IPConnected_Enable; GPIO_InitStructure.GPIO_Alternate = GPIO_InputAlt1; GPIO_Init (GPIO5, &GPIO_InitStructure); /*Gonfigure UART0_Tx pin GPIO3.4*/ GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_InitStructure.GPIO_Alternate = GPIO_OutputAlt3 ; GPIO_Init (GPIO3, &GPIO_InitStructure);
/* UART Configuration --------------------------------------------------------*/ // Release reset and enable clock UART_DeInit(UART0); // Enable UART0 clocks SCU_APBPeriphClockConfig(__UART0, ENABLE); // Release UART0 reset SCU_APBPeriphReset(__UART0, DISABLE); UART_InitStructure.UART_WordLength = UART_WordLength_8D; UART_InitStructure.UART_StopBits = UART_StopBits_1; UART_InitStructure.UART_Parity = UART_Parity_No ; UART_InitStructure.UART_BaudRate = 115200; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; UART_InitStructure.UART_FIFO = UART_FIFO_Disable; UART_Init(UART0, &UART_InitStructure); UART_DMACmd(UART0,UART_DMAReq_Tx | UART_DMAReq_Rx, DISABLE); // Enable and configure the priority of the UART0 Update IRQ Channel // VIC_Config(UART0_ITLine, VIC_IRQ, 14); VIC_Config(UART0_ITLine, VIC_IRQ, 0);
VIC_ITCmd(UART0_ITLine, ENABLE); /* Enable UART interrupt */ UART_ITConfig(UART0, UART_IT_Receive, ENABLE); /* Enable the UART0 */ UART_Cmd(UART0, ENABLE); // Enable the Interrupt controller to manage IRQ channel __enable_interrupt(); }
//定时器中断 void TIM0_IRQHandler(void) { TIM0->CNTR=0; //TIM_CounterCmd(TIM0, TIM_START); /* Clear TIM0 ISR registers */ TIM_ClearFlag(TIM0, TIM_FLAG_OC1); }
//UART0 中断 void UART0_IRQHandler(void) { unsigned char data1; data1 = UART_ReceiveData(UART0); UART_SendData(UART0, data1); // resend received data /* Clear the UART0 Receive interrupt */ UART_ClearITPendingBit(UART0, UART_IT_Receive); }
当我定时器打开的时候,UART接收会收漏丢!如果,把定时器关了,就收得很正常~ 谁帮我看一下,竟究是什么问题,谢谢!!!
|
|