News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Using the same Subs with Hardware and Software I2C?

Started by trastikata, May 01, 2022, 09:40 AM

Previous topic - Next topic

trastikata

Hi all,

I have two I2C LCD's which unfortunately do not have the option of changing the I2C address. So I connected one to the hardware I2C and the other is using a software I2C - thus one is using HBStart-HBusOut-HBStop and the other BStart-BusOut-BStop.

I have already written the subroutines for displaying the information I need on those LCDs in previous projects using either HBStart-HBusOut-HBStop or BStart-BusOut-BStop.

I know I can simply use I2Cout SDA_Pin, SCL_Pin, Control, { Address }, [ OutputData ] with both LCD's in a software I2C mode, but it would mean rewriting the Subroutines.

So I am thinking about a "simple" way of setting a bit before sending the data and switching between HBStart-HBusOut-HBStop and BStart-BusOut-BStop. Something that sounds and looks like:

If HardwareBit = 0 Then Use BStart-BusOut-BStop : Else Use HBStart-HBusOut-HBStop

Any suggestions are welcome. Ultimately, if not possible, I'll modify my Subroutines using I2Cout SDA_Pin, SCL_Pin, Control, { Address }, [ OutputData ] but for now I'd like to spare myself that extra work if possible.

tumbleweed

Another option (if your device supports it) is to use PPS and remap the I2C pins by adding a "SelectPort" subroutine.
That way you could use hardware I2C with both.

trastikata

Quote from: tumbleweed on May 01, 2022, 10:38 AMAnother option (if your device supports it) is to use PPS and remap the I2C pins by adding a "SelectPort" subroutine.
That way you could use hardware I2C with both.

Good point - this is an option I didn't think of, unfortunately PIC18F46J50 doesn't support I2C remapping.