LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

i2c - I am using the 485 converter, can read register locations, write instructions do not modify the register

Here is the code, I've tried various registers to no avail, I am able to read all registers:

 

//Write - simple to validate instructions - fails to write, does not return any errors, the bit pattern on scope looks correct for slave addres, register addres and register data
WriteData[0] =  0x0;  // address
WriteData[1] =  0x0;  // data

// create script
if (errorCode = ni845xI2cScriptOpen (&ScriptHandle)) return errorCode;
// configure clock rate
if (errorCode = ni845xI2cScriptClockRate (ScriptHandle, ClockRate)) return errorCode;
if (errorCode = ni845xI2cScriptIssueStart (ScriptHandle))return errorCode;
//write 7-bit address and direction bit 0 (write)
if (errorCode = ni845xI2cScriptAddressWrite (ScriptHandle, I2C_SLAVE))return errorCode;
//write array
if (errorCode = ni845xI2cScriptWrite (ScriptHandle, 2, WriteData)) return errorCode;
// issue stop condition
if (errorCode = ni845xI2cScriptIssueStop (ScriptHandle)) return errorCode;
//set delay
if (errorCode = ni845xI2cScriptDelay (ScriptHandle, 5)) return errorCode;
// run the script
if (errorCode = ni845xI2cScriptRun (ScriptHandle, DeviceHandle, 0)) return errorCode;
// close script handle
if (errorCode = ni845xI2cScriptClose (ScriptHandle)) return errorCode;

 

 

//Read instructions - works correctly, no issues

// create script
if (errorCode = ni845xI2cScriptOpen (&ScriptHandle)) return errorCode;
// configure clock rate
if (errorCode = ni845xI2cScriptClockRate (ScriptHandle, ClockRate)) return errorCode;
if (errorCode = ni845xI2cScriptIssueStart (ScriptHandle))return errorCode;
//write 7-bit address and direction bit 0 (write)
if (errorCode = ni845xI2cScriptAddressWrite (ScriptHandle, I2C_SLAVE))return errorCode;
//write address to read from 
if (errorCode = ni845xI2cScriptWrite (ScriptHandle, WriteSize, WriteData))return errorCode;
//write read location
if (errorCode = ni845xI2cScriptIssueStart (ScriptHandle)) return errorCode; 
if (errorCode = ni845xI2cScriptAddressRead (ScriptHandle, I2C_SLAVE)) return errorCode;
if (errorCode = ni845xI2cScriptRead (ScriptHandle, ReadSize, kNi845xI2cNakTrue, &ScriptReadIndex)) return errorCode;

0 Kudos
Message 1 of 2
(2,933 Views)

Hey

Check this link, also try inserting dealy between your writes this might help. Also try testing in MAX by opening VISA test panel to see if the device is working or not.

Cheers

lab

0 Kudos
Message 2 of 2
(2,907 Views)