tito-t:
why do you talk about "overclocking"? That is not my goal, just clocking at the desired clock speed of 400kHz and perhaps even faster.
Because you said this:
tito-t:
I want to test different i2c devices on different boards if they work with i2cclock speeds of 10000, 100000, 400000, and 1000000 Hz, theoretically perhaps even at 3400000.
You haven't really said what you are really trying to do or what core you are working with so it is a bit of a XY problem, leaving us to guess details about what are trying to accomplish.
Given you seem to be wanting to test a slave with multiple clock rates,
I had assumed that you are trying to test different i2c clock speeds to determine what works and what doesn't, to create something in s/w that can automatically determine the maximum supported clock rate for a i2c slave that "works".
Others like septillion seem to have made the same assumption.
If that is what you are trying to do, you will end up overclocking the slave since the s/w wouldn't know the maximum clock rate of the slave and would keep increasing the clock until it overclocks the slave and something stops working or locks up.
Finally those clock speeds are supported both by some MCU boards and also by some devices.
My goal is to see, which i2c masters will work with which devices at which speed. But for that goal I need to have reliable clock speeds first, and to know, if the speed is set to n Hz and works at n Hz reliably if I had initially set Wire.setClock(n) , apart from having to evaluate tons of data sheets.
The datasheet is what you tells you the maximum clock rate the slave chip is specified to handle so you will need to be looking at datasheets.
Pretty much any Arduino core can support 100k, 400k, and 1M clocks so if the slave supports the clock rate, and the wiring isn't crazy and proper pullups are used, it is going to work.
Often chips can be overclocked much faster than what is specified in their datasheet. For example, PCF8574 chips are specified to only go to 100Khz, but they do work reliably at 400Khz at room temperatures at 5v.
But keep in mind that slaves are often not reliable when overclocked and can misbehave when overclocked.
i.e. they don't hard fail when you get to the magic tip over point; they often start misbehaving which can confuse the master h/w or s/w.
Doing a scan like what the scanner sketch does, is not a good test if the slave supports the i2c clock rate being used.
All it does is select the slave and then disconnect and look for the ack from the slave.
It doesn't actually move any data.
A PCF8574 chip will usually pass that test with a 1MHZ clock but will fail to reliably transfer actual data at 1Mhz.
When playing at this level, you are likely going to have to start digging into the actual library code.
And each core is a bit different in how it works so if you intend to run on multiple cores, you will have to closely examine each core you are planing on using.
In pretty much all the cores, when you call Wire.begin() it initializes the i2c hardware for master mode which includes setting the master clock to its default rate.
The AVR core uses TWI_FREQ for the default i2c clock which is defined to be 100000L or 100Khz in twi.h, but all the cores use 100k as the default clock.
If you want to change the i2c clock from its default you must call setClock() after you call begin() since begin() will set it to the default clock rate (100k) when it initializes the i2c h/w.
i.e. call begin() then you can call setClock() at any time to change the master clock.
There is no need to call begin() again when changing clock rates.
--- bill