john1993, I fear you're telling me something useful, but I don't have enough domain knowledge to know what it means. "i calibrate by hitting return at 9600 and storing the value in ee" - I'm not sure what 'hitting return' refers to here.
Coding Badly though - thanks, that was really useful! I started out trying Tiny Tuner 2, but it looks like it relies quite heavily on TinyCore, which doesn't seem to be ported to the ATmega8? I therefore looked at Tiny Tuner (1). It also wasn't ported, but being self-contained, it was pretty easy to get it working with the help of a data sheet. An extra:
#elif defined( __AVR_ATmega8__ )
typedef TinyTunerTemplate<0x10,0> Mega8Tuner;
typedef Mega8Tuner TinyTuner;
#else
in TinyTuner2.h, and a #if defined( CLKPR )
around the references to CLKPR were all it took, IIRC. I then modified the "Save_to_EEPROM" sketch (the serial communication broke down so early that it didn't even get through the headers on the interactive ones!) as so:
/*==============================================================================
Copyright 2010 Rowdy Dog Software.
This file is part of TinyTuner.
TinyTuner is free software: you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option)
any later version.
TinyTuner is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with TinyTuner. If not, see <http://www.gnu.org/licenses/>.
Inspired by the work of oPossum (Kevin Timmerman)...
http://forums.adafruit.com/viewtopic.php?t=5078
==============================================================================*/
/*==============================================================================
The purpose of this example is to determine the optimal calibration register
value based on input from a serial port and store the value at EEPROM
address zero.
================================================================================
ATtiny84 Instructions...
- Select the correct board / serial port
- Upload this Sketch to the processor
- Connect PB1 / Pin 1 to transmit on the serial converter
- Connect an LED + resistor --> ground on PA6 / Pin 4
- Start your favorite terminal program, open the correct serial port, change
the baud rate to 9600
- Reset the processor
- Continue sending single 'x' characters (no carriage-return; no line-feed)
until the LED glows solid. As each 'x' is sent, the LED should blink.
- The calibration register value is stored at EEPROM address zero
================================================================================
ATtiny85 / ATtiny45 Instructions...
- Select the correct board / serial port
- Upload this Sketch to the processor
- Connect PB4 / Pin 4 to transmit on the serial converter
- Connect an LED + resistor --> ground on PB0 / Pin 0
- Start your favorite terminal program, open the correct serial port, change
the baud rate to 9600
- Reset the processor
- Continue sending single 'x' characters (no carriage-return; no line-feed)
until the LED glows solid. As each 'x' is sent, the LED should blink.
- The calibration register value is stored at EEPROM address zero
==============================================================================*/
#include <EEPROM.h>
#include <TinyTuner.h>
#include "s2eLed.h"
#define PinLED 13
void setup( void )
{
pinMode( PinLED, OUTPUT );
}
void loop( void )
{
TinyTuner tt;
bool KeepGoing = true;
digitalWrite( PinLED, HIGH );
while ( KeepGoing )
{
KeepGoing = tt.update();
digitalWrite( PinLED, LOW );
delay( 100 );
digitalWrite( PinLED, HIGH );
delay( 100 );
}
uint8_t Temp = OSCCAL;
EEPROM.write( 0, Temp );
Serial.begin( 9600 );
if ( EEPROM.read(0) == Temp )
{
digitalWrite( PinLED, HIGH );
while(1) {
Serial.print( "OSCAL = " );
Serial.print( OSCCAL, HEX );
Serial.print( "\r\n" );
delay(1000);
}
}
else
{
digitalWrite( PinLED, LOW );
}
while ( 1 );
}
connected up on a breadboard in the usual arduino-like circuit, and I got a calibration value out - and stable serial communication at last!
That brings up some more questions though. It looks to me from the data sheets that the calibration value in the "signature row" is not re-writable, even with avrdude? Which means that OSCCAL must be re-written manually after startup?
If I'm correct here, I guess I'd need to modify the bootloader to be able to have stable serial communication with the Arduino IDE?
In that case, I think you're right and I may as well just continue to use Arduino-as-an-ISP. My application isn't even that timing sensitive, so I suppose I don't even actually need to calibrate the oscillator if that's the case!
Still, I've learned a lot - thanks for all your help!