Mmm... To eliminate things, I tried to use i2cread/i2cwrite on PORTB.4 (Clock) and PORTB.5 (Data), but this also doesn't seem to work.
TRISB=0 sets the outputs to a solid low level, but the I2C commands are still not working.
Mmm... To eliminate things, I tried to use i2cread/i2cwrite on PORTB.4 (Clock) and PORTB.5 (Data), but this also doesn't seem to work.
TRISB=0 sets the outputs to a solid low level, but the I2C commands are still not working.
You need those pull-up resistors on both pins for I2C.
2.2 or 4.7K.
DT
Yes, I know that this is an often made mistake.
But of course I have those pull-up resistors connected!
The strange thing is that everything worked fine with a PIC18F4550, but not with a PIC 18F14K50.
When I look with an oscilloscope on the data and clock lines, I don't see any signal at all while sending an I2C command.
Last edited by RuudNL; - 27th February 2012 at 18:23. Reason: Typo
Don't do that.
I2C requires the pins to be in INPUT mode when not transfering data.
The pins are never driven high, only low, which is why you need the pull-up resistors.
Since it's a 14K50, you're probably running at 48Mhz.
So you may want to add ...
DEFINE I2C_SLOW 1
Depending on if the device you're talking to is a 100Khz I2C part.
If it's a 400Khz part, you won't need it.
DT
I know...
The only reason I tried TRISB=0 is because I wanted to check if I could use the pins as a digital output.
In the meantime I found the problem. In fact, it had nothing to do with the i2cread/i2cwrite commands.
The crystal I used apparently had a low activity. Sometimes the oscillator was working, but most of the time it was not!
I changed the crystal and now it works! (Maybe changing the values of the capacitors would have worked, but I did not try that.)
Bookmarks