Hi there
We have implemented an IO card function based on the XIO2001 using the I2C bus controller.
Do you have source code examples showing how to access the I2C control registers under windows (32 or 64 bit)
Alan
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi there
We have implemented an IO card function based on the XIO2001 using the I2C bus controller.
Do you have source code examples showing how to access the I2C control registers under windows (32 or 64 bit)
Alan
Hello Alan,
Unfortunately we have no source code examples we can provide; although I just found a code snippet that I hope can help to clarify the process in case you have any doubts.
Example: Write a value of 0x55 to address 0x00 on an I2C EEPROM which slave address is 0xA0
I2C Write Byte
// Write the address to register offset 0xB1
WritePciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB1, 0x00)
// Write the data to register offset 0xB0
WritePciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB0, 0x55)
// Write the device’s slave address and write command to register offset 0xB2
WritePciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB2, 0xA0)
Where
Example: Read back the data written on the previous example
I2C Read Byte
Byte ROM_Busy_Counter = 0
// Write the address to register offset 0xB1
WritePciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB1, 0x00)
// Write the device’s slave address and read command to register offset 0xB2
WritePciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB2, 0xA1)
// Wait for EEPROM to come ready
Do
{
ROM_Busy_Counter ++
If ( ROM_Busy_Counter >= 50 )
{
Print("EEPROM BUSY TIMEOUT REACHED!");
break;
}
} while ( REQBUSY() == true )
// Check for errors
If (SB_ERR() )
// There was a read error. Data is not valid.
Data_Returned = -1
Else
Data_Returned = ReadPciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB0)
Where
{
Byte Busy_Register = ReadPciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB3)
If ( (Busy_Register && 0x20) == 0x20 )
{
// EEPROM busy. Wait a bit.
mS_Wait(0.4)
return True
}
else
return False
}
{
Byte Error_Register = ReadPciByte(Local_Device.BUS_NUMBER, Local_Device.DEVICE_NUMBER, 0, 0xB3)
If ( (Error_Register && 0x02) == 0x02 )
return True
else
return False
}