|
|
View previous topic :: View next topic |
Author |
Message |
arunb
Joined: 08 Sep 2003 Posts: 492 Location: India
|
Some queries regarding multiple I2C buses... |
Posted: Thu Feb 07, 2008 10:30 pm |
|
|
Hi,
MCU: 16F648A
Compiler: PCM 3.228
I am using 2 I2C buses, on two PICs, PIC1, PIC2
Each of the PICs are connected to two FRAMs F1 and F2
PIC1 is connected to Fram F1 and fram F2
PIC2 is connected to Fram F1 and Fram F2
A byte can be written to fram F1 using this code (it uses FRAM1_SDA and FRAM1_SCL)
Code: |
#use i2c(master, sda=FRAM1_SDA, scl=FRAM1_SCL)
void write_fram1(int16 address,int8 data)
{
//Code for I2C access of FRAM
}
|
similary a byte can be written to fram F2 using this code
Code: |
#use i2c(master, sda=FRAM2_SDA, scl=FRAM2_SCL)
void write_fram2(int16 address,int8 data)
{
//Code for I2C access of FRAM
}
|
Now I would like to have a single function that writes a 16bit data to say on fram F1, so i would have a function like this
Code: |
#use i2c(master, sda=FRAM1_SDA, scl=FRAM1_SCL)
void write_fram1_16bit(int16 address,int16 data)
{
write_fram1(address,make8(data,1));
write_fram1(address+1,make8(data,0));
}
|
These functions are accessed by another function say sl_process()
Code: |
void sl_process()
{
write_fram1_16bit(nAddress,nData);
}
|
Will the above function work ??
or do I have to call the write_fram1 function individully for each of the
bytes.
like this
Code: |
void sl_process()
{
write_fram1(nAddress,make8(nData,1));
write_fram1(nAddress+1,make8(nData,0));
}
|
I observed that the above method works, but the write_fram1_16bit function does not.
Could anyone explain this.., is there something wrong with the usage of functions..and #use statement
Please help...
thanks
arunb |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 08, 2008 12:16 pm |
|
|
The #use i2c() statement only affects the CCS i2c functions, such as
i2c_read() and i2c_write(), etc.
It does not affect higher level functions written by you, such as this one.
Quote: | #use i2c(master, sda=FRAM1_SDA, scl=FRAM1_SCL)
void write_fram1_16bit(int16 address,int16 data)
{
write_fram1(address,make8(data,1));
write_fram1(address+1,make8(data,0));
} |
The #use i2c() statement causes the compiler to use the specified pins
in the i2c_read(), i2c_write(), etc., functions.
This is done at compile-time. It's not done at run-time. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|