C code for interfacing ESP8266 with AVR mcu

Go To Last Post
140 posts / 0 new

Pages

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

So remember:

  • A UART (or USART) sends/receives just one character at a time.
  • The control characters matter.

 

 

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

 

 

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

staring.net@gmail.com wrote:

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.

 

 

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

you only read the uart once -

 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.

 

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

In #72, clawson wrote:

awneil wrote:

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.

In #69, I wrote:
eg, draw a flowchart 

Perhaps this will help: http://www.bbc.co.uk/schools/gcsebitesize/design/resistantmaterials/processystemsrev3.shtml

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

Kartman wrote:

you only read the uart once -

 data=usart_rx();             //--- send the received data back

Stepping 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.

 

 

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

Manish verma

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

Go 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.

 

Last Edited: Mon. Oct 30, 2017 - 12:10 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Manish verma

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

Again, 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

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

Manish verma

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

sorry - I can't read what it says in your first decision box

 

sad

 

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

 

 

Last Edited: Mon. Oct 30, 2017 - 01:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
I can't read what it says in your first decision box

If I zoom in, all I see is:

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

Sorry I was not aware of it...." Check response"
If yes then print ok ,if no then print error.

Manish verma

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

But 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?

Last Edited: Mon. Oct 30, 2017 - 05:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Awneil 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

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

This 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.

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

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.

And sorry if i irritated you any how.

Manish verma

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

staring.net@gmail.com wrote:
Kartman sir i am not pleading with you to spoon feed me.

I'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 http://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

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

Fundamental 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:

Flowchart - 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 ...

 

 

 

Last Edited: Tue. Oct 31, 2017 - 09:16 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Please have a look over here.

#include<avr/io.h>              
#include<avr/interrupt.h>
#include<string.h>
void usart_init();  
unsigned char usart_rx();
void usart_tx(unsigned char send_data);
void usart_tx_string(unsigned char send_string_tx[]);
unsigned char rx_usart[30];
unsigned char receive_data;
int main()
{ 
   unsigned char AT[]="AT\r\n";
   unsigned char CIPMUX[]="AT+CIPMUX\r\n";
   usart_init();
   sei();
   usart_tx_string(AT);
   usart_rx();
   while(receive_data!='\r')
   {
   usart_rx();
   usart_tx(receive_data);
   }
   usart_tx_string(CIPMUX);
   while(1)
   {
      
   }
}
void usart_init()
{
    UBRRL = 51;                       //--- Baud Rate Set as 9600 by Data Sheet
    UCSRB = (1<<TXEN) | (1<<RXEN);      //--- Transmit and Receive Enable
    UCSRC = (1<<URSEL) | (3<<UCSZ0);    //--- 8 bit data and UCSRC is selected
}
void usart_tx(unsigned char send_data)
{
   UDR=send_data;
   while(!(UCSRA&(1<<UDRE))); 
}
void usart_tx_string(unsigned char send_string_tx[])
{
   unsigned char i=0;
   while(send_string_tx[i]!='\0')
   {
      usart_tx(send_string_tx[i]);
      i++;
   }
}
unsigned char usart_rx()
{ 
   while(!(UCSRA&(1<<RXC)));
       receive_data=UDR; 
      return receive_data;

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

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

You're not listening, are you?

 

How many times has it been said already: 

 

Do NOT just jump in and start throwing 'C' code into your editor !!

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

staring.net@gmail.com wrote:
please have a look on it

No.

 

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?

 

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

I 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

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

staring.net@gmail.com wrote:
I am listening

No, you clearly are not.

 

i was just completing my codes

Which is what you have specifically been told not to do!!

 

How, then, can you say you are listening?!

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

But 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

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

Nobody 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.

 

Bart Simpsons Chalkboard

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

awneil wrote:
Nobody asked you to write any code.

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.

 

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

ok Sorry !! first i make flow chart then i'll go further.

Manish verma

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

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.

 

I showed you an example in #63.

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

Noted.

Be back as soon as possible after completing what you said.

Thanks.

Manish verma

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

No need to rush.

 

Take your time.

 

Think carefully; review everything.

 

 

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

I 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.

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

^awneil

 

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

John_A_Brown wrote:
maybe in a Jesuit programming school
People often says "LOL" but don't really mean they laughed out loud. I just did. Priceless !!!

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

OK, for once it wasn't me that started OTing, so there! Still...

clawson wrote:
People often says "LOL" but don't really mean they laughed out loud. I just did. Priceless !!!

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!

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"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]

Last Edited: Wed. Nov 1, 2017 - 03:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This video contains content from Fremantle International, who has blocked it in your country on copyright grounds.

sad

 

But it's an Epidsode of QI.

 

laugh

 

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 ...

 

laugh

 

EDIT

 

https://www.youtube.com/watch?v=...

 

Thank you, Google!

 

Last Edited: Wed. Nov 1, 2017 - 04:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello 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

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

"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 intimidation patience.

Quebracho seems to be the hardest wood.

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

heartThanks. heheh

Manish verma

Pages