News:

;) This forum is the property of Proton software developers

Main Menu

2 I2c

Started by tolyan249, Oct 07, 2026, 05:52 PM

Previous topic - Next topic

tolyan249

Question: how can I create 2 I2C ports?
Since the speeds are very different, one hardware port works with an OLED display, and I need a second software port for the equipment. For the second port, I want to use the I2C_software.inc file for PIC12F1840.

Thank you.

Frizie

You can opt for the software variant using the I2CIn and I2COut instructions.
Ohm sweet Ohm | www.picbasic.nl

trastikata

You can still use the same hardware I2C port, just change the speed before accessing the devices. Use the SSP1ADD to set the new speed, you can calculate it as shown on page 259, equation 25-1.

tolyan249

Thanks everyone.

tolyan249

One more question. If the controller is powered by 5V and the OLED display is also powered by 5V, do we need to match the SCL and SDA levels? Or will it work like this?
Since the display has a 3.3V stabilizer.

trastikata

#5
Check the datasheet for the required voltage levels on those I2C pins - if 3.3v is sufficient, then just connect the pull-up resistors to the 3.3v rail.

Edit:

I checked it for you:
- the I2C logic requires 0.7xVDD as minimum for high - 3.3v is border line - hardware I2C might work or might not.
- The general IO port uses TTL, so for the same pins the minimum high is 0.25xVDD + 0.8v which means software I2C will work with 3.3v pull-up resistors.

JonW

#6
If voltage domains are within 0.4V over temp you are safe.

I2c always needs pull ups. If you counter a voltage domain conflict greater than 0.5V, shift the levels.

Imho
Domain is usually bounded by a diode. Generally esd frame diodes in the Ic.  Hence is speed is not a major issue add current limiters to about 20maA

david

Keep in mind the OLED display will have a jelly-bean 3.3V regulator with tolerance and the 5V micro supply may also have a tolerance.  If using the MSSP under these conditions, then getting a reliable high ACK signal from the display back to the micro will generally be a problem.  (distorted and hanging characters)
The displays usually have 10k pull-ups fitted to the nominal 3.3V regulated supply which is adequate depending on bus capacitance but only if the micro is operating below about 4.2V.  As trastikata mentioned, using software I2C with TTL levels should be fine.
For a one-off hobby project you could use the MSSP with a moderate (12k-15k) pull-up to 5V on the data pin only.  Yes it exceeds the OLED ratings but it works and I've yet to see one fail.  The proper approach is to use level shifting but ideally it needs to be at the 3.3V end on the display as the micro end may not have 3.3V available.

tolyan249

Thank you all for your help.

▲