42688六轴传感器读取陀螺仪和加速度计的数据,使用的是iic的形式读取的,设备的地址是0xD0 cpu:stm32f405 + 硬件iic读取数据,由于42688的寄存器分布在不同的bank,在进行寄存器操作之前,首先选择bank,默认的是bank0 42688初始化:
write(ADDRESS,REG_BANK_SEL,0x00);
write(ADDRESS,0x11,0x01);
id = read(ADDRESS,WHOAMI);
data = read(ADDRESS,PWR_MGMT0);
write(ADDRESS,PWR_MGMT0,data|0x0F);
data = read(ADDRESS,GYRO_CONFIG0);
write(ADDRESS,GYRO_CONFIG0,data|0x06);
data = read(ADDRESS,ACCEL_CONFIG0);
write(ADDRESS,ACCEL_CONFIG0,data|0x06);
读取gyro:
dat[0] = read(ADDRESS,GYRO_DATA_X0);
dat[1] = read(ADDRESS,GYRO_DATA_X1);
dat[4] = read(ADDRESS,GYRO_DATA_Z0);
dat[5] = read(ADDRESS,GYRO_DATA_Z1);
dat[2] = read(ADDRESS,GYRO_DATA_Y0);
dat[3] = read(ADDRESS,GYRO_DATA_Y1);
读取acc:
dat[0] = read(ADDRESS,ACCEL_DATA_X0);
dat[1] = read(ADDRESS,ACCEL_DATA_X1);
dat[2] = read(ADDRESS,ACCEL_DATA_Y0);
dat[3] = read(ADDRESS,ACCEL_DATA_Y1);
dat[4] = read(ADDRESS,ACCEL_DATA_Z0);
dat[5] = read(ADDRESS,ACCEL_DATA_Z1);
宏定义:
#define ADDRESS 0XD0
#define WHOAMI 0X75
#define PWR_MGMT0 0x4E
#define GYRO_CONFIG0 0x4F
#define ACCEL_CONFIG0 0x50
#define SENSOR_CONFIG0 0x03
#define ACCEL_DATA_X1 0x1F
#define ACCEL_DATA_X0 0x20
#define ACCEL_DATA_Y1 0x21
#define ACCEL_DATA_Y0 0x22
#define ACCEL_DATA_Z1 0x23
#define ACCEL_DATA_Z0 0x24
#define GYRO_DATA_X1 0x25
#define GYRO_DATA_X0 0x26
#define GYRO_DATA_Y1 0x27
#define GYRO_DATA_Y0 0x28
#define GYRO_DATA_Z1 0x29
#define GYRO_DATA_Z0 0x2A
#define REG_BANK_SEL 0x76
下载链接: https://download.csdn.net/download/liumengyang1992/20481328
|