Pages: [1]   Go Down
Author Topic: Atmega8 - compile error  (Read 456 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have sketch when is fully functional on Mega328.
Now I have some errors when I tried to compile a program for Mega8 :

C:\DOCUME~1\Notebook\LOCALS~1\Temp/cchjwH1j.s: Assembler messages:
C:\DOCUME~1\Notebook\LOCALS~1\Temp/cchjwH1j.s:29: Error: illegal opcode jmp for mcu atmega8
C:\DOCUME~1\Notebook\LOCALS~1\Temp/cchjwH1j.s:269: Error: illegal opcode jmp for mcu atmega8

I have selected board : Arduino NG w ATMEGA8...
In sketch I using WDT, HW serial, SW serial and some IF, delays and write to ports. Arduino IDE is 1.0.2

Please can you help me find source of this problem?

many thanks,
Petr
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18816
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Read this before posting a programming question

Quote
I have sketch  ...

What sketch?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I found this error.
In sketch I have function software reset, which contain :

Code:
void softReset()
{
asm volatile ("  jmp 0");            // mega8 not supported
;
}

So, when I commented it, everything is ok. I change this function to wdt reset and everything will be ok.


Petr
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18816
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The Atmega8 doesn't have a "jmp" instruction. It has a "ijmp" which jumps to whereever the Z register is pointing. This compiles (not tested on an Atmega8 but works on a Atmega328):

Code:
void softReset()
  {
 
   Serial.end ();  // if necessary
   
   asm ("cli");          // interrupts off
   
   // reset USART to reset defaults
  #ifdef __AVR_ATmega8__
    UDR = 0;
    UCSRA = _BV (UDRE);
    UCSRB = 0;
    UCSRC = _BV (URSEL) | _BV (UCSZ1) |  _BV (UCSZ0);
    UBRRL = 0;
    UBRRH = 0;
  #else
    UDR0   = 0;
    UCSR0A = _BV (UDRE0);
    UCSR0B = 0;
    UCSR0C = _BV (UCSZ01) |  _BV (UCSZ00);
    UBRR0L = 0;
    UBRR0H = 0;
  #endif
   
   asm volatile ("eor r1,r1");     // make sure zero-register is zero
   asm volatile ("ldi r16,0xFF");  // end of RAM (0xFF)
   asm volatile ("sts 0x5E,r16");  // SPH
   asm volatile ("sts 0x5D,r16");  // SPL
   asm volatile ("eor r31,r31");   // Clear Z register
   asm volatile ("eor r30,r30");
   asm volatile ("ijmp");          // jump to (Z)
  }

void setup ()
  {
  Serial.begin (115200);
  Serial.println ("Entering setup.");
  }  // end of setup

void loop ()
  {
  delay (2000);
  softReset ();
  }  // end of loop
 

I put some extra stuff in there, because Optiboot (bootloader) expects certain things, like the stack pointer to be correct, and the USART to be in a default state.

I should point out however that this is not the same as doing a hardware reset (pushing the reset button). All this does is jump back to the start of the code. It doesn't set IO ports back to inputs, and things like that.

Really, you should never need to do a software reset like that. A "watchdog" reset would be better because that is an actual reset.

Logged


Pages: [1]   Go Up
Jump to: