Go Down

Topic: MegaCore - Arduino support for ATmega64/128/1281/2561 and ATmega640/1280/2560 (Read 21982 times) previous topic - next topic

scharkalvin

I had an idea for  a mod to the bootloader.
When operating the chip at 1.8-3.3 volts it's usually necessary to lower the clock frequency by half.
There is a fuse setting that divides the xtal clock (but not by 2).   So if I'm using a mega644 at 3.3 volts, and I have a 20mhz crystal in there, we could set the fuse to divide the clock frequency (by 4 or 8 ), and then in the bootloader, reset the divider to 2.  This in case we don't have a 10mhz clock.

Oh, also we'd need to add 10mhz to the list of cpu clock frequencies for those processors that can use it.

westfw

Optiboot, if you compile it from source, supports any clock rate that you care to give it.

The fuses only permit "full speed" or "divide by 8."
It's not clear that the oscillator is spec'ed to work at full speed at low voltage; frequently when "overclocking" CPUs in general, the oscillator is the first thing to stop working (and you use an external clock generator instead.)

I think you could set the fuses for divide-by-8 and configure the bootloader for 20MHz/8, and then reset CLKPR in the beginning of your sketch to get 5 or 10MHz...


talamascool

In order to get the IRremote library to work, you'll have to manually download and install the library. You can get it from here. Click the green "clone or download" button.
hello i've tried to upload this code to an attiny2313 @8mhz internal clock.

#include <IRremote.h>

const int pin=4;
const int led=9;
int toggle=0;
IRrecv irrecv(pin);
decode_results results;

void setup() {
irrecv.enableIRIn();
pinMode(led,OUTPUT);

}

void loop() {
  if(irrecv.decode(&results)){
    if(results.value==0x1000C||0xC||0x17AB7F3E){
    if(toggle==0){
      digitalWrite(led,HIGH);
      toggle=1;
    }
    else{
      digitalWrite(led,LOW);
      toggle=0;
    }   
  }
  irrecv.resume();
}

}

pretty simple really, just trying something.

it will give me a lot of errors in the verbose, they're so many that i think is rude to post them all, but i can do if needed. but the errors look mostly like this.

G:\arduino\libraries\IRremote\boarddefs.h:217:29: error: 'WGM22' was not declared in this scope

  TCCR2B               = _BV(WGM22) | _BV(CS20); \

                             ^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro 'TIMER_CONFIG_KHZ'

  TIMER_CONFIG_KHZ(khz);

  ^

G:\arduino\libraries\IRremote\boarddefs.h:217:42: error: 'CS20' was not declared in this scope

  TCCR2B               = _BV(WGM22) | _BV(CS20); \

                                          ^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro 'TIMER_CONFIG_KHZ'

  TIMER_CONFIG_KHZ(khz);

  ^

In file included from G:\arduino\libraries\IRremote\IRremoteInt.h:111:0,

                 from G:\arduino\libraries\IRremote\IRremote.h:24,

                 from G:\arduino\libraries\IRremote\irSend.cpp:1:

G:\arduino\libraries\IRremote\boarddefs.h:218:2: error: 'OCR2A' was not declared in this scope

  OCR2A                = pwmval; \

  ^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro 'TIMER_CONFIG_KHZ'

  TIMER_CONFIG_KHZ(khz);

  ^

G:\arduino\libraries\IRremote\boarddefs.h:219:2: error: 'OCR2B' was not declared in this scope

  OCR2B                = pwmval / 3; \

  ^

G:\arduino\libraries\IRremote\irSend.cpp:119:2: note: in expansion of macro 'TIMER_CONFIG_KHZ'

  TIMER_CONFIG_KHZ(khz);

  ^

i have the feeling that the attiny is not compatible with the library.


RMRob

I'm using an AT90CAN128 in a PCB I designed. Right now i'm trying to upload a bootloader onto the board via an Atmel-ICE ISP programmer. I've added the Megacore library to the Arduino IDE and am using the 8MHZ internal RC oscillator. When I hit burn bootloader it seems to recognize the device and read/write the fuses. However I get a verification error and it fails:

         Using Port                    : usb
         Using Programmer              : atmelice_isp
avrdude: Found CMSIS-DAP compliant device, using EDBG protocol
         AVR Part                      : AT90CAN128
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     8    0 no       4096    8      0  9000  9000 0xff 0xff
           flash         65     6   256    0 yes    131072  256    512  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : JTAG3_ISP
         Description     : Atmel-ICE (ARM/AVR) in ISP mode
         Vtarget         : 4.9 V
         SCK period      : 8.00 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e9781 (probably c128)
avrdude: erasing chip
avrdude: reading input file "0x3f"
avrdude: writing lock (1 bytes):

Writing | ################################################## | 100% 0.00s

avrdude: 1 bytes of lock written
avrdude: verifying lock memory against 0x3f:
avrdude: load data lock data from input file 0x3f:
avrdude: input file 0x3f contains 1 bytes
avrdude: reading on-chip lock data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: WARNING: invalid value for unused bits in fuse "lock", should be set to 1 according to datasheet
This behaviour is deprecated and will result in an error in future version
You probably want to use 0xff instead of 0x3f (double check with your datasheet first).
avrdude: 1 bytes of lock verified
avrdude: reading input file "0xf5"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.09s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xf5:
avrdude: load data efuse data from input file 0xf5:
avrdude: input file 0xf5 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified
avrdude: reading input file "0xd6"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.09s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xd6:
avrdude: load data hfuse data from input file 0xd6:
avrdude: input file 0xd6 contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xe2"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.09s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe2:
avrdude: load data lfuse data from input file 0xe2:
avrdude: input file 0xe2 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.00s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified

avrdude done.  Thank you.

avrdude: verification error, first mismatch at byte 0x0000
         0xff != 0x0f
avrdude: verification error; content mismatch
Error while burning bootloader. 

Any ideas on how to fix this? I can provide more information if needed.

Thanks,
Rob

Go Up