Hello,
I’m developing an application that talks with two MCP4725 DACS.
The DACs are on the same bus and they have different address 0x60 and 0x61.
The communication is fine, I can write normally to each DAC, the problem is I cannot reach an high speed rate of write commands. The best I have is 2000 writes per second in total.
I’ve tryied to set the Standard (100 kbps) and the Fast (400 kbps) Modes but nothing changes, the rate is the same.
Could you help me?
Here is the code I use:
For the initialization:
public MCP4725(uint Address)
{
bool bResult = false;
i2cHandle = i2c.I2c_Init("I2C1"); ///< get handle to I2C device
if (i2cHandle == IntPtr.Zero)
{
Program.cGlobals.cLogging.LogMessage("MCP4725 --> Error in I2c_Init()");
}
if (!i2c.I2c_Open(i2cHandle)) ///< open I2c for communication
{
Program.cGlobals.cLogging.LogMessage("MCP4725 --> Error: I2C Open");
}
bResult = i2c.I2c_SetConfigInt(i2cHandle, "BitRateHz", 100000, TdxCommon.ParamStorageType.StoreVolatile); ///< Configuring I2C channel with appropriate settings
bResult = i2c.I2c_SetConfigInt(i2cHandle, "SlaveAddrSize", 7, TdxCommon.ParamStorageType.StoreVolatile);
DeviceAddress = Address;
bResult = i2c.I2c_SetConfigInt(i2cHandle, "SlaveAddr", DeviceAddress, TdxCommon.ParamStorageType.StoreToRegistry);
bResult = i2c.I2c_SetConfigInt(i2cHandle, "RegisterAddrSize", 0, TdxCommon.ParamStorageType.StoreToRegistry);
bStarted = false;
}
For the Write Command:
public void WriteRegister(int iValue)
{
if (bReverse)
iValue = MAX_VALUE - iValue;
//Modalità non fast
//uint bufferLenght = 3;
//Byte[] DataToWrite = new Byte[bufferLenght];
//DataToWrite[0] = MCP4726_CMD_WRITEDAC; // cmd to update the DAC
//DataToWrite[1] = (byte)(iValue >> 4); // the 8 most significant bits... (D11.D10.D9.D8.D7.D6.D5.D4)
//DataToWrite[2] = (byte)((iValue & 15) << 4); // the 4 least significant bits... (D3.D2.D1.D0)
//Modalità fast
uint bufferLenght = 2;
Byte[] DataToWrite = new Byte[bufferLenght];
DataToWrite[0] = (byte)((iValue & 3840) >> 8);
DataToWrite[1] = (byte)(iValue & 255);
try
{
unsafe
{
fixed (byte* for_Casting_Intptr_to_Byte = DataToWrite)
{
returnValue = i2c.I2c_Write(i2cHandle, (IntPtr)for_Casting_Intptr_to_Byte, bufferLenght);
if (returnValue == 0)
throw new Exception(); ///< If Write operation returns 0
}
}
}
catch (Exception ex)
{
Program.cGlobals.cLogging.LogMessage("Scrittura Configurazione Fallita - Codice Errore: " + ex.Message);
}
}
Thanks in advance for your support.