HW i2c & DC

The DC Function reference doesn’t appear to document the
i2c API for the R6000. And my manual has a copyright date
of 2011. Nor do there appear to be any examples of using
the HW i2c API in DC v10.64. Is there any documention
available other than the source code?

It is not in the Dynamic C Users manual. You might want to look at Tech Note TN215 Using the i2c Bus that is located in the Tech notes section under DC 10 documentation

I should have mentioned that I also checked TN215 under
DC10. But TN215 only applies to R2000 and R3000. Go

For the R2000 & R3000, if I wanted to read a 2-bytes from a
slave device, I would do something like this:

i2c_startw_tx(); // generate i2c start condition
i2c_wr_wait( slave_adr ); // address slave device to write.
i2c_wr_wait( control_word ); // write control word to slave.
i2c_startw_tx(); // generate another start condition
i2c_wr_wait( slave_adr+1); // Put slave device in read mode.
i2c_read_char( &byte1 ); // read back 2-bytes
i2c_read_char( &byte2 );

But in the new i2c.lib, the only read function is
I2C_ReadFromSlave( slave_adr, data, len, mode, timeout);

I don’t see how to do the equivalent of above.


The documention in the function description block in I2C_HW.LIB for this function is quite clear. For this you would do something like:

char cBytes[2];
int iStatus;

iStatus = I2C_ReadFromSlave(slave_adr, (char far *)&cBytes[0], 2, 1, 100);

if(iStatus != 0)
/// Handle error

For a blocking read with 100mS timeout.


I was tying these functions on the RCM6700 development board. For me, the board just locks up. It never does time out. Have you ever seen this?

I tried the I2C_24LC16.c example too. Same thing, just locks up. I figured it would return after the timeout.

I also tried this on a few dev kits (all RMC6700)

This is another file I tried. I wrote it to read a 24C02 EEPROM. Also locks up. I never get the second print. Any suggestions?

#use I2C_HW.LIB

I2C_initIO(1, 0);


char Data[5];

I2C_ReadFromSlave(0xA2, (char far *)&Data[0], 2, 1, 500);


You are using 8 bit slave address. It should be 7-bit.
The library adds r/w bit to the address. This is what i use for 24AA02 chip.

//Note Address is 7bit NOT 8 bit library adds r/w bit
#define EEPROM 0x50 //Mac address and EEPROM
#define BusReset_ADDRESS 0x00 //I2C bus Slave address

#use RCM67xx.LIB //library used for RCM67xx modules
#use I2C.lib //library used for I2C comms

int EEPROMerr; //i2c error code from EEPROM 0=noerror
char cBytes[258];
unsigned char calibrat[256] , *cal; //Calibration constants EEPROM
unsigned char wEEPROM[9] , *wEEP; //EEPROM working string

brdInit(); //Initialize RCM ports
if(EEPROMerr = i2c_init()) //Initialize i2c
// Error handler here
if(EEPROMerr = resetI2C()) //Reset i2c bus this is optional
// Error handler here
if(EEPROMerr = Read_EEPROM());
// Error handler here

int resetI2C(void)
int len;
wEEPROM[0] = 6; //Command SoftReset
len = 1; //No of chars to write
EEPROMerr = I2C_WriteToSlave(BusReset_ADDRESS,(char far *)&wEEPROM[0],len,1,5);
return EEPROMerr;

int Read_EEPROM(void)
cal = calibrat;
cBytes[1] = 0x00;
for(i = 0; i < 256; i+=8) //Read EEPROM data max 8 bytes at a time
if(EEPROMerr = I2C_WriteToSlaveNoStop(EEPROM, (char far *)&cBytes[1], 1, 1, 5))
// Error handler here
if(EEPROMerr = I2C_ReadFromSlave(EEPROM, (char far *)cal, 8, 1, 5))
// Error handler here
return EEPROMerr;

Thanks, I will try your code when I get a chance. I did notice awhile back my I2C address was incorrect. It is supposed to be 7 bit. But even after using the right address, the board just locks up. That was the bigger issue. Even with a wrong address, it should not lock up.
I ran the sample I2C examples that came with the install and they too would lock up. So, I submitted a ticket and I believe it is being looked into.

In the meantime, my fix was to use the I2C_DEVICES.LIB instead. See the code below.

#define I2C_CLOCKPIN 1
#define I2C_DATAPIN 0
//#use I2C_HW.LIB
unsigned I2C_ISR_State;
i2cTransaction I2Cdata;
unsigned long I2C_CLK_COUNT;

in the function, I used

unsigned int I2C_Address=0x00;
char sData[32];

I2C_initIO(1, 0); // Set 1=PE1 as clock, 0=PE0 as data
//Example (Sets I2C bus speed to 40 Kbits/second):

Result=I2C_WriteToSlave(I2C_Address, (char far *)&sData, 1, 1, 250);