新手入门
- 积分
- 17
- 金钱
- 17
- 注册时间
- 2016-4-15
- 在线时间
- 4 小时
|
最近使用了stm的lsm9ds1这个九轴触感器,各个数据都读出,现在给大家分享下磁力计这部分代码,顺便问一下,磁力计这样配置对不对,file:///C:\Users\dell\AppData\Roaming\Tencent\Users\1531886062\QQ\WinTemp\RichOle\6_JBF]PVFTOIK~0I4ADD9I5.pngCTRL_REG1_M (20h),这个此存器该怎么配置?void config_mag_default(){
unsigned char buffer[2];
int wait;
//CTRL_REG1_M
buffer[0] = 0x20; //10hz
buffer[1] = 0x30; // 0b00110000 datasheet
i2cWrite(SAD_M_0, buffer, sizeof(buffer), I2C_STD);
for(wait = 0; wait < 1000000; wait++){;} // Wait before doing another operation
//CTRL_REG2_M
buffer[0] = 0x21; //
buffer[1] = 0x00; // table 112 113 114 ----4g
i2cWrite(SAD_M_0, buffer, sizeof(buffer), I2C_STD);
for(wait = 0; wait < 1000000; wait++){;} // Wait before doing another operation
//CTRL_REG3_M
buffer[0] = 0x22; // 0b00000000 -----Continuous-conversion mode
buffer[1] = 0x00; // table 115 116 117
i2cWrite(SAD_M_0, buffer, sizeof(buffer), I2C_STD);
for(wait = 0; wait < 1000000; wait++){;} // Wait before doing another operation
//CTRL_REG4_M
buffer[0] = 0x23; // 0b00001000
buffer[1] = 0x04; // table 118 119 120
i2cWrite(SAD_M_0, buffer, sizeof(buffer), I2C_STD);
for(wait = 0; wait < 1000000; wait++){;} // Wait before doing another operation
}
void get_sensor_data_M(char address, int data, int *output){ // output[0] = x | output[1] = y | output[2] = z
unsigned char buffer[6] = {0}; // each value has 2 byter (3 values x 2 byter = 6 bytes)
unsigned char buffer1[1] = {0};
address = SAD_M_0;
data = 0x28;
buffer1[0] = data;
i2cWrite(SAD_M_0,buffer1, 1, I2C_STD); // sequentially reads 6 registers
i2cRead(SAD_M_0, buffer, 6, I2C_STD);
output[0] = (buffer[1] << 8) | buffer[0]; // merge the 2 bytes in a single value, e.g. (OUT_X_H_G << 8) | OUT_X_L_G
output[1] = (buffer[3] << 8) | buffer[2]; // xxx_x_H_x contains the most significant bytes and xxx_x_L_x contains the least significant bytes
output[2] = (buffer[5] << 8) | buffer[4];
}
|
|