I'm using a bare ATMega328P to do a lot of high-speed serial communication and I think I want to use a 14.7456 MHz crystal to better match the clock to baud rates and reduce errors over time. I'm programming the chip with a USBTinyISP programmer from the Arduino IDE. I'm not using a bootloader.
What steps (if any) do I have to take to ensure that the serial hardware in the ATMega328P gets set up correctly to account for the 14.7456 Mhz clock? I found this old thread SOLVED! ATMega328P at 14.7456 MHz - Other Hardware Development - Arduino Forum which seems to discuss the same goal but some critical messages in the thread relating to the solution appear to be missing now. I understand from what I read in that thread that delay() and friends won't be accurate at 14.7456 Mhz but I could live with that if my baud rates are correct.
Has anyone done this and can describe the software steps to take?
I understand from what I read in that thread that delay() and friends won't be accurate at 14.7456 Mhz but I could live with that if my baud rates are correct.
When not using bootloader, you have to change the crystal frequency in board.txt for your particular board, ie:
you can modify wiring.c and implement a delayMicroseconds() for 14.7456MHz...
i wrote one for 1Mhz clock:
#else
// for the 1MHz clock
// for a 8-microsecond delay, simply return. the overhead of the
// the function calls takes more than 8 microseconds. can't just
// substract eight, since us is unsigned; we'd overflow.
if (--us == 0)
return;
if (--us == 0)
return;
if (--us == 0)
return;
if (--us == 0)
return;
if (--us == 0)
return;
if (--us == 0)
return;
if (--us == 0)
return;
if (--us == 0)
return;
// the following loop takes two microsecond (4 cycles)
// per iteration, so execute it once for each two microsecond
// of delay requested
us >>= 1;
#endif
SaintGimp:
What steps (if any) do I have to take to ensure that the serial hardware in the ATMega328P gets set up correctly to account for the 14.7456 Mhz clock?
None.
In theory....
You'll need to add a new entry to "boards.txt" to tell the Arduino libraries your clock speed. After that the "Serial.begin()" function will do the math for you.