Hi,
I have a Texas Instruments CC2650 with Debugger Devpack, and I use CCS Version 6.1.2.00015. I am trying to use the mpu9250 (built-in accelerometer) and I already managed to initialize the accelerometer configure a callback for the interrupts, and execute the code of the callback when I enable the Wake on Motion feature. However, when I read the data from the accelerometer I don't get coherent values.
I use a function sensorMpu9250AccRead((uint16_t*) &accData) , with accData an uint8_t array of 6 length, where the values read from accelerometer data registers are stored (registers 0x3B to 0x40, in this order). Then, I set three int16_t variables (one for each axis) to convert the data of each axis, using a function sensorMpu9250AccConvert(accel).
This is the portion of code I use to read the accelerometer data:
uint8_t accData[6];
int16_t accel_x, accel_y, accel_z;
uint8_t range;
float accelx, accely, accelz;while(1){
sensorMpu9250AccRead((uint16_t*) &accData);
range = sensorMpu9250AccReadRange();
System_printf("Accelerometer Range: %u\n", range);
accel_x = (accData[0] << 8) + accData[1];
accel_y = (accData[2] << 8) + accData[3];
accel_z = (accData[4] << 8) + accData[5];
accelx = sensorMpu9250AccConvert(accel_x);
accely = sensorMpu9250AccConvert(accel_y);
accelz = sensorMpu9250AccConvert(accel_z);
System_printf("Accel data x: %1.2f\n", accelx);
System_printf("Accel data y: %1.2f\n", accely);
System_printf("Accel data z: %1.2f \n", accelz);
System_flush();
Task_sleep(5000 * (1000 / Clock_tickPeriod));
}
And this is the sensorMpu9250AccConvert() function that converts a 16 bit binary to a float with the corresponding acceleration value:
float sensorMpu9250AccConvert(int16_t rawData)
{
float v; switch (accRange)
{
case ACC_RANGE_2G:
//-- calculate acceleration, unit G, range -2, +2
v = (rawData * 1.0) / (32768/2);
break;
case ACC_RANGE_4G:
//-- calculate acceleration, unit G, range -4, +4
v = (rawData * 1.0) / (32768/4);
break;
case ACC_RANGE_8G:
//-- calculate acceleration, unit G, range -8, +8
v = (rawData * 1.0) / (32768/8);
break;
case ACC_RANGE_16G:
//-- calculate acceleration, unit G, range -16, +16
v = (rawData * 1.0) / (32768/16);
break;
}
return v;
}
When I start the program, the sensor is static on my table, and the accelerometer is pointing upwards, so I expect the output would be 0 for x and y axes, and 1 for z axis. However, the output of the console shows inaccurate and non-coherent data. This is the console output after some seconds of running the program:
Accelerometer Range: 2
Accel data x: -6.6894
Accel data y: 0.1237
Accel data z: -1.1220
Accelerometer Range: 2
Accel data x: -7.1894
Accel data y: 0.6237
Accel data z: -1.1220
Accelerometer Range: 2
Accel data x: -7.5019
Accel data y: 0.3737
Accel data z: -1.3720
Accelerometer Range: 2
Accel data x: -7.1269
Accel data y: 0.4362
Accel data z: -1.4345
Accelerometer Range: 2
Accel data x: -7.2519
Accel data y: 0.5612
Accel data z: -1.4970
Accelerometer Range: 2
Accel data x: -6.7519
Accel data y: 0.4362
Accel data z: -1.1220
I didn't found the procedure in the documentation to read the accelerometer data and convert it to acceleration (in g), but I did my implementation based on different examples extracted from other projects, and some explanations found in the forums.
I think I may be missing something but after a lot of searching in the forums, I don't know what can be happening. ¿Anyone knows what am I doing wrong? (or what can I check to review my procedure?)
Thank you in advance!