Wire.h at 20MHz

I am planning a project with an ATMega328@20MHz.
I am just curious, if the Wire.h-Library depends on the clock, which normally is 16MHz.
So, will I2C with the Wire.h-library also work, when the chip is clocked to 20MHz?

Try it and let us know.

If I had both, 16 and 20MHz Arduinos lying around, I'd never have asked. But I am not sure, which crystal to solder onto my PCB. That's why.

I did have a quick look at the source code of the Wire library and I don't expect problems.

Are you using MiniCore or some other board package that has an option for 20MHz clock frequency? I would expect the Wire library supplied with the board package to be able to handle all of the clock frequencies properly.

Using the Arduino board package for the UNO, you would need to modify the boards.txt file for 20MHz, otherwise the timing of a lot of code will be incorrect (such as the millis() counter).

I2C default speed is 100kHz on Arduino UNO (and many others). That frequency can be changed using Wire.setClock(clockFrequency).

Great, thank you all. So I will just try it with a 20MHz crystal.

@david_2018 I know, that the clockspeed affects a lot of timings, that's the origin of my question. But all others than Wire.h are not crucial for my application.

It will need some time, until I have tested this out for real, but then I will report.

You do know that you will need a different bootloader.

You will need to account for the change in serial speed, unless you intend to load code using an ISP. At least modify the boards.txt file to reflect the 20MHz clock speed, or use MiniCore which already has the option for 20MHz, and the bootloader compiled for that frequency.

So I assembled my PCB with a 20MHz crystal right now and everything works great. So thanks for all your replies.

For reference: you can absolutely drive an ATMega328 with a 20MHz crystal and use the Wire-Library. I didn't do much testing yet, but the delay()-function seems to work in time as well.

Most of us already know that.

delay()-function seems to work in time as well.

It will certainly "seem" to work.

Just of curiosity - what is the benefit of the run an Atmega on 20 MHz? Only bust the clock by 25%?
as for me it's such a small increase that you simply won't notice it.
Not to mention that there are many compatible Arduino boards with frequencies of tens and hundreds of megahertz ...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.