News:

Let's find out together what makes a PIC Tick!

Main Menu

how to declare two I2C on a same chip

Started by Yves, May 25, 2023, 12:30 PM

Previous topic - Next topic

Yves

I have two I2C on a same chip one is for the I2C display and one is for an a/d converter. When I compile I get a warning I that the SCL_PIN and SDA_PIN are already declared. I have something like this:

  Declare SCL_Pin = PORTC.0       ;SCL = Port.Pin  SCL OLED
  Declare SDA_Pin = PORTC.1       ;SDA = Port.pin  SDA OLED
and
  Declare SCL_Pin = PORTA.5  'For MCP 3421
  Declare SDA_Pin = PORTA.4  'For MCP 3421

Both I2C are software none using the EUSART. My question is how to solve the conflict?

Yves
Yves

Pepe

Use the same I2C for both devices and change the address of one of them, that's why I2C was designed, to communicate several devices through a single line.

John Drew

Pepe's got the answer.
Personally I prefer hardware I2C but both methods have their advantages.
I've used  up to three devices off the single Clk and Dta pins.
Procedures make it easy too.
John

Yves

I understand I could use the same Clk and Dat and use the the different address of both slave items but the board is already made and I had an afterthought to use a different display than a a RS232 LCD. The the A/D is hard wired on the board. What I can do to save the situation is to solder the wires of the display on the bottom of the of the on pullup resistors of the A/D chip. The SSD1306 module I believe has already pullup resistors, maybe I could take them off and use the OLED's pullup for both items, it will look shit but it may work. I thought there will be a way around.

Yves
Yves

trastikata

Quote from: Yves on May 25, 2023, 02:38 PMWhat I can do to save the situation is to solder the wires ...

Situation is not so desperate as to hard rewire the board  :)

If you are not comfortable applying Les' I2C Procs from the compiler's include file, which is the easy solution, and you prefer the built in commands then use:

I2Cin SDA_Pin, SCL_Pin, Control, { Address }, [ Variable {, Variable...} ]
I2Cout SDA_Pin, SCL_Pin, Control, { Address }, [ OutputData ]



Yves

Thank you trastikata,

I will go that route for the easy one the Les MCP3421 routine to modify with the I2C commands. There is something I don't really understand about the "Control" byte is it the read or write and  chip address byte?

Yves
Yves

TimB

I would for now recommend you use the i2cin command as its very easy to use

Here is an example pSDA1 etc are the port pins


       I2CIn pSDA1, pSCL1, cPressureSensorI2CAddress, [wTemp1.Byte1, wTemp1.Byte0]                         ; Read pressure sensor 1



       I2CIn pSDA2, pSCL2, cPressureSensorI2CAddress, [wTemp1.Byte1, wTemp1.Byte0]                         ; Read pressure sensor 1


Yves

Thank you Tim,

That will sort my design blunder and in a new boards I will connect all the I2C on a single 2 lines as the slave I2C chip is responding to its "unique" type and address.

Regards,

Yves
Yves

John Lawton

If you are using a mix of I2C chips, check that you don't have any matching addresses as there aren't that many different addresses to go round all the chips available.