my simple code is ... --------------------------------------------------------------
unsigned char flag[3] = {0,}; unsigned char abc, sdf, def ; void main (void) { while(1) { //if( flag[0] == 0 && flag[1] == 0 && flag[2] == 0 ) if ( ((*((int *)flag)) & 0xFFFFFF00) == 0 ) { abc &= ~0x1; sdf = 0; if( def ) { //do_something; } } } }
------------------------------------------------------------- this code is going to hard fault handler.. and -------------------------------------------------------------
unsigned char flag[3] = {0,}; unsigned char abc, sdf, def ; void main (void) { while(1) { //if( flag[0] == 0 && flag[1] == 0 && flag[2] == 0 ) if ( ((*((int *)flag)) & 0xFFFFFF00) == 0 ) { // abc &= ~0x1; // sdf = 0; if( def ) { //do_something; } } } }
------------------------------------------------------------- this code is working well..
-------------------------------------------------------------
unsigned char flag[3] = {0,}; unsigned char abc, sdf, def ; void main (void) { while(1) { //if( flag[0] == 0 && flag[1] == 0 && flag[2] == 0 ) if ( ((*((int *)flag)) & 0xFFFFFF00) == 0 ) { abc &= ~0x1; sdf = 0; /*if( def ) { //do_something; } */ } } }
------------------------------------------------------------- this is also working well.. please let me know what's the problem.. are there any guru??
Single step thru the code. you should clearly see where it faults.
My guess is 'coz you're typecasting a char pointer to an int pointer. Probably an alignment fault.
ps I'm not a guru, but I have at least looked at a few manuals.
View all questions in Keil forum