PIC18F4525 to DAC (PCF8591P) I2CWrite too fast?
I have an I2C compatible DAC (PCF8591P) that I've connected to the SCL/SDA of my PIC18F4525. I'm using the following code to program it, and an external 20MHz oscillator to the PIC. The output of the DAC should simply ramp from 0 to 5V repeatedly, but I'm getting some weird noise from it when I look at it from the oscilloscope. I checked the output of SCL to see what frequency it is and the oscillator says that its around 1MHz! Is that normal? I thought standard I2C is normally run at 100kHz...
It feels like that the communication synchronization would occur if the SCL/SDA was slowed down to 100kHz, but I don't know how to do that in code, or what I should change in the code. I'm pretty inexperienced in PicBasic Pro, so any help you could provide would be appreciated.
Code:
DEFINE OSC 20 '20 MHz external oscillator
SDA var PORTC.4 'SDA port
SCL var PORTC.3 'SCL port
Loop VAR Byte
DACAddressByte con %01001000 ' DAC Address byte (7-bit address: 1001 000)
DACControlByte con %01000000 ' DAC control byte (sets DAC to D/A:0100 0000)
start:
For Loop = 0 To 255 'ramp up
I2CWRITE sda,scl,DACAddressByte,DACControlByte,[Loop] 'I2CWrite
Pause 10 'wait for write
Next
GoTo start