//以下是SPI模块的初始化代码,配置成主机模式
//SPI口初始化
//这里针是对SPI1的初始化
void SPI1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);//使能GPIOA时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//使能SPI1时钟
//GPIOFB3,4,5初始化设置
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;//PB5~7复用功能输出
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
GPIO_Init(GPIOB, &GPIO_InitStructure);//初始化
GPIO_InitStructure.GPIO_Pin =GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource5,GPIO_AF_SPI1); //PA5复用为 SPI1
GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_SPI1); //PA6复用为 SPI1
GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_SPI1); //PA7复用为 SPI1
//这里只针对SPI口初始化
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,ENABLE);//复位SPI1
RCC_APB2PeriphResetCmd(RCC_APB2Periph_SPI1,DISABLE);//停止复位SPI1
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //设置SPI单向或者双向的数据模式:SPI设置为双线双向全双工
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //设置SPI工作模式:设置为主SPI
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //设置SPI的数据大小:SPI发送接收8位帧结构
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //串行同步时钟的空闲状态为高电平
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //串行同步时钟的第二个跳变沿(上升或下降)数据被采样
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS信号由硬件(NSS管脚)还是软件(使用SSI位)管理:内部NSS信号有SSI位控制
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16; //定义波特率预分频的值:波特率预分频值为256
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //指定数据传输从MSB位还是LSB位开始:数据传输从MSB位开始
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC值计算的多项式
SPI_Init(SPI1, &SPI_InitStructure); //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
SPI_Cmd(SPI1, ENABLE); //使能SPI外设
SPI1_ReadWriteByte(0xff);//启动传输
}
//SPI1速度设置函数
//SPI速度=fAPB2/分频系数
//@ref SPI_BaudRate_Prescaler:SPI_BaudRatePrescaler_2~SPI_BaudRatePrescaler_256
//fAPB2时钟一般为84Mhz:
void SPI1_SetSpeed(u8 SPI_BaudRatePrescaler)
{
assert_param(IS_SPI_BAUDRATE_PRESCALER(SPI_BaudRatePrescaler));//判断有效性
SPI1->CR1&=0XFFC7;//位3-5清零,用来设置波特率
SPI1->CR1|=SPI_BaudRatePrescaler; //设置SPI1速度
SPI_Cmd(SPI1,ENABLE); //使能SPI1
}
//SPI1 读写一个字节
//TxData:要写入的字节
//返回值:读取到的字节
u8 SPI1_ReadWriteByte(u8 TxData)
{
u8 retry;
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET)//等待发送区空,即发送完成
{
retry++;
if(retry>200)
return 0;
}
SPI_I2S_SendData(SPI1, TxData); //通过外设SPIx发送一个byte数据
while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET) //等待接收完一个byte
{
retry++;
if(retry>200)
return 0;
}
return ((uint8_t)SPI_I2S_ReceiveData(SPI1)); //返回通过SPIx最近接收的数据
}
bool SPI1_ReadWriteLen(SPI_TypeDef *instance, u8 *out, const u8 *in, int len)
{
u8 b;
instance->DR;
while (len--)
{
b = in ? *(in++) : 0xFF;
while (SPI_I2S_GetFlagStatus(instance, SPI_I2S_FLAG_TXE) == RESET){} //等待发送区空,即发送完成
SPI_I2S_SendData(instance, b);
while (SPI_I2S_GetFlagStatus(instance, SPI_I2S_FLAG_RXNE) == RESET){} //等待接收完一个byte
b = SPI_I2S_ReceiveData(instance);
if (out)
*(out++) = b;
}
return true;
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
u8 ICM_Init(void)
{
icm20602WriteRegister(PWR_MGMT_1,0X80); //复位icm20602
delay_ms(100);
icm20602WriteRegister(SIGNAL_PATH_RESET,0X03); //Reset accel digital signal path. Reset temp digital signal path.
delay_ms(100);
// icm20602WriteRegister(PWR_MGMT_1,0X00); //唤醒icm20602
ICM_Set_Gyro_Fsr(3); //陀螺仪传感器,±2000dps
delay_ms(15);
ICM_Set_Accel_Fsr(0); //加速度传感器,±2g
delay_ms(15);
ICM_Set_Rate(50); //设置采样率50Hz
delay_ms(15);
icm20602WriteRegister(INT_PIN_CFG,0X10);
delay_ms(15);
icm20602WriteRegister(INT_ENABLE,0X00); //关闭所有中断
// icm20602WriteRegister(FIFO_EN,0X00); //关闭FIFO
// icm20602WriteRegister(INT_PIN_CFG,0X80); //INT引脚低电平有效
return icm20602SpiDetect(); //器件ID不正确,返回false
}
u8 icm20602WriteRegister(u8 reg,u8 data)
{
u8 status;
ICM20602_CS=ENABLE_ICM20602;//选中icm20602
status=SPI1_ReadWriteByte(reg);
SPI1_ReadWriteByte(data);
ICM20602_CS=DISABLE_ICM20602;//取消选中icm20602
return (status);
}
u8 icm20602ReadRegister(u8 reg, u8 length, u8 *data)
{
u8 reg_val;
ICM20602_CS=ENABLE_ICM20602;//选中icm20602
SPI1_ReadWriteByte(reg|0x80); //读取
reg_val=SPI1_ReadWriteLen(SPI1, data, NULL, length);
ICM20602_CS=DISABLE_ICM20602;//取消选中icm20602
return 0;
}
u8 icm20602SpiDetect(void)
{
u8 tmp;
while(1)
{
icm20602ReadRegister(WHO_AM_I, 1, &tmp);
printf("ID is %d
",tmp);
delay_ms(500);
}
if (tmp == ICM20602_WHO_AM_I_CONST)
{
return 1;
}
return 0;
}
代码如上,但是不知道为什么在进行串口输出WHO_AM_I的值的时候输出的是0而不是数据手册上的0x12,可能是初始化有问题,但是具体是什么问题搞了很久都没弄懂,求各位大神可以帮帮忙.
******************************************************************************
* File Name : icm20602_driver.h
* Description : This file provides code for the icm20602 .
******************************************************************************
*
* COPYRIGHT(c) 2016 aibird
*
******************************************************************************
*
* Author:
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef _ICM20602_DRIVER_H
#define _ICM20602_DRIVER_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
void Init_Icm20602(I2C_HandleTypeDef *hi2c);
void Read_Icm20602_Data(I2C_HandleTypeDef *hi2c, float * p_f_icm20602_gyro_data_p, float *p_f_icm20602_acc_data_p);
void Init_Icm20602_Soft(void);
void Read_Icm20602_Data_Soft(float * p_f_icm20602_gyro_data_p, float *p_f_icm20602_acc_data_p);
#ifdef __cplusplus
}
#endif
#endif
/**
******************************************************************************
* File Name : icm20602_driver.c
* Description : This file provides code for the icm_20602 .
******************************************************************************
*
* COPYRIGHT(c) 2016 aibird
*
******************************************************************************
*
* Author:
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
#include "icm20602_driver.h"
#include "soft_iic.h"
/* Private define ------------------------------------------------------------*/
/** @defgroup ICM20602 Device And Register Address
*/
#define ICM20602_DEVICE_ADDRESS (0xD0) //0xD0@SA0=0 0xD2@SA0=1
#define ICM20602_ID_REG_ADDRESS (0x75) //who am i
/*ICM20602配置寄存器*/
#define ICM20602_CFG_REG_ADDR (0x1A)
#define ICM20602_GYRO_CFG_REG_ADDR (0x1B)
#define ICM20602_ACC_CFG_REG_ADDR (0x1C)
#define ICM20602_ACC_CFG2_REG_ADDR (0x1D)
#define ICM20602_GYRO_LPM_CFG_REG_ADDR (0x1E)
/*ICM20602的数据寄存器*/
#define ICM20602_ACC_XOUT_H_REG_ADDR (0x3B)
#define ICM20602_ACC_XOUT_L_REG_ADDR (0x3C)
#define ICM20602_ACC_YOUT_H_REG_ADDR (0x3D)
#define ICM20602_ACC_YOUT_L_REG_ADDR (0x3E)
#define ICM20602_ACC_ZOUT_H_REG_ADDR (0x3F)
#define ICM20602_ACC_ZOUT_L_REG_ADDR (0x40)
#define ICM20602_TMEP_OUT_H_REG_ADDR (0x41)
#define ICM20602_TMEP_OUT_L_REG_ADDR (0x42)
#define ICM20602_GYRO_XOUT_H_REG_ADDR (0x43)
#define ICM20602_GYRO_XOUT_L_REG_ADDR (0x44)
#define ICM20602_GYRO_YOUT_H_REG_ADDR (0x45)
#define ICM20602_GYRO_YOUT_L_REG_ADDR (0x46)
#define ICM20602_GYRO_ZOUT_H_REG_ADDR (0x47)
#define ICM20602_GYRO_ZOUT_L_REG_ADDR (0x48)
/*ICM20602的电源寄存器*/
#define ICM20602_USER_CTRL_REG_ADDR (0x6A)
#define ICM20602_PWR_MGMT_1_REG_ADDR (0x6B)
#define ICM20602_PWR_MGMT_2_REG_ADDR (0x6C)
/* Private variables ---------------------------------------------------------*/
static float f_icm20602_gyro_scale = 1/16.4f; //default 2000dps
static float f_icm20602_acc_scale = 1/16384.f; //default ±2g
/**
* @brief init mpu6050
*/
void Init_Icm20602(I2C_HandleTypeDef *hi2c)
{
uint8_t uc_icm20602_reg_config_value_p;
uint8_t uc_icm20602_reg_value_fdb_p;
/**
* ICM20602_PWR_MGMT_1_REG_ADDR
* bit7-RST 1-trig device reset 0-no action
* bit6-SLEEP 1-SLEEP 0-NORMAL
* bit5-CYCLE 1-ENABLE 0-DISABLE 周期采样ACC
* bit4-GYRO_STANDBY 1-GYRO_SLEEP 0-GYRO_NROMAL
* bit3-TMEP_DIS 1-DISBALE TEMP 0-ENABLE_TEMP
* bit2:0-CLKSEL[2:0] 0or6-internal 20M 1~5-auto clk 7-no clk
*/
uc_icm20602_reg_config_value_p = 0x80; //standby
HAL_I2C_Mem_Write(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_PWR_MGMT_1_REG_ADDR, I2C_MEMADD_SIZE_8BIT, &uc_icm20602_reg_config_value_p, 1, 100);
/*wait ICM20602 RESET completed*/
do
{
HAL_I2C_Mem_Read(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_PWR_MGMT_1_REG_ADDR, I2C_MEMADD_SIZE_8BIT, &uc_icm20602_reg_value_fdb_p, 1, 100);
}while(uc_icm20602_reg_value_fdb_p&0x80);
HAL_Delay(100);
/*auto clk to achieve full gyroscope performance*/
uc_icm20602_reg_config_value_p = 0x01;
HAL_I2C_Mem_Write(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_PWR_MGMT_1_REG_ADDR, I2C_MEMADD_SIZE_8BIT, &uc_icm20602_reg_config_value_p, 1, 100);
/**
* ICM20602_CFG_REG_ADDR
* bit6-FIFO MODE 1-FIFO满了不再填写 0-FIFO满了替换
* bit5:3-EXT_SYNC_SET 1~7-SYNC SOURCE 0-DISABLE
* bit2:0-DLPF_CFG[2:0] DLPF截至频率配置
*/
uc_icm20602_reg_config_value_p = 0x00;
HAL_I2C_Mem_Write(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_CFG_REG_ADDR, I2C_MEMADD_SIZE_8BIT, &uc_icm20602_reg_config_value_p, 1, 100);
/**
* ICM20602_GYRO_CFG_REG_ADDR
* bit7-XG_ST X_GYRO self-test
* bit6-YG_ST Y_GYRO self-test
* bit5-ZG_ST Z_GYRO self-test
* bit4:3-FS_SEL 00-±250dps 01-±500dps 10-±1000dps 11-±2000dps
* bit1:0-FCHOICE_B 1~3-DLPF DISBALE 0-DLPF ENABLE
*/
uc_icm20602_reg_config_value_p = 0x18;
HAL_I2C_Mem_Write(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_GYRO_CFG_REG_ADDR, I2C_MEMADD_SIZE_8BIT, &uc_icm20602_reg_config_value_p, 1, 100);
/*计算陀螺的分辨率*/
f_icm20602_gyro_scale = (1/131.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
/**
* ICM20602_ACC_CFG_REG_ADDR
* bit7-XA_ST X_ACC self-test
* bit6-YA_ST Y_ACC self-test
* bit5-ZA_ST Z_ACC self-test
* bit4:3-FS_SEL 00-±2g 01-±4g 10-±8g 11-±16g
*/
uc_icm20602_reg_config_value_p = 0x00;
HAL_I2C_Mem_Write(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_ACC_CFG_REG_ADDR, I2C_MEMADD_SIZE_8BIT, &uc_icm20602_reg_config_value_p, 1, 100);
/*计算陀螺的分辨率*/
f_icm20602_acc_scale = (1/16384.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
}
/**
* @brief get icm20602 data
* @note 不要再其他位置访问icm20602
* 角速度数据为float类型,存储在float * p_f_icm20602_gyro_data_p (float icm20602_gyro[3])
*/
void Read_Icm20602_Data(I2C_HandleTypeDef *hi2c, float * p_f_icm20602_gyro_data_p, float *p_f_icm20602_acc_data_p)
{
static FlagStatus st_first_read_icm20602_reg_data_flag_p = SET;
uint8_t uc_icm20602_data_p[14];
if(SET == st_first_read_icm20602_reg_data_flag_p)
{
/*读取一次角度寄存器的值,使auto_increment pointer锁定在angle_reg,保证后续读取不需要发送内部寄存器地址*/
HAL_I2C_Mem_Read(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_ACC_XOUT_H_REG_ADDR, I2C_MEMADD_SIZE_8BIT, uc_icm20602_data_p, 14, 100);
st_first_read_icm20602_reg_data_flag_p = RESET;
}
else
{
HAL_I2C_Mem_Read(hi2c, ICM20602_DEVICE_ADDRESS, ICM20602_ACC_XOUT_H_REG_ADDR, I2C_MEMADD_SIZE_8BIT, uc_icm20602_data_p, 14, 100);
}
p_f_icm20602_acc_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[0] <<8 )|uc_icm20602_data_p[1] )*f_icm20602_acc_scale;
p_f_icm20602_acc_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[2] <<8 )|uc_icm20602_data_p[3] )*f_icm20602_acc_scale;
p_f_icm20602_acc_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[4] <<8 )|uc_icm20602_data_p[5] )*f_icm20602_acc_scale;
p_f_icm20602_gyro_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[8] <<8 )|uc_icm20602_data_p[9] )*f_icm20602_gyro_scale;
p_f_icm20602_gyro_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[10] <<8 )|uc_icm20602_data_p[11] )*f_icm20602_gyro_scale;
p_f_icm20602_gyro_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[12] <<8 )|uc_icm20602_data_p[13] )*f_icm20602_gyro_scale;
}
/*--------------------------------------------------模拟I2C读取Icm20602数据--------------------------------------*/
/**
* @brief init Icm20602
*/
uint8_t uc_icm20602_reg_value_fdb_p;
void Init_Icm20602_Soft(void)
{
uint8_t uc_icm20602_reg_config_value_p;
uc_icm20602_reg_value_fdb_p = I2C_Read_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_ID_REG_ADDRESS);
/**
* ICM20602_PWR_MGMT_1_REG_ADDR
* bit7-RST 1-trig device reset 0-no action
* bit6-SLEEP 1-SLEEP 0-NORMAL
* bit5-CYCLE 1-ENABLE 0-DISABLE 周期采样ACC
* bit4-GYRO_STANDBY 1-GYRO_SLEEP 0-GYRO_NROMAL
* bit3-TMEP_DIS 1-DISBALE TEMP 0-ENABLE_TEMP
* bit2:0-CLKSEL[2:0] 0or6-internal 20M 1~5-auto clk 7-no clk
*/
uc_icm20602_reg_config_value_p = 0x80; //standby
I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_PWR_MGMT_1_REG_ADDR, uc_icm20602_reg_config_value_p);
/*wait ICM20602 RESET completed*/
while(I2C_Read_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_PWR_MGMT_1_REG_ADDR)&0x80);
HAL_Delay(100);
/*auto clk to achieve full gyroscope performance*/
uc_icm20602_reg_config_value_p = 0x01;
I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_PWR_MGMT_1_REG_ADDR, uc_icm20602_reg_config_value_p);
/**
* ICM20602_CFG_REG_ADDR
* bit6-FIFO MODE 1-FIFO满了不再填写 0-FIFO满了替换
* bit5:3-EXT_SYNC_SET 1~7-SYNC SOURCE 0-DISABLE
* bit2:0-DLPF_CFG[2:0] DLPF截至频率配置
*/
uc_icm20602_reg_config_value_p = 0x00;
I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_CFG_REG_ADDR, uc_icm20602_reg_config_value_p);
/**
* ICM20602_GYRO_CFG_REG_ADDR
* bit7-XG_ST X_GYRO self-test
* bit6-YG_ST Y_GYRO self-test
* bit5-ZG_ST Z_GYRO self-test
* bit4:3-FS_SEL 00-±250dps 01-±500dps 10-±1000dps 11-±2000dps
* bit1:0-FCHOICE_B 1~3-DLPF DISBALE 0-DLPF ENABLE
*/
uc_icm20602_reg_config_value_p = 0x18;
I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_GYRO_CFG_REG_ADDR, uc_icm20602_reg_config_value_p);
uc_icm20602_reg_value_fdb_p = I2C_Read_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_GYRO_CFG_REG_ADDR);
/*计算陀螺的分辨率*/
f_icm20602_gyro_scale = (1/131.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
/**
* ICM20602_ACC_CFG_REG_ADDR
* bit7-XA_ST X_ACC self-test
* bit6-YA_ST Y_ACC self-test
* bit5-ZA_ST Z_ACC self-test
* bit4:3-FS_SEL 00-±2g 01-±4g 10-±8g 11-±16g
*/
uc_icm20602_reg_config_value_p = 0x00;
I2C_Write_Single_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_ACC_CFG_REG_ADDR, uc_icm20602_reg_config_value_p);
/*计算陀螺的分辨率*/
f_icm20602_acc_scale = (1/16384.f)*(0x01<<( (uc_icm20602_reg_config_value_p&0x18)>>3 ));
}
/**
* @brief get icm20602 data
* @note 不要再其他位置访问icm20602
* 角速度数据为float类型,存储在float * p_f_icm20602_gyro_data_p (float icm20602_gyro[3])
*/
uint8_t uc_icm20602_data_p[14];
float f_icm20602_temp = 0;
void Read_Icm20602_Data_Soft(float * p_f_icm20602_gyro_data_p, float *p_f_icm20602_acc_data_p)
{
static FlagStatus st_first_read_icm20602_reg_data_flag_p = SET;
if(SET == st_first_read_icm20602_reg_data_flag_p)
{
/*读取一次角度寄存器的值,使auto_increment pointer锁定在angle_reg,保证后续读取不需要发送内部寄存器地址*/
I2C_Read_Multi_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_ACC_XOUT_H_REG_ADDR, uc_icm20602_data_p, 14);
st_first_read_icm20602_reg_data_flag_p = RESET;
}
else
{
I2C_Read_Multi_Reg(ICM20602_DEVICE_ADDRESS, ICM20602_ACC_XOUT_H_REG_ADDR, uc_icm20602_data_p, 14);
}
p_f_icm20602_acc_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[0] <<8 )|uc_icm20602_data_p[1] )*f_icm20602_acc_scale;
p_f_icm20602_acc_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[2] <<8 )|uc_icm20602_data_p[3] )*f_icm20602_acc_scale;
p_f_icm20602_acc_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[4] <<8 )|uc_icm20602_data_p[5] )*f_icm20602_acc_scale;
p_f_icm20602_gyro_data_p[0] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[8] <<8 )|uc_icm20602_data_p[9] )*f_icm20602_gyro_scale;
p_f_icm20602_gyro_data_p[1] = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[10] <<8 )|uc_icm20602_data_p[11] )*f_icm20602_gyro_scale;
p_f_icm20602_gyro_data_p[2] = -(float)( ( (int16_t)(int8_t)uc_icm20602_data_p[12] <<8 )|uc_icm20602_data_p[13] )*f_icm20602_gyro_scale;
f_icm20602_temp = (float)( ( (int16_t)(int8_t)uc_icm20602_data_p[6] <<8 )|uc_icm20602_data_p[7] )/326.8 + 25;
}
[/mw_shl_code]
一周热门 更多>