cancel
Showing results for 
Search instead for 
Did you mean: 

c code

joemccarr
Senior
Posted on October 23, 2016 at 02:16

Hello folks,

Would anyone know why this does NOT work

 while (DMA1->ISR & DMA_ISR_TCIF1==0);    //wait until transfer complete

but this WORKs

 

  tc_flag=DMA1->ISR & DMA_ISR_TCIF1; //save transfer complete flag

  

 while (!tc_flag){                                                       

 tc_flag=DMA1->ISR & DMA_ISR_TCIF1;    //wait until transfer complete

}

  

Thank you

#c
5 REPLIES 5
michaelc.barton9
Associate II
Posted on October 23, 2016 at 09:43

does your compiler not give you a warnimg like mine ? eg:

src\main.c 49 warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]

hint: Operator Precedence

Posted on October 23, 2016 at 16:31

Try

while ((DMA1->ISR & DMA_ISR_TCIF1) == 0);    //wait until transfer complete

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
joemccarr
Senior
Posted on October 25, 2016 at 00:46

Michael, my compiler does not give me a warning.

That worked clive1, thank you

michaelc.barton9
Associate II
Posted on October 25, 2016 at 09:21

''Michael, my compiler does not give me a warning.''

I'm using ARM-GCC compiler not setup anything special (Em:Blocks)

it doesn't give quite all issues, but is pretty good

''That worked clive1, thank you''

yes, but

why

!

how will you know to avoid this error in future, especially since your compiler is giving you any warnings !

qwer.asdf
Senior
Posted on October 25, 2016 at 10:27

> yes, but

why

!

> how will you know to avoid this error in future, especially since your

> compiler is giving you any warnings !

The code was valid C. There were no syntax errors. So the warning that the up-to-date compilers are giving is a courtesy.

McC.Joe, my advice would be to better learn the C language, use an updated GCC version, and make sure you are telling your compiler to be verbose about the errors and warnings, something like this must be OK (I'd use -Werror too but some of ST libraries throw warnings and restrict us from using such strict but safer compiler options):

-std=c99 -Wall -Wextra -Wformat -Wformat-security -Wno-missing-field-initializers -Wno-unused-function -Wno-unused-but-set-variable -fno-strict-aliasing