mega1284p and esp8266 communication

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

Hi guys,

 

I'm currently using atmega1284p to communicate to an esp8266 chip using UART0 and seem to be having problem.

When I send any command (e.g. "AT+GMR"), i poll my receiver from my UART0 and not get anything. Below is part of the code for the receiving from UART0. It goes to 

c = UDR0;

but it goes to at

if (c == '\0') break; 

and the loop continues.

unsigned char wifi_receive(uint8_t *x, unsigned char size)
{

    unsigned char i = 0;

    if (size == 0) return 0;            // return 0 if no space
	uint8_t timeout = TIMEOUT;
    while (i < size - 1) {              // check space is available (including additional null char at end)
        uint8_t c;
        while ( !(UCSR0A & (1<<RXC0)) && timeout) {
			timeout--;
		}
        c = UDR0;
        if (c == '\0') break;           // break on NULL character
        x[i] = c;                       // write into the supplied buffer
        i++;
    }
    x[i] = 0;                           // ensure string is null terminated

    return i + 1;                       // return number of characters written
} 

 

My atmega1284p is using a baud rate of 9600 while I believe the esp8266 is using 115200. 

I've tried changing the baud rate of the atmega1284p to 115200 and did not work.

I've also tried changing the esp8266 to 9600 using

AT+UART_DEF=9600,8,0,0

Some notes:

  • I'm not using any 8266 library (e.g. https://github.com/esp8266/Arduino)
  • I've placed an oscilloscope to the 8266.. It does get a blimp at the beginning. I've tested the pinouts and it seemed to be doing the right one? VCC/GND and RX/TX.. 
  • I've tried the chip with arduino and it worked with arduino serial monitor. I also tried multiple chips to ensure its not a brick chip

 

Am I doing anything wrong? Or is there something I can try?

 

Appreciate any help in this area.

 

 

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

weeyoung wrote:
I believe the esp8266 is using 115200. 

Can you look at 8266 arduino lib to make sure the baud rate?(I think it's well proven lib?)
.
MG

I don't know why I'm still doing this hobby

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

weeyoung wrote:
My atmega1284p is using a baud rate of 9600 while I believe the esp8266 is using 115200.

What you "believe" is irrelevant - you need to confirm that.

 

This is absolutely fundamental!

 

 I've tried changing the baud rate of the atmega1284p to 115200 and did not work.

So what, exactly, did you try?

What was the result?

What did you do to investigate it?

 

 

I've also tried changing the esp8266 to 9600 

And did that work?

 

 

 

Last Edited: Tue. Sep 12, 2017 - 09:46 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What exactly are you sending to the ESP? I got mine working only after sending CR+LF after the command, a CR alone wouldn't make it.

Einstein was right: "Two things are unlimited: the universe and the human stupidity. But i'm not quite sure about the former..."

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

DO1THL wrote:
CR alone wouldn't make it

Strange.

 

Strictly, it should be just CR - not CRLF. 

 

 

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

AT Commands - including ESP8266: http://www.avrfreaks.net/comment...

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

I've also tried changing the esp8266 to 9600 using

But that won't possibly work until you have reliable communications with the 8266!

 

i.e. you need a working comm link to then send it a command to change its internal settings.

 

JC 

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

What clock speed is your AVR running at? External stall or internal RC? DIV8 fuse programmed?

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

Thanks all for the comments..  Appreciate it...

 

MicroGyro wrote:
weeyoung wrote:
I believe the esp8266 is using 115200. 
Can you look at 8266 arduino lib to make sure the baud rate?(I think it's well proven lib?) . MG

 

The arduino lib doesnt state the baud rate i think. Depending on the firmware version, baud rate is different: 9600, 57600 or 115200.. I've tested it out on the chip itself with a baud rate of 115200 and it worked. 

 

.

awneil wrote:

weeyoung wrote:
My atmega1284p is using a baud rate of 9600 while I believe the esp8266 is using 115200.

What you "believe" is irrelevant - you need to confirm that.

 

This is absolutely fundamental!

 

 I've tried changing the baud rate of the atmega1284p to 115200 and did not work.

So what, exactly, did you try?

What was the result?

What did you do to investigate it?

 

 

I've also tried changing the esp8266 to 9600 

And did that work?

 

 

 

 

I set the baud rate at atmega1284p as follows:

#define TIMEOUT 250

#define F_CPU 1000000UL //1600000UL


#define BAUD 9600 //   115200 //


//! set the baud rate tolerance to 2%
#define BAUD_TOL 3

I also checked the baud rate as follows:

 char baud[100];
	 dtostrf(BAUD , 2, 2, baud);
	char fcpu[100];
	 dtostrf(F_CPU , 2, 2, fcpu);
	 char ubrrh[100];
	 dtostrf(UBRRH_VALUE , 2, 2, ubrrh);
	 snprintf(sm, 700, "F_CPU, Baud Rate and UBRRH_VALUE is %s, %s and %s.\r\n", fcpu, baud, ubrrh);

And it shows the correct baud rate as I defined above.

 

For esp8266, i set the baud rate as

AT+UART_DEF=9600,8,0,0

 

But i also noted DocJC point as per below. Hence I'm trying to keep it to 115200

DocJC wrote:

I've also tried changing the esp8266 to 9600 using

But that won't possibly work until you have reliable communications with the 8266!

 

i.e. you need a working comm link to then send it a command to change its internal settings.

 

JC 

 

awneil wrote:

DO1THL wrote:
CR alone wouldn't make it

Strange.

 

Strictly, it should be just CR - not CRLF. 

 

 

 

I tried both <CR> and <CR><LF>.. I thought both would work though. 

 

I'm only sending

AT+GMR<CR><LF>

 

However, now i'm getting a response.. Looks like i actually forgot to place a resistor at pin15-16 of the esp8266.

However, I'm getting garbage response.. like AtoAAAAAA. trying to figure out why.

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

weeyoung wrote:
I also checked the baud rate as follows:

 char baud[100];
	 dtostrf(BAUD , 2, 2, baud);
	char fcpu[100];
	 dtostrf(F_CPU , 2, 2, fcpu);
	 char ubrrh[100];
	 dtostrf(UBRRH_VALUE , 2, 2, ubrrh);
	 snprintf(sm, 700, "F_CPU, Baud Rate and UBRRH_VALUE is %s, %s and %s.\r\n", fcpu, baud, ubrrh);

And it shows the correct baud rate as I defined above.

But that doesn't tell you anything about the actual speed of the actual transmission on the actual wires - does it.

 

You've already mentioned that you have an oscilloscope - so use that to verify the actual timing on the wires.

 

Continuously transmitting 'U' will give an easy-to-measure waveform ...

 

However, I'm getting garbage response.. like AtoAAAAAA. trying to figure out why.

How, exactly, are you "getting" that? Where and how are you observing it?

 

Almost invariably, "garbage" characters means that the baud rate is wrong.