03-08-2016 12:17 PM
Hi there,
I'm using the USB-8451 for reading data from a MPU 9250/9150/6050 IMU (mostly the same ). The chip allows a I2C protocol for this task. I usually write my code in C, sometimes CVI but in this case Visual Studio 12.
I need to characterize this device for future control applications. Clearly, the bandwidth of my measurements will provide me better spectral information for modelling purposes.
1- High level approach:
2- Scripting approach:
// Script basics
ni845xI2cScriptOpen (&ScriptHandle); // create script handle
ni845xI2cScriptClockRate (ScriptHandle, I2C_FREQ); // configure clock rate
// Read sequences
ni845xI2cScriptIssueStart (ScriptHandle); // issue start condition
ni845xI2cScriptAddressWrite (ScriptHandle, MPU9250_ADDRESS); //Set direction of I2C device (slave) + direction bit 0 (write)
ni845xI2cScriptWrite (ScriptHandle, nWrite, &dirRegs[0]); //write (1 byte) register address
ni845xI2cScriptIssueStart (ScriptHandle);// issue start condition
ni845xI2cScriptAddressRead (ScriptHandle, MPU9250_ADDRESS); //Set direction of I2C device (slave) + direction bit (1) (read)
ni845xI2cScriptRead (ScriptHandle, nRead1[0], kNi845xI2cNakTrue, &scriptReadIndex[0]);//read number of bytes (1) specified and get Read Index
ni845xI2cScriptIssueStop (ScriptHandle); //issue stop condition
//==============================================================================================
//Second Register (Same code)
//==============================================================================================
ni845xI2cScriptIssueStart (ScriptHandle); // issue start condition
ni845xI2cScriptAddressWrite (ScriptHandle, MPU9250_ADDRESS); //Set direction of I2C device (slave) + direction bit 0 (write)
ni845xI2cScriptWrite (ScriptHandle, nWrite, &dirRegs[1]);//Set direction of I2C device (slave) + direction bit 0 (write)
ni845xI2cScriptIssueStart (ScriptHandle);// issue start condition
ni845xI2cScriptAddressRead (ScriptHandle, MPU9250_ADDRESS);//Set direction of I2C device (slave) + direction bit (1) (read)
ni845xI2cScriptRead (ScriptHandle, nRead2[0], kNi845xI2cNakTrue, &scriptReadIndex[1]);//read number of bytes (1) specified and get Read Index
ni845xI2cScriptIssueStop (ScriptHandle); //issue stop condition
/*========================== RUN ==========================*/
errChk (ni845xI2cScriptRun (ScriptHandle, myUSB8451, PortNumber));
*nRead1 = 0;
*nRead2 = 0;
/*========================== READ ==========================*/
ni845xI2cScriptExtractReadDataSize (ScriptHandle, scriptReadIndex[0], nRead1);
ni845xI2cScriptExtractReadDataSize (ScriptHandle, scriptReadIndex[1], nRead2);
/* extract the read data */
ni845xI2cScriptExtractReadData (ScriptHandle, scriptReadIndex[0], dMeas1);
ni845xI2cScriptExtractReadData (ScriptHandle, scriptReadIndex[1], dMeas2);
/*========================== CLOSE ==========================*/
ni845xI2cScriptClose (ScriptHandle);
The behaviour of this code was totally unespected. I'm getting estrange measuments. I buid my data from:
*yM = (double)(((PINT16)rawData_X[0] << 😎 + rawData_X[1]);
My measurements are wrong and data jumps continuosly between two values:
Everithing in this plot is wrong, values and jums.
Please, any advice??
Thanks a lot.
WAB.