# atmega128 doesnt return from function even if Extended.M103 fuse bit is disabled

Hi I know i should n't be using atmega128 but it will take some time to replace besides there are 100's of PCB already in making. my problem is, if you look at the main() i have declared each function just once , at first it seems like my program was never leaving the intialize_ESP8266() function because i had the TX of my 128 connected to arduino and i was seeing this on serial monitor

AT+CWMODE=3
BT+CIPMUX=0
AT+CWMODE=3
BT+CIPMUX=0
AT+CWMODE=3
BT+CIPMUX=0
AT+CWMODE=3
BT+CIPMUX=0
I dont understand where the problem exactly is a similar problem occured before but it was solved when i disabled the M103 fuse bit.


char AT_Command_Mode[]="AT+CWMODE=3\r\n@";
char AT_Command_Single_Connection[]="BT+CIPMUX=0\r\n@";

void Initialize_usart()
{
UBRR1L=103;
UCSR1B|=(1<<TXEN1)|(1<<RXEN1)|(1<<RXCIE1);
UCSR1C|=(1<<UCSZ10)|(1<<UCSZ11);
}

void intialize_ESP8266()
{

int Wifi_buffer_counter=0;
while(AT_Command_Mode[Wifi_buffer_counter]!='@')
{
while(((UCSR1A&(1<<UDRE1))==0));
UDR1=AT_Command_Mode[Wifi_buffer_counter];
_delay_ms(10);
Wifi_buffer_counter++;
}
_delay_ms(3000);
Wifi_buffer_counter=0;
while(AT_Command_Single_Connection[Wifi_buffer_counter]!='@')
{
while((UCSR1A&(1<<UDRE1))==0);
UDR1=AT_Command_Single_Connection[Wifi_buffer_counter];
_delay_ms(20);
Wifi_buffer_counter++;
}
_delay_ms(3000);

}

void timer_initialization()
{
TCCR0 = (1<<CS02)|(1<<WGM01)|(1<<COM01)|(1<<CS00)|(1<<CS01);
OCR0 =50;
TCNT0=0;
TIMSK = (1<<OCIE0);
sei();
}
ISR(TIMER0_COMP_vect)
{
shift_out_data2(data,digit_number);
digit_number++;
if(digit_number==5)
digit_number=0;
}

int main(void)
{
DDRC=0b00111100;
int number=0;

Initialize_usart();
intialize_ESP8266();
timer_initialization();
while (1)
{

}

}


Here are a few things that i tried i put this chunk of code in different places of my code to see where my Instruction pointer was actually reaching

 PORTC &= 0b11011111;   //LED attached to pin 5 of PORT C
_delay_us(1000);
PORTC |= (1<<5);     // LED TURN OFF


The LEd turns on after several iteration of Initialize_ESP8266() function and stays on and the USART stops it doesn't transmit anything the program looks kind of stuck for few seconds (with LED still on) and then goes back to the same iteration of ESP8266 function. Here i noticed that my ISR miracoulously starts working because i can then see digits on my seven segments.

Then i tried putting this code between Timer intialize() function and intialize_ESP8266() function and it blinked for 1 second after every iteration of initialize_ESP8266 function as if these three function were in some kind of a loop.

Finally i tried putting this code inside my ISR (only the first line ofcourse without delay) and the led is on continuously but then as soon as i put some code in while() it stopped working

Does it make sense to anyone???

I have attached an image depicting the fuse bits ... i am using 16MHz oscillator