As far as I have read, the I2C pins are Open Drain or Open collector, but in the PIC18F2550 the datasheet doesnt say anything about those pins, and even says they are a digital output if you select them to be one. Do I need to add a pullup resistor to the pins so to use them as a digitial output? If I dont, how do they work in the I2C? Thanks!
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
You can do open drain on any digital pin on the PIC yourself, it's easy! I'll show through a quick chunk of example code using RB0.
The I2C module will do something similar to this internally, without you doing anything. In other words: yes! You'll need a pullup resistor!
EDIT: To answer your second question which I did not directly address, the pin does not need a pullup resistor during normal digital output operation. My example was to show you how a normal, fully functioning digital I/O pin could operate as a open-drain without any additional behavior or behaving unexpectedly. I should also note that I have done this exactly what I showed here to do open-drain in real programs, so this isn't a toy example, it's really how you do it!
The PIC has a built-in peripheral (the MSSP) that allows hardware-based i2c operation. The open-drain behavior results from the fact that it operates the direction control (aka "TRIS") automatically for these pins. If the MSSP is disabled, the port pins become ordinary I/O pins and now they're controlled the conventional way, and if programmed as output they will drive high or low.
What was confusing you was the fact that they can operate in either mode. You'd use the pullup resistors if it were set up for i2c, but not if the port pins were being used as general-purpose I/O.