ESP8266 misses some data sent by UART (Interfacing with AVR ATmega32)

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

First of all, I apologize in case I make some mistakes posting this question. I'm writing from Argentina and I'm trying to send data from ATmega32 (via UART) to ESP8266, and ESP8266 re-transmits this data on the air (via WiFi).

The problem is that some data is missing SOMETIMES, and sometimes it is sent OK.

For example, if I send voltage, frequency and current values, I would like to receive in my computer this data in cyclic sequence, like the following

 

"220.00" [V]
"10.000" [A]
"50.00" [Hz]
"220.00" [V]
"10.000" [A]
"50.00" [Hz]
"220.00" [V]
"10.000" [A]
"50.00" [Hz] 

However, I see something like this

 

"220.00" [V]
"50.00" [Hz]
"220.00" [V]
"10.000" [A]
"50.00" [Hz]
"220.00" [V]
"50.00" [Hz]

As you see, some data is missing (not always the same field, neither all the time).

The code is the following.

 

        int main(void)
{

    char _buffer[150];
    uint8_t Connect_Status;


    USART_Init();           /* Initiate USART with 115200 baud rate */
    sei();                  /* Start global interrupt */

    while(!ESP8266_Begin());
    ESP8266_WIFIMode(BOTH_STATION_AND_ACCESPOINT);/* 3 = Both (AP and STA) */
    ESP8266_ConnectionMode(SINGLE);     /* 0 = Single; 1 = Multi */
    ESP8266_ApplicationMode(NORMAL);    /* 0 = Normal Mode; 1 = Transperant Mode*/

    if(ESP8266_connected() == ESP8266_NOT_CONNECTED_TO_AP)
    ESP8266_JoinAccessPoint(SSID, PASSWORD);
    ESP8266_Start(0, DOMAIN, PORT);
    while(1)
    {
        Connect_Status = ESP8266_connected();
        if(Connect_Status == ESP8266_NOT_CONNECTED_TO_AP)
        ESP8266_JoinAccessPoint(SSID, PASSWORD);
        if(Connect_Status == ESP8266_TRANSMISSION_DISCONNECTED)
        ESP8266_Start(0, DOMAIN, PORT);


        switch (counter)

        {

        case 0: memset(_buffer, 0, 150);
                sprintf(_buffer,"220.00");
                ESP8266_Send(_buffer);
                counter++;
                _delay_ms (500); /* Thingspeak server delay */
        break;

        case 1: memset(_buffer, 0, 150);
                sprintf(_buffer,"10.000");
                ESP8266_Send(_buffer);
                counter++;
                _delay_ms(500); /* Thingspeak server delay */
        break;


        case 2: memset(_buffer, 0, 150);
                sprintf(_buffer,"50.00");
                ESP8266_Send(_buffer);
                counter++;
                _delay_ms(500); /* Thingspeak server delay */
        break;

        }

    }
}

Thanks for any help. Dario

Making progress in Firmware Design. Bit by bit, Step by step.

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

Hi friend.

Is that your own code or you copy it somewhere? If you copy it, then ask the author.

 

The classic mistake of AT command is people pretend to skip the response time. Each AT command has a different length time. To make it easy, the longest time is chosen. That is not correct.

You need to wait until the response finished.

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

Thanks for your help flycatnguyen, I've found the mistake. It was a HARDWARE problem, just becasue ESP8266 presents peaks of current, so my 3.3V regulator was too weak.

 

In that peaks, ATMega32 detected 0 instead of 1 in some characters, so it retransmitted wrong values. I solved the problem by changing the regulator from a TO-92 to a TO-220 one.

 

Thanks..!

 

Dario.

Making progress in Firmware Design. Bit by bit, Step by step.