cancel
Showing results for 
Search instead for 
Did you mean: 

Troubles about operating the main function of STM32F103C8T6

letters ling
Associate
Posted on April 10, 2017 at 08:41

Hello~all,thanks for reading my thread.I met some troubles in the process of operating STM32F103C8T6,here this is the

http://www.kynix.com/uploadfiles/pdf8827/STM32F103C8T6.pdf

. does anyone here can help me out?

The program is as following:

            while (1)

                {

                        if(flag==0x01)

                        {

                                flag=0;//标志ä½�清0

                                iPose=0;

                                USART1_Printf('123456789');

                                memcpy(&XY2_position,Receie_data,9);

                                if(XY2_position.num)Line_Bresenham(XY2_position.x0,XY2_position.y0,XY2_position.x1,XY2_position.y1);

                                else                      Line_DDA(XY2_position.x0,XY2_position.y0,XY2_position.x1,XY2_position.y1);

                        }

                }

}

void USART1_IRQHandler(void)        //串å�£1中断函数

{

        USART_ClearFlag(USART1,USART_FLAG_TC);

        if(USART1->SR & 0x00000020)//检查指定的USART中断å�‘ç�?Ÿä¸Žå�¦

        {

                Receie_data[iPose]=USART1->DR & (uint16_t)0x01FF;//读å�–接æ�?¶åˆ°çš„æ•°æ�®

                iPose++;//计数器加1

                if(iPose==9)flag=0x01;                

                USART1->DR = (flag & (uint16_t)0x01FF);

                while((USART1->SR&0x00000040) == 0);//准备å�‘é€�一个数æ�®        

        }

}

When I operated the program in the STM32,the reactive data which were reviewed shows normal.However,It always can

’

t review that

“

flag==1

�

.What

’

s odd,the ninth digital of reactive data from series shows

“

flag=1

�

. According to its situation,I change another SCM to have a try,it

’

s normal in the first programming while there always display that the

“

flag=1

�

 from the second time.

Why? How to solve this problems? Please help me !

Thank you in advance!

2 REPLIES 2
Max
ST Employee
Posted on April 11, 2017 at 05:02

Hello, 

is your 'flag' declared as volatile?

if not, the compiler may optimize and remove the test and even the whole loop altogether...

You must declare as volatile any variable that you use in the main and you modify inside an interrupt routine.

regards,

Max

Posted on April 14, 2017 at 11:18

Hi,Max

I have found the specific problems,it's the 

memcpy(&XY2_position,Receie_data,9) that lead to the program died!

Thank you for you kind help!

Thank you very much!