void usart_tx(char x)
{
UDR = x; //--- Move data to UDR Data Reg
while (!(UCSRA & (1<<UDRE))); //--- Check whether UDR is empty
}
Don't you think it would make more sense to ensure that UDR is empty before you put something into it?
Please take care with your code layout - it's so much easier to read when nicely laid-out:
void usart_tx(char x)
{
UDR = x; //--- Move data to UDR Data Reg
while (!(UCSRA & (1<<UDRE))); //--- Check whether UDR is empty
}
Note that using TAB characters is not reliable; therefore, do not use TAB characters - use only spaces. This will ensure that your layout is preserved whatever it is viewed on.
Any decent code editor will have an option so that it will insert the appropriate number of spaces when you press the TAB button on your keyboard.
data=usart_rx(); //--- send the received data back
but yet you want to respond to multiple uart inputs. According to your code, once you hit 'k' it will send "AT" then drop into the while(1) loop and do nothing. You wrote the code and it does exactly what you asked it to do.
As is so often said here, you need to stop just flinging code into your editor and design your program.
Sage advice. I'd follow it if i were you. You need a clear plan of how the micro is going to interact with the peripheral. Specify the expected operation and then implement it in as modular a way as possible. Try to test the function of each module in isolation then when you put it all together you should have strong confidence that all the bits work and the only bit that remains to be debugged/developed is the "glue" that connects all the pieces (in fact Arudino programming is very like this!).
Just sitting in a C editor and adding lines that keep trying to "patch up this problem that I face right now" might work for something simple like flashing an LED when a button is pushed but you need a more methodical design approach for more complex projects. It would be an utter miracle if it all "just worked" at the initial attempt.
sorry - I can't read what it says in your first decision box
EDIT
and the "If no / if yes" question in the 2nd decision box makes no sense.
A decision box should contain a question to which the answer is Yes or No (or equivalent) - and it has exit lines correspondingly labelled "Yes" and "No".
Manish - you are pleading with us to spoon feed you, is this what you want? Or would you like to further your education? Currently you have access to the World's largest store of information ever known to man, and you're struggling with a problem that has been solved a zillion times and half them have published example code.
I'd guess collectively we've given you all the answers you need, but you have not taken the initiative to research and understand them. If you want to read a number of characters terminated by a line ending, the standard solution is scanf(). Google AVR stdio
For comparing strings, the function is strcmp(). You can Google these and find out way more than I can describe in the few minutes I'll allocate for you.
For general handling of AT commands for a gsm module - there's plenty of Arduino examples - note these are in C/C++. The main thing though is they show you the technique that can be used in a variety of computer languages.
Kartman sir i am not pleading with you to spoon feed me.
I was about to share my codes so you can help me over it,
I need help to improve them, Not to just give me the desired codes.
I really understand that i am wasting your time and feel sorry for that but i really want to further my education but not in wrong direction thats why i ask you every single doubt.Hope you understand.
As already noted, there are hundreds of projects already published on line specifically using an AVR and an ESP - and there must be thousands that show generally how to have a microcontroller communicate with a device using AT Commands.
It is not new.
It is not rocket science.
Your problem is that you are trying to leap into stuff without having first laid the basic foundations of how to create a program.
You really need to go back to basics, start from scratch, and work through a good book or tutorial on programming.
Better still, join a class and/or get some personal tuition.
In fact, the suggestion was that you should set this whole project aside for a while to concentrate on getting your basic programming foundations laid.
Another thing that has been repeatedly suggested to you - and you still haven't done - is to write out a detailed, character-by-character analysis of what gets sent between the AVR and the ESP.
By all means, do watch the whole episode! It is one of the most hilarious episodes out there. I just had to locate it because of the "LOL" and watched it all again. I've been LOL'ing (actually) and tears have been flowing... Bill Bailey as a total wreck at 24:35 is priceless. And Mr Fry, who normally can keep a constant stone face when needed, just barely keeps from breaking at 25:55-16:05. And there's a lot more..
But don't cherry-pick - there's lots of "back references" so spend the half hour of bandwidth. Worth it. Unless you're easily offended by foul language and insinuations, in which case you should stay off completely..
The Brits sure are excellent at televised humor!
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]
This video contains content from Fremantle International, who has blocked it in your country on copyright grounds.
But it's an Epidsode of QI.
Bill Bailley also has a section on this in one of his own shows - I always think of "ROFLYSSST" = Rolling On the Floor Laughing Yet Somehow, Strangely, Still Typing ...
So remember:
So re-draw that sequence as I showed you in #63 - including the control characters.
You now appear to be running in Proteus - so you can step through your code, line-by-line, and examine your variables as you go.
Do that! and see that using the data from your sequence - drawn as in #63
Top Tips:
- Log in or register to post comments
TopDon't you think it would make more sense to ensure that UDR is empty before you put something into it?
Please take care with your code layout - it's so much easier to read when nicely laid-out:
Note that using TAB characters is not reliable; therefore, do not use TAB characters - use only spaces. This will ensure that your layout is preserved whatever it is viewed on.
Any decent code editor will have an option so that it will insert the appropriate number of spaces when you press the TAB button on your keyboard.
Top Tips:
- Log in or register to post comments
Topyou only read the uart once -
but yet you want to respond to multiple uart inputs. According to your code, once you hit 'k' it will send "AT" then drop into the while(1) loop and do nothing. You wrote the code and it does exactly what you asked it to do.
- Log in or register to post comments
TopPerhaps this will help: http://www.bbc.co.uk/schools/gcsebitesize/design/resistantmaterials/processystemsrev3.shtml
Top Tips:
- Log in or register to post comments
TopStepping in the simulator (or a debugger) would immediately have shown you that!
In fact, just stepping through the code manually with pencil & paper would have shown you that!
It should also have been obvious from a flowchart.
Note also that your comment here is a lie.
Top Tips:
- Log in or register to post comments
TopManish verma
- Log in or register to post comments
TopGo on -you could have rotated it.
A flowchart, as the linked site explained, is supposed to show a sequence of steps - so what is the top "send a command" box supposed to mean?
And, as the linked site mentioned, the different shaped boxes have specific meanings.
Note that the linked site is aimed at 16-year-old school children - this is not rocket science!
Now you need to break it down into handling character-by-character.
In particular, you need to think about how you will identify when a response is complete ...
Again, writing your sequence as shown in #63 will help.
EDIT
https://en.wikipedia.org/wiki/Flowchart
"Flowcharts" have been around since (at least) the 1920s - it's not like this is something new or obscure.
Any basic programming book should cover it - it's not related to any particular language.
Top Tips:
- Log in or register to post comments
TopManish verma
- Log in or register to post comments
TopAgain, note that the command terminator is just \r - not \r\n.
You have missed the terminator from AT+CPMUX
You still haven't shown the process detail of receiving & recognising the "OK" response - which is the part you are struggling with!!
In #107, you send ATE1. This will turn the echo on - is that what you really want? If it is, you will need to adjust your process accordingly
Top Tips:
- Log in or register to post comments
TopManish verma
- Log in or register to post comments
Topsorry - I can't read what it says in your first decision box
EDIT
and the "If no / if yes" question in the 2nd decision box makes no sense.
A decision box should contain a question to which the answer is Yes or No (or equivalent) - and it has exit lines correspondingly labelled "Yes" and "No".
https://en.wikipedia.org/wiki/Flowchart#Common_symbols
Top Tips:
- Log in or register to post comments
TopIf I zoom in, all I see is:
Top Tips:
- Log in or register to post comments
TopSorry I was not aware of it...." Check response"
If yes then print ok ,if no then print error.
Manish verma
- Log in or register to post comments
TopBut that makes no sense in that position - does it?
At that point, you have not yet received anything - have you?
EDIT
and what about the echo?
Top Tips:
- Log in or register to post comments
TopAwneil please help me out to make receive buffer,
All i want is to make a function which receives character by character like 'M','N','O','\r','\n'.
and they all stored in some array. like receive_data[],
And after that how can i compare that
receive_data=="MNO\r\n.
please help.
Manish verma
- Log in or register to post comments
TopThis is getting painful for all concerned.
Manish - you are pleading with us to spoon feed you, is this what you want? Or would you like to further your education? Currently you have access to the World's largest store of information ever known to man, and you're struggling with a problem that has been solved a zillion times and half them have published example code.
I'd guess collectively we've given you all the answers you need, but you have not taken the initiative to research and understand them. If you want to read a number of characters terminated by a line ending, the standard solution is scanf(). Google AVR stdio
For comparing strings, the function is strcmp(). You can Google these and find out way more than I can describe in the few minutes I'll allocate for you.
For general handling of AT commands for a gsm module - there's plenty of Arduino examples - note these are in C/C++. The main thing though is they show you the technique that can be used in a variety of computer languages.
- Log in or register to post comments
TopKartman sir i am not pleading with you to spoon feed me.
I was about to share my codes so you can help me over it,
I need help to improve them, Not to just give me the desired codes.
I really understand that i am wasting your time and feel sorry for that but i really want to further my education but not in wrong direction thats why i ask you every single doubt.Hope you understand.
And sorry if i irritated you any how.
Manish verma
- Log in or register to post comments
TopI'm sorry, but yes - you are.
Just look at #116 for a prime example.
You're starting to get the idea of flowcharts - so why don't you carry on
Kartman is right - this is all basic stuff, which has been covered in countless books before the internet was even invented.
And now, with the internet, you have access to it all form the comfort of your desk at the touch of a button.
See https://www.avrfreaks.net/comment...
As already noted, there are hundreds of projects already published on line specifically using an AVR and an ESP - and there must be thousands that show generally how to have a microcontroller communicate with a device using AT Commands.
It is not new.
It is not rocket science.
Your problem is that you are trying to leap into stuff without having first laid the basic foundations of how to create a program.
You really need to go back to basics, start from scratch, and work through a good book or tutorial on programming.
Better still, join a class and/or get some personal tuition.
There's a booklist included here: http://blog.antronics.co.uk/2011...
EDIT
typo
Top Tips:
- Log in or register to post comments
TopFundamental to any form of programming is the ability to analyze a problem, and break it down into the steps needed to complete the task.
The standard example when starting learning programming is to describe some "simple" everyday task; eg, boiling the kettle to make a cup of tea:
EDIT
Think how filling a kettle with water is analogous to filling a buffer with characters ...
Top Tips:
- Log in or register to post comments
TopPlease have a look over here.
please have a look on it, i just made a simple program in which AT prints, then waits for receving character '\r',
once it receive it , it shows next command.
Manish verma
- Log in or register to post comments
TopYou're not listening, are you?
How many times has it been said already:
Top Tips:
- Log in or register to post comments
TopNo.
Before asking others to "have a look on it", you test it.
For a simple piece of code like this, you can simply step through it on paper with a pencil.
Or step through it in a simulator or debugger - see #106.
This would immediately show you a couple of basic flaws.
And you still haven't paid attention to the correct command termination - have you?
Top Tips:
- Log in or register to post comments
TopI am listening, i was just completing my codes to show you.
Now i am reading what you ask me to until then give me some time because i takes some time.
Manish verma
- Log in or register to post comments
TopNo, you clearly are not.
Which is what you have specifically been told not to do!!
How, then, can you say you are listening?!
Top Tips:
- Log in or register to post comments
TopBut this is the code i learnt after reading what you ask me too so before going further i thought lets try it once.
Manish verma
- Log in or register to post comments
TopNobody asked you to write any code.
You haven't showed any design yet.
eg, a flowchart of how you intend to collect the incoming characters.
Top Tips:
- Log in or register to post comments
TopIn fact, the suggestion was that you should set this whole project aside for a while to concentrate on getting your basic programming foundations laid.
Top Tips:
- Log in or register to post comments
Topok Sorry !! first i make flow chart then i'll go further.
Manish verma
- Log in or register to post comments
TopAnother thing that has been repeatedly suggested to you - and you still haven't done - is to write out a detailed, character-by-character analysis of what gets sent between the AVR and the ESP.
I showed you an example in #63.
Top Tips:
- Log in or register to post comments
TopNoted.
Be back as soon as possible after completing what you said.
Thanks.
Manish verma
- Log in or register to post comments
TopNo need to rush.
Take your time.
Think carefully; review everything.
Top Tips:
- Log in or register to post comments
TopI think you missed your vocation, awneil. You would have made a fine programming instructor, maybe in a Jesuit programming school.
Quebracho seems to be the hardest wood.
- Log in or register to post comments
Top^awneil
- Log in or register to post comments
Top- Log in or register to post comments
TopOK, for once it wasn't me that started OTing, so there! Still...
https://youtu.be/8h0LLD_N9ds?lis...
By all means, do watch the whole episode! It is one of the most hilarious episodes out there. I just had to locate it because of the "LOL" and watched it all again. I've been LOL'ing (actually) and tears have been flowing... Bill Bailey as a total wreck at 24:35 is priceless. And Mr Fry, who normally can keep a constant stone face when needed, just barely keeps from breaking at 25:55-16:05. And there's a lot more..
But don't cherry-pick - there's lots of "back references" so spend the half hour of bandwidth. Worth it. Unless you're easily offended by foul language and insinuations, in which case you should stay off completely..
The Brits sure are excellent at televised humor!
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]
- Log in or register to post comments
TopBut it's an Epidsode of QI.
Bill Bailley also has a section on this in one of his own shows - I always think of "ROFLYSSST" = Rolling On the Floor Laughing Yet Somehow, Strangely, Still Typing ...
EDIT
https://www.youtube.com/watch?v=...
Thank you, Google!
Top Tips:
- Log in or register to post comments
TopHello friends i am back with good news finally i've acheived what i wanted.
Thanks to all and specially Awneil for all your support and intimidation.
so happy !!
My micro sending some data to esp and esp send that data to another esp using wifi and then another micro receives and work according to receive data.
Thanks a ton.
Love you Awneil as a BROTHER !! :)
I'll post my codes after commenting all strings so anyone can understand them easily.
Manish verma
- Log in or register to post comments
Top"Thanks to all and specially Awneil for all your support and intimidation."
Brilliant!
"Love you Awneil as a BROTHER !! :)"
https://en.wikipedia.org/wiki/Je...
Joking aside, well done to "staring" for persevering, and to awneil for his
intimidationpatience.Quebracho seems to be the hardest wood.
- Log in or register to post comments
TopManish verma
- Log in or register to post comments
TopPages