Re: MOD54415 SPI and I2C question
Posted: Fri Sep 13, 2013 5:04 am
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...
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...