cancel
Showing results for 
Search instead for 
Did you mean: 

USART DMA misses the input string sequence (Pending DMA)

JJohn.3
Associate II

Hello,

I configure my DMA in Normal mode. Here is my code:

void DMA1_Channel3_IRQHandler(void){ // USART3_RX 
		unsigned char CheckSum[2];
 
		Var1=Var1+1;
		if(Var1>1000){Var1=0;}	
	
		if(Buffer[0]==89 && Buffer[26]=='\n')
			{			
				
 
		Var2=Var2+1;
		if(Var2>1000){Var2=0;}	
 
					
			}		
			DMA_ClearITPendingBit(DMA1_IT_TC3);	
			DMA_ClearITPendingBit(DMA1_IT_TE3);				
			DMA_Cmd(DMA1_Channel3, DISABLE);
			DMA_SetCurrDataCounter(DMA1_Channel3,sizeof(Buffer));
 
 
				
	}
void EXTI9_5_IRQHandler(void){
	
    if (EXTI_GetITStatus(EXTI_Line5) != RESET)
			{	
				if(GPIO_ReadInputDataBit(GPIOA,GetPosition)==0 )
					{								
							DMA_SetCurrDataCounter(DMA1_Channel3,sizeof(Buffer));
							DMA_ClearITPendingBit(DMA1_IT_TC3);	
							DMA_ITConfig(DMA1_Channel3,DMA_IT_TE, ENABLE);
							USART_ITConfig(USART3, USART_IT_ERR, ENABLE);
							USART_DMACmd(USART3, USART_DMAReq_Rx, ENABLE);
							DMA_Cmd(DMA1_Channel3, ENABLE);
							GPIO_ResetBits(GPIOA,SendSignalPosition);
					}				
				else
					{	
							GPIO_SetBits(GPIOA,SendSignalPosition);
							DMA_Cmd(DMA1_Channel3, DISABLE);	
					}			
							EXTI_ClearITPendingBit(EXTI_Line5);
    }
}

Before each transmission, The transmitter change the PA.5 to low level , and if the receiver changes its SendSignalPosition pin(start DMA), the transmitter start transmitting and wait for 50us after all bytes being transferred.

This code works fine until I send some packages to the transmitter with DMA(TX) from the receiver. After sending some packages, the DMA looses the input sequence. I checked the variable Var1 and Var2 and I found out that Var1 is increasing ( the DMA is collecting the input bytes) but Var2 doesn't change after losing the input string sequence.

I need to know why this is happening while before each transsmison I disable/enable the DMA.

In addition, I've checked the Buffer[0] and I've seen that it contains the last character of the previous string. It seems the last character maintain in the buffer while the DMA is disabled.

0 REPLIES 0