|
|
View previous topic :: View next topic |
Author |
Message |
bobsalterego Guest
|
does anyone have multiple i2c buses working? (!) |
Posted: Sun Feb 17, 2002 11:29 am |
|
|
folks,
after a week's worth of writing and rewriting code for multiple i2c buses, it still is a no go. i've simplified to no end and all to no avail. the first #use i2c(...) encountered by the compiler is used *forever*. despite many different ways of implementing the code, the first directive used is the only one used. to date i have tried compiler versions 3.068, 3.073, and 3.074. tech support at ccs says the same thing the manual does, "the last #use i2c(...) encountered is applied to any following i2c functions".
some excerpts to form an example,
#device PIC16C65B
#define PIN_B6 54 /* local i2c devices */
#define SCTLCLK 54
#define PIN_B7 55
#define SCTLDAT 55
#define PIN_C1 57 /* i2c devices on backplane segment B */
#define BKPLBCLK 57
#define PIN_C2 58
#define BKPLBDAT 58
#define PIN_C3 59 /* i2c devices on backplane segment A */
#define BKPLACLK 59
#define PIN_C4 60
#define BKPLADAT 60
#use i2c(master,sda=SCTLDAT,scl=SCTLCLK)
[code here using i2c, PART A]
#use i2c(master,sda=BKPLADAT,scl=BKPLACLK)
[code here using i2c, PART B]
#use i2c(master,sda=BKPLBDAT,scl=BKPLBCLK)
[code here using i2c, PART C]
well, the code in PART A works correction; then ALL of the i2c commands in PARTS B and C result in wiggling of the SCTLDAT and SCTLCLK pins. the correct addresses and commands are sent, albeit on the wrong pair of pins. if i reorder the parts, again the first bus designated is utilized forever.
hence my questions: does anyone have multiple i2c buses working? what version of compiler are you using? care to share some ideas or code?
thanks,
bob
___________________________
This message was ported from CCS's old forum
Original Post ID: 2643 |
|
|
Andrew Wilson Jones Guest
|
Re: does anyone have multiple i2c buses working? (!) |
Posted: Mon Feb 18, 2002 5:07 am |
|
|
Hi Bob,
I have used the code below to produce an Eeprom (24LC65) copier. I can read the master chip and the program and verify the copy chip. I am using PCB version 2.632 During the program I just call:-
write_eeprom_byte()
read_eeprom_byte()
read_master_eeprom_byte()
as needed.
Andy
#define EEPROM_I2C_WRITE_ADDR 0xA0
#define EEPROM_I2C_READ_ADDR 0xA1
//--------------------------------------------------------------
// The First I2C functions
//--------------------------------------------------------------
#use i2c(Master, SDA=PIN_B7, SCL=PIN_B6, FAST)
//--------------------------------------------------------------
void write_eeprom_byte(long addr, char data)
{
i2c_start();
i2c_write(EEPROM_I2C_WRITE_ADDR);
i2c_write((char)(addr >> 8));
i2c_write((char)addr);
i2c_write(data);
i2c_stop();
delay_ms(6); // Wait enough time for the write to occur
}
//--------------------------------------------------------------
char read_eeprom_byte(long addr)
{
char data;
i2c_start();
i2c_write(EEPROM_I2C_WRITE_ADDR);
i2c_write((char)(addr >> 8));
i2c_write((char)addr);
i2c_start();
i2c_write(EEPROM_I2C_READ_ADDR);
data = i2c_read(0);
i2c_stop();
return(data);
}
//--------------------------------------------------------------
// The second I2C functions
//--------------------------------------------------------------
#use i2c(Master, SDA=PIN_A1, SCL=PIN_A0, FAST)
//--------------------------------------------------------------
char read_master_eeprom_byte(long addr)
{
char data;
i2c_start();
i2c_write(EEPROM_I2C_WRITE_ADDR);
i2c_write((char)(addr >> 8));
i2c_write((char)addr);
i2c_start();
i2c_write(EEPROM_I2C_READ_ADDR);
data = i2c_read(0);
i2c_stop();
return(data);
}
//--------------------------------------------------------------
// end of program
//--------------------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
___________________________
This message was ported from CCS's old forum
Original Post ID: 2655 |
|
|
|
|
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
|