Board time out issue : Mega 2560 with ESP8266

Hi,

i recently purchased Mega board with ESP8266 and tried to upload the sketch. My board manager was Arduino Mega (or) Mega 2560.

When i upload the sketch -> the code compiles and in the final seconds of upload i get the following error message. I tried hitting reset button -> but it does not work. Any suggestion?

**avrdude: stk500v2_ReceiveMessage(): timeout**
**avrdude: stk500v2_ReceiveMessage(): timeout**
**avrdude: stk500v2_ReceiveMessage(): timeout**
**avrdude: stk500v2_ReceiveMessage(): timeout**
**avrdude: stk500v2_ReceiveMessage(): timeout**
**avrdude: stk500v2_ReceiveMessage(): timeout**
**avrdude: stk500v2_getsync(): timeout communicating with programmer**
**An error occurred while uploading the sketch**

board - Board link

Which one of those boards were you trying to upload to?

On the Mega + ESP board there are DIP switches to set to select which processor is connected to the USB. Are they set correctly?

1 Like

i was able to execute this code in standalone Mega 2560. My objective was to send data to WiFi and that is were i procured the Mega 2560 board with Esp.

You answered neither of my questions. It is more difficult to help you if it is a one way conversation.

You posted code improperly. Did you not see a warning? Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
code tags new

1 Like

i am new the Mega 2560 + ESp8266 topic. I am not aware of the DIP switches. Is this a setting which i have to do? if yes, kindly share me some instructions.

I did upload a code which is successfully uploaded into Mega 2560 but get time out issues when i upload with the ESP8266 variant.

My objective is to run Mega 2560 sketch with the feature of ESP8266 webserver.

Best Regds
Rahul.

#include "lin_frame.h"

#define BUFF_SIZE       64
#define FRAME_BYTE      0x00
#define SYNC_BYTE       0x55
#define WHEEL_SLAVE1    97
#define WHEEL_SLAVE2    240

#define LIN_BUFF_SIZE   16

const uint8_t pinTX2 = 16;
const uint8_t pinRX1 = 19;
const uint8_t pinTX1 = 18;
const uint8_t pinCS = 8;
const uint8_t pinTXE = 13;

int i =0;

LinFrame frame;

const uint8_t
    //grLINPacket[] = { 0xF0, 0xFD, 0xD0, 0x00, 0x34, 0x00 }; //bad checksum
    grLINPacket[] = {0xC1, 0xFF, 0x0B, 0x57, 0x44, 0x51, 0xFF, 0x03, 0x90, 0xB2 };     //good msg

//give the serial ports names to make things more human-readable
HardwareSerial 
    *VehicleSimulator = (HardwareSerial *)&Serial2,
    *SerialConsole = (HardwareSerial *)&Serial;
    
enum eLINStates
{
    SEEK_FRAME_START = 0,
    SEEK_SYNC_BYTE,
    RECEIVE_FRAME_DATA,
     
};

volatile uint8_t
    rxHeadPtr = 0;
volatile uint16_t
    gruRxBuffer[BUFF_SIZE];
uint8_t    
    rxTailPtr = 0;

void setup( void ) 
{
    //UART0 (default) serial console
    SerialConsole->begin(19200);

    pinMode( pinCS, OUTPUT );
    digitalWrite( pinCS, HIGH );
    pinMode( pinTXE, OUTPUT );        
    digitalWrite( pinTXE, HIGH );    
        
    //UART2 used to simulate LIN messages; connect TX2 to RX1 for bench testing
    pinMode( pinTX2, OUTPUT );    
    VehicleSimulator->begin(19200);
    
    //UART1 to be our LIN receiver
    UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); //async operation, 8N1
    UBRR1 = 51;                         //19.2kbaud UBRR = (16MHz / 16 x 19200) - 1
    UCSR1B = _BV(RXCIE1) | _BV(RXEN1) | _BV(TXEN1);  //enable the UART1 receiver & transmitter and UART1 RX interrupt
    pinMode( pinRX1, INPUT_PULLUP );           //should be input out of reset; shown for clarity
    pinMode( pinTX1, OUTPUT );    

    SerialConsole->println( "Starting..." );

}//setup

void loop( void ) 
{
    static uint32_t
        tLIN = 0ul;
    uint32_t
        tNow = millis();

  //           SerialConsole->println(tNow );
   //  SerialConsole->println(tLIN );
   

//#if 0
    //send a test message once a second
    if( (tNow - tLIN) >= 1000ul )
    {
 SerialConsole->println( "Print debug..."+i );
 i=i+1;
        tLIN = tNow;
        
        //send a break on UART0 by disabling TX, setting the pin
        //low and waiting >10 bit times at 19200
        UCSR2B &= ~(_BV(TXEN2));        //disable transmitter to access pin
        digitalWrite( pinTX2, LOW );    //drive pin low
        delayMicroseconds( 1000ul );    //wait >>10x bit times at 19200
        digitalWrite( pinTX2, HIGH );   //set pin high
        UCSR2B |= _BV(TXEN2);           //re-enable transmitter
        delayMicroseconds( 50ul );      //wait for pin to rise and settle
        //send the sync character
        VehicleSimulator->write( SYNC_BYTE );
        //send the data
        VehicleSimulator->write( grLINPacket, sizeof( grLINPacket ) );
            
    }//if
//#endif

    //process LIN messages
    linRXStateMachine();
   delay(100); 
}//loop

void linRXStateMachine( void )
{
    static uint8_t
        stateLIN = SEEK_FRAME_START;        //LIN state variable
    uint16_t
        rx;                                 //combo of status and received byte
    uint8_t
        b,                                  //rx'd byte
        s,                                  //status
        tempHead;                           //temporary receive buffer head pointer value

    //read the head pointer
    noInterrupts();             
    tempHead = rxHeadPtr;
    interrupts();

    //if not the same as the tail pointer there are bytes to process
    if( tempHead != rxTailPtr )
    {
        do
        {
            //read the combination status and rx'd byte from the buffer
            rx = gruRxBuffer[rxTailPtr];            
            //split into the byte and status
            b = (uint8_t)(rx & 0xff);                        
            s = (uint8_t)((rx >> 8) & 0xff); 
                       
            switch( stateLIN )
            {
                case    SEEK_FRAME_START:
                    //waiting for a break indication (framing error; FE1 bit in status register)
                    //start of frame ==  framing error and rx'd a 0x00                    
                    if( (s & _BV(FE1)) && (b == FRAME_BYTE) )
                        stateLIN = SEEK_SYNC_BYTE;
                break;

                case    SEEK_SYNC_BYTE:
                    //byte immediately following the start condition should be a SYNC byte
                    if( b == SYNC_BYTE )
                    {
                        //got it; reset the LIN frame
                        frame.reset();
                        //and go get the frame
                        stateLIN = RECEIVE_FRAME_DATA;                                                
                        
                    }//if
                    
                break;

                case    RECEIVE_FRAME_DATA:
                    //if we don't see a framing error
                    if( !(s & _BV(FE1) ) )
                    {
                        //just append the received byte to the frame
                        frame.append_byte( b );
                        
                    }//if
                    else
                    {
                        //we see a break here; if we rx'd a 0x00 we
                        //are looking at the start of the next frame so we can process
                        //the one sitting in the buffer                        
                        if( b == 0x00 )
                        {
                            //if the frame is valid... frame.isValid()
                            if(true )
                            {
                                //show it
                                DumpFrame();
                               
                            }//if
                            else
                            {
                                //frame check failed
                                SerialConsole->println( "Message invalid" );
                                
                            }//else

                            //got back and wait for the sync byte
                            stateLIN = SEEK_SYNC_BYTE;
                            
                        }//if
                        else
                        {
                            //got a framing error but not an accompanying 0x00
                            //go to seek a frame start state
                            stateLIN = SEEK_FRAME_START;
                            
                        }//else
                        
                    }//else
                    
                break;
                
            }//switch

            //after each pass, advance the tail pointer...
            rxTailPtr = (rxTailPtr + 1) & (BUFF_SIZE - 1);

            //until we match the head pointer when we started this
        }while( rxTailPtr != tempHead );
        
    }//if

}//linRXStateMachine

ISR( USART1_RX_vect )
{
    uint8_t
        ch,
        s;

    //read the character and the status register
    s = UCSR1A; //need to be in this order (read status then received data) to get the right status value
    ch = UDR1;    

    //put the status byte in the most-sig. byte and the character in the least-sig byte of the word in the buffer
    gruRxBuffer[rxHeadPtr] = (uint16_t)((s << 8) | ch);
    //bump the head pointer
    rxHeadPtr = (rxHeadPtr + 1) & (BUFF_SIZE - 1);
    
}//RX interrupt


void DumpFrame( void )
{       
    if (frame.get_byte(0) != WHEEL_SLAVE2)
    {
      return;
    }
   
    for (uint8_t idx = 0; idx<frame.num_bytes(); idx++) 
    {
        uint8_t b = frame.get_byte(idx);
        if( b <= 0xf )
            SerialConsole->write( '0' );
        SerialConsole->print( b, HEX );
        SerialConsole->write( ' ' );
        
    }//for    
    SerialConsole->println();
    
}//DumpFrame

the code which works fine in Mega 2560 board. When i upload the same code into Mega 2560+ESP8266 i get time out error.

My objective was first upload this code and then add the soft access point of ESP8266

P.S -> i am using WIN OS.

i tried to use the DIP switch by enabling "1,2,3,4" and did a reset the mode.

when i flash the sketch, i get the below error.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: verification error, first mismatch at byte 0x0c00
         0xff != 0x8f
avrdude: verification error; content mismatch
avrdude: verification error; content mismatch


Finally worked : i needed to update the DIP switches :slight_smile: -> had to also update Rx3/Tx3

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.