cancel
Showing results for 
Search instead for 
Did you mean: 

How to stop receiving UART data with DMA.

HYosh.2
Associate II

Hi all

I'm triying using DMA to receive UART.

But the number of UART data is depending on the situation.

So I want to set a CNDTR register with margin.

I was wondering that I can stop DMA before CNDTR is zero.

When DMA Enable bit is cleared, it seem that don't stop immediately.

I think that the cause is that CNDTR is not zero.

But I want to stop DMA before CNDTR is zero.

Is there way to solve it? 

Regards,

6 REPLIES 6

Which STM32?

> When DMA Enable bit is cleared, it seem that don't stop immediately

Why do you think so?

It just finishes the last transaction if it already started.

JW

HYosh.2
Associate II

>Which STM32?

I'm using Nucleo-G071RE.

CNDTR is set with margin(Because data size is not constant)

I took test by 256Bytes date with break(Break is mark of data starting).

And I coded that when I recieve break, DMA data receive pointer and CNDTR reset, then receive restart.

When I set 256Bytes to CNDTR, it worked properly.

When I set more than 256Byte to CNDTR, it does'nt work as expected.

0693W000003CABoQAO.png

TDK
Guru

In your example, when it "works", the data becomes 0, 0, 0, ...

When it "doesn't work", the data is 0, 1, 2, ...

Since you're sending 0, 1, 2, ..., that statement seems backwards to me.

Writing EN=0 definitely disables the stream.

If you feel a post has answered your question, please click "Accept as Solution".
HYosh.2
Associate II

In this test situation, 1 packet is 256Bytes.

I programmed that when it received 256Bytes, then En = 0 , then data pointer set to "Buffer adr = 0" , CNDTR is reset(256 or more than 256), En = 1. 

So, My expected result is that there is no data above "Buffer Adrs = 256".

I was wondering that result depending on CNDTR.

TDK
Guru

Okay, that makes more sense.

It should work as you expect. When EN=0, the DMA is off. There's likely a bug in the code somewhere.

If you feel a post has answered your question, please click "Accept as Solution".

Thank for you replying.

I'll check my code again.​