cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 UART DMA(RX AND TX) can execute only once ,

BeMercy
Associate II
Posted on July 02, 2015 at 09:57

Hi:

i use the DMA interrupt to send 8 byte data and receive 9 byte,it can only executes once,but when i debug it step by step,it works well。i'm so confused.Sorry for my poor english.

Here is my code,is there something important i miss?

Thank you for your patience

void DMA1_Channel4_IRQHandler(void) /* DMA TX ,interrupt after all the datas send over*/
{ 
DMA_ClearFlag(DMA1_FLAG_TC4); 
DMA_ClearITPendingBit(DMA1_IT_TC4);
DMA_Cmd(DMA1_Channel4,DISABLE); 
}
void DMA1_Channel5_IRQHandler(void) 
{ 
DMA_ClearITPendingBit(DMA1_IT_TC5);
DMA_Cmd(DMA1_Channel5, DISABLE); /*Enable DMA RX*/
DMA_SetCurrDataCounter(DMA1_Channel5,9); 
DMA_Cmd(DMA1_Channel5, ENABLE); 
/*
here is data process, 9 byte datas
*/
if(TempHumidity.AddressSelectFlag == 0) /* Uart_Send_Buffer is the buffer connected to USART1->DR*/
{
TempHumidity.AddressSelectFlag = 1;
MemCopy(Uart_Send_Buffer,TempHumidity.UartSendBufferA,8); 
}
else
{
TempHumidity.AddressSelectFlag = 0;
MemCopy(Uart_Send_Buffer,TempHumidity.UartSendBufferB,8); 
}
DMA_Cmd(DMA1_Channel4, DISABLE); 
DMA_SetCurrDataCounter(DMA1_Channel4,8); 
DMA_Cmd(DMA1_Channel4, ENABLE); /*Enable DMA TX*/
}

3 REPLIES 3
Posted on July 02, 2015 at 17:17

Please don't spam other threads, that's not how the forum works.

If it works under the debugger look carefully at the timing and potential race conditions.

I would try to qualify the interrupt sources, and perhaps use GPIO's and a logic analyzer to understand the failure and timing of things.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
BeMercy
Associate II
Posted on July 02, 2015 at 17:54

sorry,i'm a sophmore from China,before asking this question,i've use the 

oscilloscope to test it,and read the datasheet many times,i guess the error must be the timing or important flags i ignored.

  i have another way to realize my goal.but i just cannot understand why this way cannot get the right answer.

  Thanks for your reply,i'll borrow a logic analyzer to test it. Actually,this is my first time to use english to ask questions.

Posted on July 02, 2015 at 19:22

Actually,this is my first time to use english to ask questions.

You're English is very good, don't worry about it.

You might want to look at how you handle synchronization issues here, if the data doesn't come back quite as you expect, or it starts out of sync. There's a potential for it to dead-lock, perhaps, where it doesn't start a new batch of bytes, and is still waiting for 1 or 2 to arrive. Consider a timeout.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..