QuoteThe problem is simply that sometimes the module's output frequency doesn't change.That code will only set the modules output frequency to one value once per run only. Therefore if you run the code again it will not change. Only when you power it down will it change.Quotebut sometimes things work.That points to decoupling problems. Where are the output wires going to? Maybe this is causing interference that is being picked up. I would add extra decoupling capacitors to the supply.
The problem is simply that sometimes the module's output frequency doesn't change.
but sometimes things work.
I would check that the pull ups are actually enabled as that could cause those sorts of problems as well.I would use a large capacitor across the supply at the module end. Start with 47uF and work up to 1000uF.The other thing that could cause this is the I2C clock geeing too fast but I don't see how that can be the case.Can you examin the waveforms on a scope?
Welli am running out of ideas. Any chance of posting a photo of your setup?