大家好,我有个事情弄了几天也没弄明白,在我的程序里面我用串口输出信息给计算机,我在外部中断和systick服务函数里面调用串口发送函数都好用,但是在主程序里面却无法发送好像程序没有回到主函数一样,还有一个更奇怪的现象就是,我必须在systick里面调用串口发送,否则在外部中断也无法发送串口数据。以下是我的部分代码:
main()
{
u16 i,j,q=0x00;
#ifdef DEBUG
debug();
#endif
/*Clear FLAG Bit,if not first Data bit will be lost*/
USART_ClearFlag(USART1, USART_FLAG_TC);
USART_ClearFlag(USART2, USART_FLAG_TC);
RCC_Configuration() ;
// Time_Configuartion();
GPIO_Configuration();
Exti_Configuartion();
NVIC_Configuration();
UART_Configuartion();
SysTick_Configuration();
// BUffer_DAQ_Data=Average_Data;
// USART_SendData(USART1, 0xaa);
/* Infinite loop */
while(1)
{
for(j=0;j<10;j++)
{
for(i=0;i<0xfff;i++) q=0xff;
}
if(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==SET)
{
USART_SendData(USART1, 0xee);
}
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET)/*等待发送完成*/
{;}
}
}
//==========================================================
void UART_Configuartion(void)
{
/* USART1 and USART2 configured as follow:
- BaudRate = 9600 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Hardware flow control disabled (RTS and CTS signals)
- Receive and transmit enabled
*/
USART_InitTypeDef USART_InitStructure;
#ifdef USART1_OnOff
/*USART1*/
USART_InitStructure.USART_BaudRate = 115200 ; //设定传输速率
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//Data 8Bit
USART_InitStructure.USART_StopBits = USART_StopBits_1; //stop 1bit
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);//初始化UART1
USART_Cmd(USART1, ENABLE);//Enable USART1
/*Enable the USART1 Rx,Tx Interrupt*/
USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
#endif
#ifdef USART2_OnOff
/*USART2*/
USART_InitStructure.USART_BaudRate = 115200; /*设置波特率为115200*/
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_Cmd(USART2, ENABLE);//Enable USART2
/*Enable the USART2 Rx,Tx Interrupt*/
USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
#endif
}
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line6) != RESET) //检测制定的EXTI线路触发请求是否发生
{
/********************************Read Input Data Value******************************/
if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5)) Collect_Data |= Collect_Data_Bit[ident1];
ident1++ ;
USART_SendData(USART1, 0xaa);
//-----------------------------------------------------------------------------------
SysTick_CounterCmd(SysTick_Counter_Clear);
EXTI_ClearITPendingBit(EXTI_Line6);//清外部中断6
}
}
void SysTickHandler(void)
{
if(ident1 == 24)
{
Array_USART2_RTx[BUffer_USART2_Rx]=Data_INput_Processing(Collect_Data);
BUffer_USART2_Rx++;
BUffer_USART2_Rx &= 0x3f;
//===========================================================
//===========================================================
}
USART_SendData(USART1, 0xbb);
ident1=0x00;
}
|