1. 手册内容介绍
这是手册里面的四种工作模式。
这里是三轴加速度值的计算过程。
这里选取模式2,加速度范围是±2.4g,读取的是Z轴的加速度值。
2. 部分代码
static float SCL3300_Read(uint8_t direction)
{
u16 result = 0;
float result1 = 0;
switch (direction) {
case ANG_X:WriteReadRegister(READ_ANG_X);result = WriteReadRegister(READ_ANG_X);break;
case ANG_Y:WriteReadRegister(READ_ANG_Y);result = WriteReadRegister(READ_ANG_Y);break;
case ANG_Z:WriteReadRegister(READ_ANG_Z);result = WriteReadRegister(READ_ANG_Z);break;
case ACC_X:WriteReadRegister(READ_ACC_X);result = WriteReadRegister(READ_ACC_X);break;
case ACC_Y:WriteReadRegister(READ_ACC_Y);result = WriteReadRegister(READ_ACC_Y);break;
case ACC_Z:WriteReadRegister(READ_ACC_Z);result = WriteReadRegister(READ_ACC_Z);break;
default:
break;
}
if ( direction < 3) {
float angleF = (float)result / 16384.0f * 90.0f; //计算角度的值
return angleF;
} else {
if(result > 32768){ //如果是负数最高位是1
result1 = -(65536 - result);
}else{
result1 = (float)result;
}
float accleF = (float)result1/3000; //这里设置的是模式2,对应表格里面除以的是3000
return accleF;
}
}
3. 结果展示