2017-04-09 11:41 PM
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!
2017-04-10 08:02 PM
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
2017-04-14 04:18 AM
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!