Batch programming ATMEGA8 with 8MHz Internal RC

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

Hey all,

i have to program a batch of ATMEGA8s that are going to use their internal RC oscillator. I have worked out how to automate the fuse setting programming but can't see a real simple way to automate the OSCCAL loading part.

ie... read calibration byte and put it into a select EEPROM position

Was thinking perhaps someone has already done such a thing... don't wan't to go reinvent the wheel.

(running Winavr & cygwin tools)

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

I assume avrdude can do this. Read the OSCCAL value into a file and write the file to the eeprom.

I never used avrdude because it is not compatible to my programmer, so my proposal isn't verified.

HTH

Volkmar

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

Ok, I figured it out, I've decided to post my solution in here for other freaks future reference, please feel free to comment on my approach.

Basically I read the calibration bytes into a file, then load that file into eeprom. This fills the 1st 4 bytes of eeprom. I then read the correct eeprom memory value into my OSCCAL register... script file is as follows...


#!/bin/sh
# This is a simple script that will
# Read calibration bits into file
avrdude -c stk500 -p m8 -P com4 -U calibration:r:"calib.hex":r
# Erase then Write Program memory, EEPROM, and Lfuse - result is 8Mhz calibrated
# Oscillator system
avrdude -c stk500 -p m8 -P com4 -e -U flash:w:main.hex -U eeprom:w:calib.hex -U lfuse:w:0xe4:m

To load OSCCAL register in uC operation mode add the following lines to your code...

#define CALOSC (uint16_t *)0x03 //address in EEPROM of OSCCAL
This will assign the 8mhz calibration byte eeprom memory address to CALOSC

In regular code area write:
OSCCAL=eeprom_read_byte(CALOSC);
This should load the OSCCAL register with the tune value stored at eeprom address CALOSC.

I hope this helps

oddbudman

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

Sorry if this is a not working sollution but it might be worth a try...:

Can't you program the OSCCAL byte from within your embedded software ? Connect a frequency of, lets say, 1 kHz to an input and change the OSCCAL until this frequency is measured correctly