|
浪淘沙请进,关于USART发送时出现IDLE中断
[复制链接]
前两天看别的东西了,没来得及写,现在发上来,请看一下。 问题如下:使用USART1发送一串数据(这里是30个),发送到不定个数量时(有时12,有时18,有时其他),会产生一个IDLE中断。 main function: int main(void) { #ifdef DEBUG debug(); #endif
/* System Clocks Configuration */ RCC_Configuration(); /* NVIC configuration */ NVIC_Configuration();
/* Configure the GPIO ports */ GPIO_Configuration(); GPIO_SetBits(GPIOC,GPIO_Pin_7);
USART_InitStructure.USART_BaudRate = 9600; 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_InitStructure.USART_Clock = USART_Clock_Disable; USART_InitStructure.USART_CPOL = USART_CPOL_Low; USART_InitStructure.USART_CPHA = USART_CPHA_2Edge; USART_InitStructure.USART_LastBit = USART_LastBit_Disable; /* Configure USART1 */ USART_Init(USART1, &USART_InitStructure);
/* Enable the USART1 */ USART_Cmd(USART1, ENABLE); i = USART_ReceiveData(USART1); USART_SendData(USART1, TxBuffer[TxCounter]); TxCounter += 1; USART_ITConfig(USART1,USART_IT_IDLE,ENABLE);
USART_ITConfig(USART1,USART_IT_TC,ENABLE); while (1) { } } interrupt function: void USART1_IRQHandler(void) { if((USART_GetITStatus(USART1, USART_IT_TC) != RESET) && (GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7) == 1)) { USART_ClearITPendingBit(USART1, USART_IT_TC); USART_SendData(USART1, TxBuffer[TxCounter]); TxCounter += 1; if(TxCounter > 29) { USART_ITConfig(USART1, USART_IT_TC, DISABLE); TxCounter =0; } } else if(USART_GetITStatus(USART1,USART_IT_IDLE) != RESET) { TxCounter = 40; } }
|
|