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

1. I want to connect it to my router at home and send commands with my phone to the esp/arduino. I want to program my arduino, not to use the mcu on the esp, only the wifi.
2.ESP modul i am a newbie. I have read many articals og seen many videos, but can't figur it out.
3. I have used usart to many things before, but not worked to "talk" with the esp.

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

Most of the esp modules come with the AT command code already loaded. There's lots of examples on how to connect it to Arduino on the web.

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

Yeah with the Arduino App, but I want to use Atmel studio and start from bottom..:)

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

Hentze90 wrote:

Yeah with the Arduino App, but I want to use Atmel studio and start from bottom..:)

No, even without any Arduino in the room, most ESP modules have the AT stuff already loaded.

 

Quebracho seems to be the hardest wood.

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

I know, but I want to use the ESP to tell my MEGA2560 what to do via USART.

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

You want to start from the bottom, but yet have no idea how to do it but yet there's many working examples. You've got a mega2560, so why not try the Arduino solution first, then try converting the code away from Arduino. You don't even need an Arduino board - the tools generate a file you can flash directly.

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

Ok I have read many commands, and I want to use them, but I only have an mega2560 so to execute an command to the i have to get the esp and mega connected via usart, and i will use the commands pre defined. But i can't get any thing from the esp.
The esp constantly have at red LED turnd on is that ok?

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

What ESP module do you have?
http://www.allaboutcircuits.com/projects/breadboard-and-program-an-esp-01-circuit-with-the-arduino-ide/

Tells me the red led is the power led. At least you have power.

Note that the Arduino mega is just a mega2560 on a pcb with some connectors, crystal and a usb to serial converter - there is no magic. You can look at the schematic to find out what pins on the connectors go to pins on the mega2560. You will need a crystal on your mega2560.
All your questions are answered by Google.

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

Hi Kobidon,

 

Use baudrate 9600, it will work.

Maulik

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

Here's a library I wrote, may be helpful, https://github.com/Soulhealer95/...

 

Soul

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

hello friends , i stucked at some place while working with Atmega32A and ESP8266-01.

I made a program and it send 3 commands

AT

AT+CIPMUX=1

AT+CWSAP="SSID","PASS"

And i m using Serial monitor to analyse the ESP response Towards send commands, so what i am receiving is

AT

OK

 

 

thats it it stucked there.....

 

i m giving them delay of 200 ms 

but when i remove delay it shows

AT

AT+CIPMUX=1

AT+CWSAP="SSID","PASS"

busyp...

OK 

 

which means it respond to 1st command only rest were untouched i guess not even read by esp.

Please help.

Manish verma

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

staring.net@gmail.com wrote:
And i m using Serial monitor to analyse the ESP response Towards send commands, so what i am receiving is

AT

OK

So you have the Echo enabled on the module, then?

 

that is, every character you send to the modules it sends straight back to you as an "echo" ?

 

Terminal           Module
       A ---->
             <---- A      -- echo!

       T ---->
             <---- T      -- echo!

      \r ---->
             <---- \r     -- echo!
             <---- \n

             <---- O      -- response
             <---- K
             <---- \r
             <---- \n

 

EDIT

 

Highlight echoes & response 

Last Edited: Thu. Oct 26, 2017 - 12:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:
i m giving them delay of 200 ms 

 

Noooooooooooo!!!!

 

Do not use "blind" delays: http://www.avrfreaks.net/comment/2139451#comment-2139451

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

yes i have echo enabled on my esp, 

NOW I'VE TRIED after disabling ECHO by ATE0

but the result be like with delay

 

 

OK

then nothing

 

and without delay

AT

AT+CIPMUX=1

busy p...
AT+CWSAP="ssid","pass"

busy p...

OK

Manish verma

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

See: http://www.avrfreaks.net/comment... and read through to the end of the thread.

 

See also: http://www.avrfreaks.net/comment... and read through to the end of the thread, where you will find links to some AT Command Libraries - including one specifically for the ESP8266

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

kindly guide me like what to code for waiting for response.

I did tried that. but i guess that was totally wrong.

 

#define F_CPU 8000000UL               //using 8 MHz crystal
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>
#include <stdio.h>

unsigned char interface_var = 0;
unsigned char counter[34];
unsigned char var = 0;
unsigned char receive_data;         //variable to store received data

void usart_init(void)
{
    UCSRB |= (1<<TXEN) | (1<<RXEN) | (1<<RXCIE) ; //  enable receive transmit of usart
    UCSRC = (1<<UCSZ1) | (1<<UCSZ0) | (1<<URSEL);
    UBRRL = 51; //  baudrate = 9600 , Fosc=8MHz
}
void usart_send( unsigned char ascii)
{
    while(!(UCSRA & (1<<UDRE)));              //Usart sending function
    UDR = ascii;

}
unsigned char usart_receive(void)
{
    while (!(UCSRA & (1<<RXC)));             // usart receiving function
    return UDR;
}
void send_AT( unsigned char message[])
{
    unsigned char i=0;
    while(message[i] != '\0')                 // for send AT commands like AT+CIPMUX
{
    usart_send(message[i]);   // This sends data to esp-01
    i++;

}
}
int main()
{
    //OSCCAL = 0xA9;
	MCUCSR=1<<JTD;
    MCUCSR=1<<JTD;                  // to disable jtag for proper fuctioning of PORTC
   DDRC=0xFF;
   PORTC=0XFF;
    unsigned char AT[] = "AT\r\n";
    unsigned char CIPMUX[] = "AT+CIPMUX=1\r\n";
    unsigned char CWSAP[] =  "AT+CWSAP=\"ESP_002\",\"1234test\",4,3\r\n";         // commands 

    _delay_ms(200);

    usart_init(); // initialize usart
    _delay_ms(500);
    sei();

    _delay_ms(200);
    send_AT(AT);                    // sending AT\r\n

    send_AT(CIPMUX);   

    _delay_ms(2000);
    send_AT(CWSAP);

    while(1)
    {   

    }//while(1) close

}// main close

ISR(USART_RXC_vect)    // Every time an AT command is sent correctly type OK on the LCD (Logic analyzer works better though :-p)
{

}

this is my code.

and the missing part for reciving is deleted already by but i show u what was that

ISR(USART_RXC_vect)
{
    received_data=UDR;    
}



while(received_data!="ok")
{
    PORTC^=1<<0; //toggle led

 

Manish verma

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
while(received_data!="ok"

How is that going to work? C won't do a string compare for you - you need to do this using the likes of strcmp().

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

Kartman wrote:

while(received_data!="ok"

How is that going to work? C won't do a string compare for you - you need to do this using the likes of strcmp().

And besides:

staring.net@gmail.com wrote:

unsigned char receive_data; //variable to store received data

 

an unsigned char can only hold one single character!

 

It does seem that you need to brush-up on some of your 'C' basics.

Here are some 'C' reference & learning resources - including a free online textbook: http://blog.antronics.co.uk/2011...

 

As is so often said here, you need to stop just flinging code into your editor and design your program.

Think about the process of receiving characters, and seeing if they form a recognised response string ...

 

eg, draw a flowchart of how you will handle this.

 

As you should have picked up from the quoted threads (you did read them, didn't you?) a State Machine would be a common approach to a problem like this.

Now that may well be a bit advanced at this stage - but it's something to bear in mind ...

 

 

Last Edited: Fri. Oct 27, 2017 - 08:03 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Note also, for plain, readable text, you should use plain char:

 

In another thread, only the other day, clawson wrote:
There are three types of "char":  

  1. char
  2. unsigned char
  3. signed char  

 

The latter two are more usually referred to as uin8_t and int8_t.

 

  • If you are using the 1 byte storage to hold 0..255 then use uint8_t,
  • if you are using it for -128 .. +127 then use int8_t
  • if you are using it to hold characters like 'h','i' then use char. Don't use char otherwise.

 

See: http://www.avrfreaks.net/comment... also #14 in that thread

 

#ThreeTypesOfChar

 

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

i tried all  those stuff but unfortunately none help me .....

i tried

1. if(received_data=='\0')

 

2.                           '\n'

                          

3.                          'K'

 

 4.                         'O'

 

But all stucked at OK .

some shows other commands but after that they shows

 

1. busyp....

2. ok

    busyp....

    busyp....

please help me...unable to serach related response code 

Manish verma

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

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.

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

 

Hmmm ... there seems to be a post missing!

 

I'm sure I wrote a post in which I advised you to set the ESP module aside for now, and just work with your AVR connected to a terminal app on a PC.

 

RealTerm is useful here, as it allows you to see the hex codes of non-printing characters - such as CR and LF

Here is a tutorial: https://learn.sparkfun.com/tutorials/terminal-basics/real-term-windows - with download link

 

Another useful tool is TeraTermhttps://ttssh2.osdn.jp/ - principally because it allows you to record a log of all sent & received data with timestamps.

 

So:

  1. Get your code to send a string - any string - to RealTerm
    Pay attention to the control characters!

     
  2. Get your code to receive a string - any string - from RealTerm.
    Agfain, pay attention to the control characters!
    Use the debugger to confirm that you are correctly receiving the string.
     
  3. ​Now get your code to recognise specific strings from RealTerm.
     
  4. Only when the above are all working, update your code to send the AT commands you want to send,
    and recognise the responses you expect.
     
  5. Add handling for error responses, and unexpected responses.
     
  6. Then - and only then - connect to an actual ESP module.

 

 

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

awneil wrote:
Use the debugger to confirm that you are correctly receiving the string

This, of course, requires that you do not disable the JTAG.

 

Disabling JTAG - certainly at this stage in the project - is (IMO) stupid: you are deliberately tying your hands behind your back when it comes to debugging your code!

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

awneil wrote:
Hmmm ... there seems to be a post missing! I'm sure I wrote a post in which I advised you to set the ESP module aside for now, and just work with your AVR connected to a terminal app on a PC.
He has "switched" the threads (hijacked this one) yesterday.

Here is the other one:

http://www.avrfreaks.net/forum/interfacing-esp8266-atmega32

 

Stefan Ernst

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

I did this because u were not there and I found this thread useful as well so I shared my problem here as well. Hope it's not against the rules. If it is then sorry... I'll make sure next time this Aint gonna happen....

Manish verma

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

staring.net@gmail.com wrote:
u were not there

Your level of patience in that thread was ridiculous. At one time you could not hold out for more than 12 minutes before adding on a "Please reply...".

 

You need to accept that things might take much longer than that. You might not know this, but the Earth is round, and at some times it is dark at a specific place, and then people tend to sleep. This can go on for 8 hours or even more. Suggest you plan for waiting for at least 24 hours before crying out for attention.

 

And yes, posting the same question in more than one place is considered bad form and manners. Apart from looking spoiled and "all over the place" there is a risk that people answer the same thing independently in the two places, whereby you effectively have wasted the time of one of those persons. Staying in your own one thread will be much more advantageous for both your progress and your reputation.

"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: Fri. Oct 27, 2017 - 02:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sternst wrote:
He has "switched" the threads (hijacked this one) yesterday

Ah - thanks!

 

Strange I did use both the search here and a google with site:avrfreaks.net and I didn't see it on either.

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

staring.net@gmail.com wrote:
u were not there

and, apparently, u weren't listening to what I said anyhow!

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

staring.net@gmail.com wrote:
u were not there
You need to realize that the various posters on this website are volunteers and do have "real" lives apart from AVRFreaks. As Johan said, "plan for waiting for at least 24 hours before crying out for attention."

David (aka frog_jr)

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

Ok let me clear myself.

This time i'll try to be more clear.

1. 

awneil wrote:

I'm sure I wrote a post in which I advised you to set the ESP module aside for now, and just work with your AVR connected to a terminal app on a PC.

  

 

Here yes I did this,

I wrote some codes and used FTDI Serial cable to communicate with PC. 

 

2. 

awneil wrote:

RealTerm is useful here, as it allows you to see the hex codes of non-printing characters - such as CR and LF

 

  1. Get your code to send a string - any string - to RealTerm
    Pay attention to the control characters!

     
  2. Get your code to receive a string - any string - from RealTerm.
    Agfain, pay attention to the control characters!
    Use the debugger to confirm that you are correctly receiving the string.
     
  3. ​Now get your code to recognise specific strings from RealTerm.
     
  4. Only when the above are all working, update your code to send the AT commands you want to send,
    and recognise the responses you expect.
     
  5. Add handling for error responses, and unexpected responses.
     
  6. Then - and only then - connect to an actual ESP module.
  

 

Yes i did used Real term not only this i've used Putty as well.

     

     1. I did get that code to send string and paid attention to control characters!

     2. I Tried to get some code for Receiving a string and succeded.(But here either i am sending or receiving strings not getting \r\n anyway).

     3. I was not clear about this point (what did you want to say), But i tried sending more than 1 command and succeded.

     4. yes all above are working and i updated my code to send the AT Commands and did recognised the reponse i wanted .

     5. At this point instead of handling errors i used esp and tried above code.(But here i can receive all the strings correctly),But....

 

But.... the problem starts here, Controller sending data and ESP receiving it as i can see that on {Real Term, Putty, and Serial monitor of Arduino}.

But Esp Stops responding after receiving any delay either it is 2ms , 20 ms ,1000 ms what  ever it is not working, then i repled bac here to ask you if you guys can help.

 

Awneil you think 

awneil wrote:
and, apparently, u weren't listening to what I said anyhow!

But it is absolutely wrong, I did every single step you say i was just aint type here and tell everything, If u are saying something that means a lot to me and i really follow that but because of some less knowledge or less experience i don't understand what did u want to say exactly and it took me some time to understand what you are saying.

JohanEkdahl wrote:

staring.net@gmail.com wrote:
u were not there

Your level of patience in that thread was ridiculous.

 

You need to accept that things might take much longer than that. You might not know this, but the Earth is round, and at some times it is dark at a specific place, and then people tend to sleep. This can go on for 8 hours or even more. Suggest you plan for waiting for at least 24 hours before crying out for attention.

 

 

sir John I was not losing my patience it was just that i was searching related stuff and fortunately found this thread which is related to mine so instead of waiting i decided to ask here as well so someone online will help me as well.

Manish verma

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

staring.net@gmail.com wrote:
sir John I was not losing my patience

Rubbish. You submitted one post at

Posted : Thu. Oct 26, 2017 - 12:44 PM

and then 12 minutes later your next post was

Posted : Thu. Oct 26, 2017 - 12:56 PM

 

Please reply...

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

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

can't expain more, Hope you understand.

Manish verma

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

staring.net@gmail.com wrote:
Esp Stops responding after receiving any delay

So, to be clear:

 

  1. You can manually send a sequence of command to the ESP from a terminal, and you see the expected replies?
     
  2. You connect your AVR to a terminal, and it sends the exact same sequence of commands - with the exact same control characters,
    and waits (not just delays) while you manually send back the exact same responses - with the exact same control characters?
     
  3. But when you connect your AVR with this code to the ESP, it "Stops responding" ?

 

 

How are you verifying, in particular, that you have all the control characters correct and identical?

 

Even more specifically, how do you know what your terminal sends when you press the 'Enter' key?

 

Rather than pressing the 'Enter' key, have you tried explicitly using Ctrl+M for CR and Cltr+J for LF ... ?

 

Have you done as I suggested in http://www.avrfreaks.net/comment... to log both sides of the communication between AVR and ESP?

 

Have you used the debugger to see exactly what your AVR code is receiving?

 

Have you drawn a flowchart of your design before just jumping into 'C' code?

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

 

  1. You can manually send a sequence of command to the ESP from a terminal, and you see the expected replies?

    yes i did see the expected replies


     

  2. You connect your AVR to a terminal, and it sends the exact same sequence of commands - with the exact same control characters,
    and waits (not just delays) while you manually send back the exact same responses - with the exact same control characters?

     


    yes


     

  3. But when you connect your AVR with this code to the ESP, it "Stops responding" ?

 


right


 

 

How are you verifying, in particular, that you have all the control characters correct and identical?


because my AT commands works when single command send but when i send more than one it stucks.[Any command accepted and response back accurate]


 

 

Even more specifically, how do you know what your terminal sends when you press the 'Enter' key?


Well for that i used a led and put a condition if received_data is same as transmitted data then toggle my led and it does


 

 

 

Rather than pressing the 'Enter' key, have you tried explicitly using Ctrl+M for CR and Cltr+J for LF ... ?


No i didn't


 

 

Have you done as I suggested in http://www.avrfreaks.net/comment... to log both sides of the communication between AVR and ESP?


Not having two ftdi cables sorry but i've used arduino uno board and yes received and transmit successfully


 

 

Have you used the debugger to see exactly what your AVR code is receiving?


Sorry but i really don't know how to use debugger, i will surely search for this tommorow 


 

 

Have you drawn a flowchart of your design before just jumping into 'C' code?


I tried but i guess i m not good at it, i just made a simple sending data, receiving data, wait for response, if yes then do this else do this and finished


 

Manish verma

Last Edited: Fri. Oct 27, 2017 - 04:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I wrote:
How are you verifying, in particular, that you have all the control characters correct and identical?

staring.net@gmail.com wrote:
because my AT commands works when single command send but when i send more than one it stucks.[Any command accepted and response back accurate]
 

Your answer bears absolutely no relation to the question I asked!

 

Again: How are you verifying, in particular, that you have all the control characters correct and identical?

 

 

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

Control characters like /r/n ?
If yes then if I send commands without them then esp stop responding and prints only transmitted data without ok response.
And with them esp respond back and ok shown

Manish verma

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

Please show the commands that you send, and the responses you receive using the same format that I did in #63 - ie, each character sent and each character received in sequence.

 

You will need to use the Forum's Code editor - as for posting source code.

 

Hint: it's easier to type it in Notepad first, then paste it into the Forum's Code editor.

 

Also show the actual code that you are currently using - taking care that it is well-formatted before you post it.

Be sure to build & test the code before you copy & paste it into the forum.

 

Your build should be "clean" - ie, no errors and no warnings.

 

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

staring.net@gmail.com wrote:
Control characters like /r/n ?

Yes.

 

if I send commands without them then esp stop responding

Which is exactly the problem you say you're having!!

 

Doesn't that tell you something?

 

EDIT

 

Note that it's /r and /n

 

It is \r and \n

 

You can't be sloppy with stuff like this in programming!

Last Edited: Fri. Oct 27, 2017 - 05:25 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry actually I am typing through mobile right now so got confused,yes it is \r\n..... it's really late here...mid night 23:00.
You can see my code at #67 I've used 8MHz external crystal,and configured fuse bits for that.
But I'll post my codes and response as per your requirement it'll need some time.

Manish verma

Last Edited: Fri. Oct 27, 2017 - 05:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

staring.net@gmail.com wrote:
Sorry actually I am typing through mobile right now so got confused, it's really late here...mid night 23:00.

So stop, then!!!

 

You're confused enough as it is without adding sleep deprivation to it!!

 

staring.net@gmail.com wrote:
code at #67

A number of mistakes have already been pointed out in that code, and you yourself have spoken of changes to it - if you're having trouble with that code, it is not surprising.

 

That code does not wait for responses - it just has blind delays.

 

So step away from the editor, get out your pencil and paper, look at the sequence in #63 and start thinking about the design of a program to handle that.

 

Start by taking the sequence in #63, and extend that to a few commands and their responses.

 

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

staring.net@gmail.com wrote:
You can see my code at #67
An empty receive interrupt is quite harmful. No wonder nothing works as expected after the ESP has sent the first response.

Stefan Ernst

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

Awneil I made changes but that code is in pc. I will update here tomorrow early morning.
And with detailed statements.
And I tried using some response commands I'll show u tomorrow.

Manish verma

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

staring.net@gmail.com wrote:
I will update here tomorrow early morning.

Again, it is important that you get good rest to be able to think clearly.

 

It is the weekend.

 

It can wait.

 

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

awneil wrote:

 

"Note that it's /r and /n"

 

Think you meant:

"Note that it's not /r and /n"

 

These things can make a difference in programming!devil

 

Quebracho seems to be the hardest wood.

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

surprise blush  laugh

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

Awneil,

Sorry i did a blunder mistake there.

Instead of analysing receive characters using PC . I was analysing ESP response which shows "OK" for related COMMANDS.

But now i tried sending Characters through PC it receives 1st command then it stop responding.

I am so messed up, please help me here,

I don't understand how to read characters of usart receive and then use them accordingly.

Please help.

Manish verma

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

staring.net@gmail.com wrote:
I don't understand how to read characters of usart receive and then use them accordingly.

Go on.

 

That is just basic UART usage - people have been doing this stuff since the first microcontrollers appeared.

 

Any book on embedded microcontrollers would cover this.

 

There must be plenty of tutorials on the interwebs ...

 

Have you checked-out the Tutorials section of this site?

 

EDIT

 

http://www.lmgtfy.com?q=AVR+UART+Tutorial

 

One of the first few hits is: http://www.avrfreaks.net/forum/tut-soft-using-usart-serial-communications

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

I did read what you ask me to, Now i'll tell you what i've got

#include <avr/io.h>
#define F_CPU       8000000UL   //--- CPU Clock Frequency
#define BAUD RATE   9600        //--- Transmission Baud Rate
#include<stdio.h>
void usart_init(void);      //--- Usart Initialize
void usart_tx(char x);      //--- Usart Transmit
char usart_rx(void);        //--- Usart Receive
void usart_msg(char *c);    //--- Usart Transmit String
void send_AT( unsigned char message[]);
char tx_data;

int main(void)
{
    unsigned char data;
    usart_init();                       //--- Usart initializing
    usart_msg("INITIALIZING USART");    //--- Send a set of String
    usart_tx(0x0d);                     //--- Cmd to jump to next line
    unsigned char ATE1[] = "ATE1\r\n";
    unsigned char AT[] = "AT\r\n";
    unsigned char CIPMUX[] = "AT+CIPMUX=1\r\n";
    unsigned char CWSAP[] =  "AT+CWSAP=\"ESP_003\",\"1234test\",4,3\r\n";
   usart_msg("<<");
         send_AT(ATE1);         //--- Receive the data from rxd
         usart_tx(0x0d);                //--- Next Line
         usart_msg(">>");
         data=usart_rx();             //--- send the received data back
         usart_tx(0x0d);                //--- Next Line
       while(data=='k')
       {
	  send_AT(AT);
	  data=0;
       }
       while(data=='k')
       {
	  send_AT(CIPMUX);
       }

    while(1)
    {

    }
}

//--- Proto Type Declaration ---//

void usart_init()
{
    UBRRH = 0x00;                       //--- Initialize UBRR value for Baud Rate
    UBRRL = 0x33;                       //--- 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(char x)
{
    UDR = x;                            //--- Move data to UDR Data Reg
    while (!(UCSRA & (1<<UDRE)));     //--- Check whether UDR is empty
}

char usart_rx()
{
    while (!(UCSRA & (1<<RXC)));      //--- Check whether Receive is complete
    return(UDR);                        //--- Return Data from UDR
}

void usart_msg(char *c)
{
    while (*c != 0)                     //--- Check for null
        usart_tx(*c++);                 //--- Increment the pointer
}
void send_AT( unsigned char message[])
{
    unsigned char i=0;
    while(message[i] != '\0')
{
    usart_tx(message[i]);   // This sends data to esp-01
    i++;

}
}

Not when i press k it shows AT but after that i need another 'k' to get CIPMUX command but it stucks.\

 

Manish verma

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

Read #72 again.

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

I just want like this.

ATE1
OK    ---after receiving this ok go further else wait for ok

AT
OK     ---after receiving this ok go further else wait for ok

AT+CIPMUX=1
OK      ---after receiving this ok go further else wait for ok

AT+CWSAP="SSID","PASSWORD",3,4
OK       ---after receiving this ok go further else wait for ok

Just this.

Manish verma

Pages