Weird behavior of "IF" statement

Go To Last Post
35 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello freaks,

 

I am trying to manipulate the ON/OFF functionality of a GSM module.

This is my code.

 

#define GSM_ON        1
#define GSM_OFF       0

volatile unsigned char gsmPresent_state = 0;  // Global variable

void gsmOnOff_func(void)
{
    switch(gsmPresent_state)
    {
        case 0 :
        gsmOnOff(GSM_ON, &gsmPresent_state);
        break;

        case 1 :
        gsmOnOff(GSM_OFF, &gsmPresent_state);
        break;
    }
}

void gsmOnOff(unsigned char desire_state, volatile unsigned char *next_state)
{
	unsigned char response = check_state_command(....);

	if(response != desire_state)
	{
		if((response == 0) && (desire_state == 1))
		{
			// Switch ON the modem

			if((response = check_state_command(...)))
			{
				*next_state = 1;
			}
		}
		else if ((response == 1) && (desire_state == 0))
		{
			if((response = send_OFFstate_command(...)))
			{
				*next_state = 0;
			}
		}
	}
}

When the gsmOnOff_func() called by an external push button runs normally and the first IF statement "if(response == 0 && desire_state == 1)" compares the values and finally switched on the GSM.

Now, when I pressed again the external push button the second IF statement "else if (response == 1 && desire_state == 0)" has being ignored.

During debugging I observed that all values at this particular point are correct (response and desire_state).

Can you explain me please this behavior?

Thanks.

This topic has a solution.
Last Edited: Thu. Jan 4, 2018 - 08:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It may or may not be your problem, but do you have the C precedence table so ingrained that you do not need parentheses?

 

I.e. is

(response == 0 && desire_state == 1)

the same as

((response == 0) && (desire_state == 1))

?  Dunno; have to look it up.  Yep, == is higher than &&

 

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

An important take-away from Lee's comment is that parenthesis cost you absolutely nothing when the code is finally compiled. Yes, it costs you a few more milliseconds to type but it removes any ambiguity or uncertainty about what the intended code is. For all I know, you COULD have intended

(response == (0 && desire_state) == 1)

Whether the compiler would accept it is another question (it probably won't, but it will accept some, to me, odd constructs). Adding parenthesis removes any ambiguity about what you REALLY intend to do.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kobogia wrote:
if((response = check_state_command(...)))

What this assignment does inside if?!
I bet you mean == not =
This is a common mistake

Majid

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

m.majid wrote:

kobogia wrote:

if((response = check_state_command(...)))

 

What this assignment does inside if?!
I bet you mean == not =
This is a common mistake

Nice catch m.majid!  Two places in the code kobogia.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Wed. Jan 3, 2018 - 03:26 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have made enough of them, time to catch them!

Majid

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your quick replies.

 

Even if I use the extra parentheses (which is the correct approach) the IF statement has being ignored.

I had tried also a different way to to do the same thing :

if (response == 1)
{
	if(desire_state == 0)
	{
		// Switch off the GSM
	}
}

But I have the same results. The second "if(desire_state == 0)" has being ignored.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the "response" is true (1) then I have positive reply of the module else (0) is negative.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

larryvc wrote:

m.majid wrote:

 

kobogia wrote:

if((response = check_state_command(...)))

 

What this assignment does inside if?!
I bet you mean == not =
This is a common mistake

Nice catch m.majid!  Two places in the code kobogia.

Seriously kobogia, do you not see the two lines of code that m.majid has referenced above that need == instead of =    On a phone can't post code now

 

EDIT:  I'm out 

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Wed. Jan 3, 2018 - 07:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In #7, kobogia wrote:
The second "if(desire_state == 0)" has being ignored

How do you know it is being ignored?

 

  • maybe desire_state is not zero?
  • maybe response is not one?

 

Have you used the debugger to step through and see what's actually happening?

 

In #8, kobogia wrote:
If the "response" is true (1)

Note that, in 'C', zero is false; but any other value is considered true - so are you sure that response is actually one ... ?

 

EDIT

 

Clarify references 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Wed. Jan 3, 2018 - 08:12 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In #9, larryvc wrote:

Seriously kobogia, do you not see the two lines of code that m.majid has referenced above that need == instead of =    On a phone can't post code now

 

Yes, I read the code of m.majid but I still don't understand why to use a comparison operator at this point.

First, I don't want to compare any value there but I want to assign the return value of the "check_state_command()" function to the "response" variable and if it is <!=0> then run that is inside.

Second, the program is running well until this point. The problem starts here:

else if ((response == 1) && (desire_state == 0))

 

Please give me detailed explanation if possible.

 

 

Last Edited: Wed. Jan 3, 2018 - 03:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In #7, kobogia wrote:
The second "if(desire_state == 0)" has being ignored

In #10, awneil wrote:

How do you know it is being ignored?

 

  • maybe desire_state is not zero?
  • maybe response is not one?

 

Have you used the debugger to step through and see what's actually happening?

 

As I mentioned in my first post I have checked already with debugging mode which are the values at this particular point.

All values are correct and the

else if ((response == 1) && (desire_state == 0))

statement must be "true".

 

 

In #8, kobogia wrote:
If the "response" is true (1)

In #10, awneil wrote:

Note that, in 'C', zero is false; but any other value is considered true - so are you sure that response is actually one ... ?

 

I have checked it with debugging. "response" variable takes the value 1(one) from returned variable of the

response = check_state_command(...);

check_state_command() function.

 

Later I'll give you pictures during debugging.

Thanks for helping.

 

Last Edited: Wed. Jan 3, 2018 - 02:43 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kobogia wrote:
I want to assign the return value of the "check_state_command()" function to the "response" variable and if it is <!=0> then run that is inside.

Yes, that is what your code as written will do.

 

But it is a common mistake for people to write code like that when they did want a compare rather than an assignment.

 

For clarity, it is better to write it as

response = check_state_command(...);
if( response )
{
   :
   : 

You don't save any code space by compacting your source text!

 

 

 

 

Quote:

The problem starts here:

else if ((response == 1) && (desire_state == 0))

 

Please give me detailed explanation if possible.

 

I think you need to start by giving a clear explanation of what, exactly, the problem is.

 

I have already raised a number of points in #10 - please address them

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
For clarity, it is better to write it as

response = check_state_command(...);
if( response )
{
   :
   : 

 

 

Or, as you don't use response, as

if( check_state_command(...) )
{
   :
   : 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So, I captured some images during debugging in order to explain you what the problem is.

I made also all suggested corrections in my code.

The GSM module is already switched ON because I have pressed the push button once and the first part of program is working well.

 

Now, when I press again the push button in order to switch OFF the GSM module.

 

On image (1d) showed the first IF statement which compares if the "response" and "desire_state" are equal or not.

As you can see below in watch variable's table those two variables are not equal and that is correct.

 

Image (2d).

At the next step the program jumps to the "else if((response==1) && (desire_state==0))" statement which is also correct according to our variable's values.

 

Image (3d).

Finally at the next step the program jumps to the end of the function without entered in the above "else if" statement and that is the problem.

I hope that I explained it good and you understood which is the issue.

 

 

 

 

 

Last Edited: Wed. Jan 3, 2018 - 08:00 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sometimes the debugger pointer is not in sync with the code.  What happens if you step a few times more?

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

larryvc wrote:

Sometimes the debugger pointer is not in sync with the code.  What happens if you step a few times more?

It continue normally to the rest of the program.

I didn't observe any synchronization issue of the debug pointer.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The code shown in the first screenshot step1 does not match the code in step2 and step3.  This is the reason it skips the else if.  Missing { leading to mismatched if else code flow.

 

Please repost the actual code you are using now with the code editor button <>.

 

EDIT: Missing...

 

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Thu. Jan 4, 2018 - 02:35 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

larryvc wrote:

The code shown in the first screenshot step1 does not match the code in step2 and step3.  This is the reason it skips the else if.

 

Please repost the actual code you are using now with the code editor button <>.

 

 

I'm sorry but I didn't understand what you mean that the code doesn't match. The code is the same in all steps and this is my actual code that I use, plus one more function which mentioned in my first post.
Can you give me more details please?
Thanks.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

They are not the same, see my post edit above and this annotated step2 screenshot;

 

 

EDIT: Copy of original step1 screenshot is below;

 

 

EDIT: edited to annotated

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Thu. Jan 4, 2018 - 02:45 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now, if you want us to continue to invest our time in helping you, please post the code you are actually using.

 

EDIT: me, my to us, our

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Wed. Jan 3, 2018 - 11:54 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

 

Just an observation but why test twice anyway if you have already ascertained that response != desire_state

 

void gsmOnOff(unsigned char desire_state, volatile unsigned char *next_state)
{
	unsigned char response = check_state_command(....);

	if(response != desire_state)
	{
		if(response == 0 && desire_state == 1)
		{
			// Switch ON the modem

			if((response = check_state_command(...)))
			{
				*next_state = 1;
			}
		}
		else if (response == 1 && desire_state == 0)
		{
			if((response = send_OFFstate_command(...)))
			{
				*next_state = 0;
			}
		}
	}
}

 

becomes:

 

void gsmOnOff(unsigned char desire_state, volatile unsigned char *next_state)
{
	unsigned char response = check_state_command(....);

	if(response != desire_state)
	{
		if(desire_state == 1)
		{
			// Switch ON the modem

			if((response = check_state_command(...)))
			{
				*next_state = 1;
			}
		}
		else
		{
			if((response = send_OFFstate_command(...)))
			{
				*next_state = 0;
			}
		}
	}
}

 

That's without removing the need for the response variable inside the if statements.

 

Sometimes the optomiser might just appear to skip the code too so maybe just check that the code isn't being run without you realising.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

j0n90 wrote:
why test twice

My thoughts exactly!

 

 

And what is the point of assigning the response inside the ifs:

			if((response = check_state_command(...)))
			{
				*next_state = 1;
			}

and

			if((response = send_OFFstate_command(...)))
			{
				*next_state = 0;
			}

since it is never used?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the purpose of the code is to simply turn the GSM off, or on based on a press of a button may I am wondering:

If PC boards have not been done, why not simply connect the push button to one of the External interrupt pins and set the interrupt. Then when one presses the button, do a fast denounce, and then toggle the associated AVR on connected to th GSM? Super simple.

The code posted seems awfully complicated for such a simple task. Am I missing something?

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
do a fast denounce

I just love that spelign misteak! ;-)

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
simply (sic) turn the GSM off

One shouldn't just turn off the power to a Cellular device - like you shouldn't just pull a USB stick out of the socket.

 

So I would guess that the OP is being good, and shutting down "nicely" ... ?

 

EDIT

 

You don't just pull USB sticks out of the socket - do you ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Thu. Jan 4, 2018 - 01:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Andy
I think you get my simplistic point...... There simply is no need for such an elaborate mechanism for something so simple as required

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

JohanEkdahl wrote:

jgmdesign wrote:
do a fast denounce

I just love that spelign misteak! ;-)


Damn autocorrect on my phone! Grr

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@Johan

jgmdesign wrote:
do a fast denounce
My first thought was, "That button did NOT just change states, IT DID NOT! Reports that it did are just false news"

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Let's keep to the thread topic and not my spelling issues :)

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

larryvc wrote:

They are not the same

 

The code is the same but when the cursor is located inside of every statement the curly braces are getting black.

If you look carefully you will see the BLACK braces. I think is a matter of the editor.

My actual code is in my first post with suggested corrections.

Thanks anyways...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kobogia wrote:

The code is the same but when the cursor is located inside of every statement the curly braces are getting black.

If you look carefully you will see the BLACK braces. I think is a matter of the editor.

My actual code is in my first post with suggested corrections.

Thanks anyways...

Okay, but the way the code flow appeared in the debugger did indicate a control flow issue.  So is your code working now?

 

If so, what is the harm in posting your new working code, including the mentioned missing function for the benefit of others to learn from?

 

EDIT:  If you are going to post debugger screen shots in the future, please change the Color Theme to Blue or Light so that we don't waste time hunting imperceptible ghosts.

"I may make you feel but I can't make you think" - Jethro Tull - Thick As A Brick

"void transmigratus(void) {transmigratus();} // recursio infinitus" - larryvc

"It's much more practical to rely on the processing powers of the real debugger, i.e. the one between the keyboard and chair." - JW wek3

"When you arise in the morning think of what a privilege it is to be alive: to breathe, to think, to enjoy, to love." -  Marcus Aurelius

Last Edited: Thu. Jan 4, 2018 - 07:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

j0n90 wrote:

Just an observation but why test twice anyway if you have already ascertained that response != desire_state

 

The code modified and is working as j0n90 suggested.
The push button is actually a button of rotary encoder and is already connected to a PCINT pin but it has a lot of functionalities since that my project includes a menu structure and not just the GSM module.
Thanks everybody for your time and I wish happy new year.

 

The final code is...

#define GSM_ON        1
#define GSM_OFF       0

volatile unsigned char gsmPresent_state = 0;  // Global variable

void gsmOnOff_func(void)
{
    switch(gsmPresent_state)
    {
        case 0 :
        gsmOnOff(GSM_ON, &gsmPresent_state);
        break;

        case 1 :
        gsmOnOff(GSM_OFF, &gsmPresent_state);
        break;
    }
}


void gsmOnOff(unsigned char desire_state, volatile unsigned char *next_state)
{
	unsigned char response = sim900SendCmdWaitReply(ATCMD_AT,500000,(unsigned char *)RESPONSE_OK,NULL);
	
	if(response != desire_state)
	{
		if(desire_state == 1)
		{
			GSM_PORT &= ~POWER_PIN;
			GSM_PORT |= POWER_PIN;
			_delay_ms(2000);
			GSM_PORT &= ~POWER_PIN;
			_delay_ms(3000);
			
			response = sim900SendCmdWaitReply(ATCMD_AT,500000,(unsigned char *)RESPONSE_OK,NULL);
			if(response)
			{
				*next_state = 1;
			}
		}
		else
		{
			response = sim900SendCmdWaitReply(ATCMD_POWER_OFF,500000,(unsigned char *)RESPONSE_POWER_DOWN,NULL);
			if(response)
			{
				*next_state = 0;
			}
		}
	}
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kobogia wrote:
code modified and is working (sic) 

Well, ...

 

Here

response = sim900SendCmdWaitReply(ATCMD_AT,500000,(unsigned char *)RESPONSE_OK,NULL);
if(response)
{
	*next_state = 1;
}

and here

response = sim900SendCmdWaitReply(ATCMD_POWER_OFF,500000,(unsigned char *)RESPONSE_POWER_DOWN,NULL);
if(response)
{
	*next_state = 0;
}

 

you test the response, presumably, for "success" - but you have no handling or recovery or even notification of failure ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

you test the response, presumably, for "success" - but you have no handling or recovery or even notification of failure ...

 

That's true. I'm planning to continue the code when I'll find a free time.
Thanks for suggestion. smiley