Two i2c lines

Discuss the Firewing language

Two i2c lines

Postby skartalov » Fri Mar 13, 2015 2:28 pm

I am using i2c library to communicate to a EEPROM 24LC08 -> Its OK.
But can I attach second EEPROM chip to another pins, and communicate with it as well?
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm

Re: Two i2c lines

Postby David John Barker » Fri Mar 13, 2015 3:22 pm

Yes, if the address is different...
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm

Re: Two i2c lines

Postby Jerry Messina » Fri Mar 13, 2015 3:27 pm

I think you can only have a single 24xx08 on a bus (no address pins).

If that's the case, you'll have to create a new module to drive a second I2C bus.
Copy the file I2C.bas to your user library and rename it to I2C2.bas. Edit the new I2C2.bas file to change the beginning few lines:
Code: Select all
module I2C2

' default pin settings
#option I2C2_SCL = PORTB.8
#option I2C2_SDA = PORTB.9

' timing delay
#option I2C2_DELAY_US = 5
#if IsOption(I2C2_DELAY_US) and not (I2C2_DELAY_US In(1 to 10))
IsValidPortPin(I2C2_SCL)
   #error I2C2_DELAY_US, "Invalid option. I2C delay must be between 1 and 10 us."
#endif

' SCL option...
#if IsOption(I2C2_SCL) and not IsValidPortPin(I2C2_SCL)
   #error I2C2_SCL, "Invalid option. I2C clock must be a valid port pin."
#endif
#option _SCL2_TRIS = GetTRIS(I2C2_SCL)

' SDA option...
#if IsOption(I2C2_SDA) and not IsValidPortPin(I2C2_SDA)
   #error I2C2_SDA, "Invalid option. I2C data line must be a valid port pin."
#endif
#option _SDA2_TRIS = GetTRIS(I2C2_SDA)

' configure SCL and SDA...
private _scl_in as I2C2_SCL.I2C2_SCL@
private _sda_in as I2C2_SDA.I2C2_SDA@
private _scl as _SCL2_TRIS.I2C2_SCL@
private _sda as _SDA2_TRIS.I2C2_SDA@
private const _delayus as byte = I2C2_DELAY_US


If I did that right that should get you a new module with all new option settings.
Jerry Messina
 
Posts: 280
Joined: Thu Feb 14, 2013 10:16 am

Re: Two i2c lines

Postby skartalov » Fri Mar 13, 2015 3:58 pm

I don't mind to use 24lc16 or 24lc32.

But because the second EEPROM is located on a socket, and I would like to plug it and remove on the fly, I do not want to interference with the first EEPROM, which is soldered on the PCB.

That's why I want to use different pins for I2C for the second EEPROM.
skartalov
 
Posts: 69
Joined: Sun Sep 15, 2013 1:12 pm


Return to Language

Who is online

Users browsing this forum: No registered users and 4 guests

x