Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
firstoption
PostPosted: May 14, 2012 - 09:14 AM
Rookie


Joined: Jun 18, 2011
Posts: 27


Good day to all,
please i need your guide on how to solve this problem.i want to use a value return by a function call to execute the codes below after the interrupt triggers:
Code:
 

ISR(PORTF_INT0_vect)

{

_delay_ms(1000);

UserChoice = eDIP240_Send_Command();//--line1

if(UserChoice==40 ||UserChoice ==41 )//line2
{

PORTC.OUTCLR = PIN4_bm;
spiC_wrt( b );

PORTC.OUTSET = PIN4_bm;

_delay_ms(500);

PORTC.OUTCLR = PIN4_bm;
spiC_wrt( a );

PORTC.OUTSET = PIN4_bm;
}




the condition for the interrupt is that,if PINF0 on PORTF goes LOW;the codes should be executed but i observed that the codes are only executed when lines 1 and 2 are not inluded,something like this
Code:



ISR(PORTF_INT0_vect)//these codes below were executed and worked as
                                    expected

     {   
                     
                               
           
                                   
           
                             PORTC.OUTCLR = PIN4_bm;
                                spiC_wrt( b );
       
                              PORTC.OUTSET = PIN4_bm;

                                _delay_ms(500);
               
                              PORTC.OUTCLR = PIN4_bm;
                                  spiC_wrt( a );
       
                              PORTC.OUTSET = PIN4_bm;

                              PORTC.OUTCLR = PIN4_bm;
                                spiC_wrt( b );
       
                              PORTC.OUTSET = PIN4_bm;

                                _delay_ms(500);
               
                              PORTC.OUTCLR = PIN4_bm;
                                  spiC_wrt( a );
       
                              PORTC.OUTSET = PIN4_bm;
   
   }
 





However,when i tried the codes with while() statement, lines 1 to 3 of the codes were executed while the remaining lines where not executed.

Code:

while (PORTF.IN & 0x01);//execute code when pin goes LOW
                 
                  _delay_ms(1000);
           
       UserChoice =  eDIP240_Send_Command();//line-1
       
      if(UserChoice==40 ||UserChoice ==41 )//line--2
         {
              PORTC.OUTCLR = PIN4_bm;
                      spiC_wrt( b );//line--3
                 PORTC.OUTSET = PIN4_bm;

                 _delay_ms(500);
 
                PORTC.OUTCLR = PIN4_bm;
                 spiC_wrt( a );//line--4
                PORTC.OUTSET = PIN4_bm;
                 _delay_ms(500);

                PORTC.OUTCLR = PIN4_bm;
               spiC_wrt( b );//line--5
               PORTC.OUTSET = PIN4_bm;
               _delay_ms(500);

               PORTC.OUTCLR = PIN4_bm;
               spiC_wrt( a );//line--6
               PORTC.OUTSET = PIN4_bm;
         }

i would be glad if somebody could guide me on how to figure it out.
best regards.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: May 14, 2012 - 09:54 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62209
Location: (using avr-gcc in) Finchingfield, Essex, England

Surely that's just telling you that the call to eDIP240_Send_Command() did not return 40 or 41?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
JohanEkdahl
PostPosted: May 14, 2012 - 10:26 AM
10k+ Postman


Joined: Mar 27, 2002
Posts: 18516
Location: Lund, Sweden

And surely, the phenomenon you are observing - that it seems that some statements inside an if-statement are e3xecuted while others are not - is due to the optimizer of the compiler having domne it's work.

Not that I am telling you to turn it off - just saying that such "phenomenon" are to be expected when the optimizer has been at it. Dont trust tracing by line-by-line-stepping through the C source for optimized code.

Use other debugging techniques (dump trace prints to a display, or through a UART to the PC, or...) and learn to read the generated assembly code at least at a rudimentary level and trae through that when demand arises.

B.t.w. you need to be more meticulous with your indentation.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
firstoption
PostPosted: May 14, 2012 - 11:40 AM
Rookie


Joined: Jun 18, 2011
Posts: 27


thank you very much for the quick response and the observation.from the second code where i used while statement,i can confirm that the function eDIP240_Send_Command() returns 40 or 41 because this line
Code:
spiC_wrt( b );
was executed(this is confimed by my LED which serves as the output,the LED was ON)the only condition for the LED to turn ON is if the function returns 40 or 41.so since the LED was ON,then one can safely say that the function returns one of the two values.
the only problem with this while statement is that the subsequent lines of codes which are supposed to turn OFF & ON the LED were not executed.
but in the case of the interrupt code,the LED did not even turn ON at all when the function and the if statement were added to the code but everything worked fine when both function and if statement were removed.
i am a bit confused.any further suggestion will be highly appreciated.
best regards.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: May 14, 2012 - 11:48 AM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62209
Location: (using avr-gcc in) Finchingfield, Essex, England

Do you have access to a JTAG or PDI debugging interface?

If not then all you can do is pepper the code with either code to light LEDs or output to a UART or lCD or something to identify where the code is "stuck". From what you have now said it sounds like execution could be stuck in the end of the spiC_wrt() function. Does it contain any kind of loop with the potential to be infinite if some condition is not being met?

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits