MOD54415 SPI and I2C question

for everything else
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 SPI and I2C question

Post by jediengineer »

Thanks for the info, but I'm still stumped a bit. How do I tell the system I'm using I2C 2 versus using I2C 1?

My setup includes this so far:

J2[17].function(2); // I2C 2 SDA line
J2[18].function(2); // I2C 2 SCL line
I2CInit();


If I'm not mistaken, on the MOD54415, this enables I2C 2 pins, and the I2Cinit() will initialize I2C at the default frequency of 100kHz?

I can't think of anything else that would distinguish I2C1 from I2C 2 - and if I was using both I2C channels, how would I differentiate when I send data? The runtime library book gives this example:

BYTE I2CSendBuf( BYTE addr, PBYTE buf, int num, bool stop = true );

Again, I run into the problem with the address as a master, and wondering if it will be sending to the right I2C port. I'm assuming "PBYTE buf" is the buffer (I have to create) that stores the data I wish to write, "num indicates how many bits I'm sending, and "bool stop = true", well, that's kind of explained already.

versamodule was kind enough to give me the following example:


// Here is a write 8bit example.

BYTE i2cStatus;

i2cStatus = I2CStart( YOUR_CHIP_ADDRESS , I2C_START_WRITE );
i2cStatus += I2CSend( data );
i2cStatus += I2CStop();



// Now a write 16bits Example.


BYTE i2cStatus;

i2cStatus = I2CStart( YOUR_CHIP_ADDRESS , I2C_START_WRITE );
i2cStatus += I2CSend( register_loc );
i2cStatus += I2CSend( data );
i2cStatus += I2CStop();


and where this is simple and broken down (thanks versamodule) again, the address, I'm not understanding what it is and where it comes from. I'm assuming that if I wanted to write 24 bits, I could follow the 16 bit example, but not sure why he references a register location versus data...


Can someone confirm? maybe elaborate a little? The runtime library and the device manual aren't exactly helping me much...
User avatar
dciliske
Posts: 623
Joined: Mon Feb 06, 2012 9:37 am
Location: San Diego, CA
Contact:

Re: MOD54415 SPI and I2C question

Post by dciliske »

YOU WANT TO STOP THE ORDER ON YOUR PCB NOW!!! If it isn't too late...

I2C2 has been removed from future revs of the MOD54415. I'm sorry you found out right at this point. We did send out product change notices in July, I don't know why you haven't seen this.
Dan Ciliske
Project Engineer
Netburner, Inc
versamodule
Posts: 14
Joined: Fri Jun 08, 2012 4:59 am

Re: MOD54415 SPI and I2C question

Post by versamodule »

and where this is simple and broken down (thanks versamodule) again, the address, I'm not understanding what it is and where it comes from. I'm assuming that if I wanted to write 24 bits, I could follow the 16 bit example, but not sure why he references a register location versus data...
Sorry if that was confusing.
In the data sheet for your IC, they will give you the chip address for it. It is hard coded into the chip. Some devices also give you some address pins on the IC (I.E. z0,a1,a2) to tie high or low to further give you more addressing so you can hang more than one IC on the same i2C lines. If your IC does have these address lines then you would calculate the new device address. Say your data sheet says your device address is 0xA0 & you have 3 address lines (a0,a1,a2) that you tie low. your address would be 0xA0, but if you tie A1 high and A0,A2 low then your address will become 0xa2. As for my reference to "register_loc" typically you will first send the address inside the IC where you want to send you data to. So it was just an example. If you want to send 24 bits you can do it the following way. As an example, lets send 0x23,0x64,0x9A

// Lets assume your chip address is 0xA0
#define YOUR_CHIP_ADDRESS (0xA0)

i2cStatus = I2CStart( YOUR_CHIP_ADDRESS , I2C_START_WRITE );
i2cStatus += I2CSend( 0x23 );
i2cStatus += I2CSend( 0x64 );
i2cStatus += I2CSend( 0x9A );
i2cStatus += I2CStop();
jediengineer
Posts: 192
Joined: Mon Dec 17, 2012 6:24 am

Re: MOD54415 SPI and I2C question

Post by jediengineer »

Thanks Dan, all fixed!! And just in time!!

Versamodule, thanks for the explanation, now it all makes sense!! I really appreciate all the help from everyone, thanks all!
Post Reply