Fading LCD backlight using PWM stopps RTC?

I am currently working on this world time clock project and got it working with three alarms and automatic account for daylight saving time in central Europe.
Now I thought it would be nice to have the LCD backlight fade in with a button press and fade out after a small delay when the button is released.
To test I just added

analogWrite(backlight, brightness);

into the setup loop which works fine for the backlight for the LCD but the RTC quits with the error message "RTC stopped".

when I change the above statement again to

digitalWrite(backlight, HIGH);

everything works fine without any hick ups.

This makes me kind of believe that using PWM is interfering with the i2c bus of the RTC. If it does, is there a work around or do I have to just live with out fading the backlight with a button press.

Since I am not even sure if there is a way of going around, I attached the full code and a fritzing file of the circuit I am currently using.

Thanks for having a look at...

worldclock_bl_0_0_5.ino (18.9 KB)

clock-speaker-04.fzz (15.5 KB)

Hi divedj

Add a 4.7k pullup resistor between SDA and +5V, and the same for SCL.

And you could also try adding decoupling capacitors to the DS1307 - 0.1uF and 10uF for example.

Regards

Ray

Thanks Ray,

it looks like the two 4.7K resistors did the job.

Regards Dieter