4251 views|12 replies

17

Posts

0

Resources
The OP
 

Using the sensor hub mode of lsm6dsl to drive lis2mdl output data unchanged [Copy link]

 
 

I configured LIS2MDL according to the magnet calibration example in "an5040-LSM6DSL: Always-On 3D Accelerometer and 3D Gyroscope.pdf" and tried to read three sets of data from the three registers OUT_MAG_RAW_X_L, SENSORHUB1_REG, and SENSORHUB13_REG, but the actual output did not change. It did not change even when I shook a magnet over the sensor. Can you help me figure out what's going on?

I have tried to drive according to the official driver of lsm6dsl. The code is as follows

int32_t LSM6DSL_SensorHub_Init(void)
{
  // 1. 将 80h 写入 FUNC_CFG_ACCESS // 使能对嵌入功能寄存器的访问(A 区)
  // 2. 将 3Ch 写入 SLV0_ADD // LIS2MDL 从设备地址 = 0011110b
  //    使能写操作(rw_0=0)
  // 3. 将 60h 写入 SLV0_SUBADD // 60h 为待写入的 LIS2MDL 寄存器
  // 4. 将 8Ch 写入 DATAWRITE_SRC_MODE_SUB_SLV0 // 8Ch 为写入到 LIS2MDL 的寄存器 60h 的值
  //    以将其配置为 Continue 模式,
  //    ODR = 100 Hz,温度补偿使能

  uint8_t w_data = 0;

  lsm6dsl_sh_cfg_write_t sh_cfg_write;
  sh_cfg_write.slv0_add = 0x3C;
  sh_cfg_write.slv0_subadd = 0x60;
  sh_cfg_write.slv0_data = 0x8C;

  if (lsm6dsl_sh_cfg_write(&sh_cfg_write) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 5. 将 10h 写入 SLAVE0_CONFIG // 将 Aux_sens_on 位设置为不等于 00b
  if (lsm6dsl_sh_num_of_dev_connected_set(LSM6DSL_SLV_0_1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 6. 将 20h 写入 SLAVE1_CONFIG // 使能 write_once 位
  // 7. 将 00h 写入 FUNC_CFG_ACCESS // 禁用对嵌入功能寄存器的访问(A 区)
  if (lsm6dsl_sh_write_mode_set(LSM6DSL_ONLY_FIRST_CYCLE) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 8. 将 04h 写入 CTRL10_C // 使能嵌入功能
  if (lsm6dsl_func_en_set(1) != LSM6DSL_OK) // lsm6dsl_func_en_set lsm6dsl_pedo_sens_set
  {
    return LSM6DSL_ERROR;
  }

  // 9. 将 09h 写入 MASTER_CONFIG // 使能 SDx/SCx 线上的内部上拉
  //    传感器集合(sensor hub)触发信号为 XL 数据准备就绪
  //    使能辅助 I2C 主线
  if (lsm6dsl_sh_pin_mode_set(LSM6DSL_INTERNAL_PULL_UP) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }
  if (lsm6dsl_sh_master_set(1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 10. 将 80h 写入 CTRL1_XL // 开启加速度计(以获取触发信号)
  if (lsm6dsl_xl_data_rate_set(LSM6DSL_XL_ODR_1k66Hz) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  lsm6dsl_func_src1_t func_src1 = {0};
  func_src1.sensorhub_end_op = 0;
  do
  {
    // 11. 读取 FUNC_SRC1 // 等待传感器集合通信结束
    // 12. 如果 SENSORHUB_END_OP = 0,转到 9
    if (lsm6dsl_read_reg(LSM6DSL_FUNC_SRC1, (uint8_t *)&func_src1, 1) != LSM6DSL_OK)
    {
      return LSM6DSL_ERROR;
    }
  } while (func_src1.sensorhub_end_op == 0);

  // 13. 将 00h 写入 CTRL10_C // 禁用嵌入功能
  w_data = 0;
  if (lsm6dsl_write_reg(LSM6DSL_CTRL10_C, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }
  // 14. 将 00h 写入 MASTER_CONFIG // 禁用辅助 I2C 主线
  if (lsm6dsl_write_reg(LSM6DSL_MASTER_CONFIG, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }
  // 15. 将 00h 写入 CTRL1_XL // 关闭加速度计
  if (lsm6dsl_write_reg(LSM6DSL_CTRL1_XL, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 16. 将 80h 写入 FUNC_CFG_ACCESS // 使能对嵌入功能寄存器的访问(A 区)
  //     使能读操作(rw_0=1)
  // 18. 将 68h 写入 SLV0_SUBADD     // 68h 为待读取的第一个 LIS2MDL 输出寄存器
  // 19. 将 06h 写入 SLAVE0_CONFIG   // 无抽取
  //                                 // 连接了 1 个外部传感器
  //                                 // 读取的寄存器数 = 6
  if (lsm6dsl_mem_bank_set(LSM6DSL_BANK_A) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  w_data = 0x3D;
  if (lsm6dsl_write_reg(LSM6DSL_SLV0_ADD, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }
  w_data = 0x68;
  if (lsm6dsl_write_reg(LSM6DSL_SLV0_SUBADD, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }
  w_data = 0x06;
  if (lsm6dsl_write_reg(LSM6DSL_SLAVE0_CONFIG, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 20. 将 FFh 写入 MAG_OFFX_H // X 偏移值初始化
  // 21. 将 20h 写入 MAG_OFFX_L // X 偏移值初始化
  // 22. 将 00h 写入 MAG_OFFY_H // Y 偏移值初始化
  // 23. 将 54h 写入 MAG_OFFY_L // Y 偏移值初始化
  // 24. 将 FFh 写入 MAG_OFFZ_H // Z 偏移值初始化
  // 25. 将 B4h 写入 MAG_OFFZ_L // Z 偏移值初始化
  // 26. 将 0Ah 写入 MAG_SI_XX  // XX 软磁参数
  // 27. 将 01h 写入 MAG_SI_XY  // XY 软磁参数
  // 28. 将 00h 写入 MAG_SI_XZ  // XZ 软磁参数
  // 29. 将 01h 写入 MAG_SI_YX  // YX 软磁参数
  // 30. 将 08h 写入 MAG_SI_YY  // YY 软磁参数
  // 31. 将 81h 写入 MAG_SI_YZ  // YZ 软磁参数
  // 32. 将 00h 写入 MAG_SI_ZX  // ZX 软磁参数
  // 33. 将 81h 写入 MAG_SI_ZY  // ZY 软磁参数
  // 34. 将 0Ah 写入 MAG_SI_ZZ  // ZZ 软磁参数
  // 35. 将 00h 写入 FUNC_CFG_ACCESS // 禁用对嵌入功能寄存器的访问(A 区)

  uint8_t mag_off[6] = {0x20, 0xFF, 0x54, 0x00, 0xB4, 0xFF};
  uint8_t mag_si[9] = {0x0A, 0x01, 0x00, 0x01, 0x08, 0x81, 0x00, 0x81, 0x0A};

  if (lsm6dsl_write_reg(LSM6DSL_MAG_OFFX_H, mag_off, 6) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }
  if (lsm6dsl_write_reg(LSM6DSL_MAG_SI_XX, mag_si, 9) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  if (lsm6dsl_mem_bank_set(LSM6DSL_USER_BANK) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 36. 将 04h 写入 CTRL10_C // 使能嵌入功能
  if (lsm6dsl_func_en_set(1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 37. 将 0Bh 写入 MASTER_CONFIG // 使能 SDx/SCx 线上的内部上拉
  //     传感器集合(sensor hub)触发信号为 XL 数据准备就绪
  //     使能硬磁校准
  //     使能辅助 I2C 主线
  w_data = 0x0B;
  if (lsm6dsl_write_reg(LSM6DSL_MASTER_CONFIG, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  // 38. 将 04h 写入 CTRL9_XL // 使能软磁校准
  w_data = 0x04;
  if (lsm6dsl_write_reg(LSM6DSL_CTRL9_XL, &w_data, 1) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }
  // 39. 将 80h 写入 CTRL1_XL // 开启加速度计(以获取触发信号)
  if (lsm6dsl_xl_data_rate_set(LSM6DSL_XL_ODR_1k66Hz) != LSM6DSL_OK)
  {
    return LSM6DSL_ERROR;
  }

  return LSM6DSL_OK;
}

The second method uses the read and write register driver of lsm6dsl

/**
 * [url=home.php?mod=space&uid=159083]@brief[/url] Configure Demo
 * @param  None
 * @retval COMPONENT_OK
 * @retval COMPONENT_ERROR
 */
uint8_t Demo_Config(void)
{
	uint8_t writeData = 0x80;
	lsm6dsl_func_src1_t readData = {0};
	
	//1.使能对嵌入功能寄存器的访问(A 区)
	lsm6dsl_write_reg(LSM6DSL_FUNC_CFG_ACCESS, &writeData, 1);
	
	//2.LIS2MDL 从设备地址 = 0011110b
	writeData = 0x3cU;
	lsm6dsl_write_reg(LSM6DSL_SLV0_ADD, &writeData, 1);
	
	//3.60h 为待写入的 LIS2MDL 寄存器
	writeData = 0x60;
	lsm6dsl_write_reg(LSM6DSL_SLV0_SUBADD, &writeData, 1);
	
	//4. 8Ch 为写入到 LIS2MDL 的寄存器 60h 的值, Continue 模式 ODR = 100 Hz
	writeData = 0x8c;
	lsm6dsl_write_reg(LSM6DSL_DATAWRITE_SRC_MODE_SUB_SLV0, &writeData, 1);
	
	//5.将 Aux_sens_on 位设置为不等于 00b
	writeData = 0x10;
	lsm6dsl_write_reg(LSM6DSL_SLAVE0_CONFIG, &writeData, 1);
	
	//6.使能 write_once 位
	writeData = 0x20;
	lsm6dsl_write_reg(LSM6DSL_SLAVE1_CONFIG, &writeData, 1);
	
	//7.禁用对嵌入功能寄存器的访问(A 区)
	writeData = 0x00;
	lsm6dsl_write_reg(LSM6DSL_FUNC_CFG_ACCESS, &writeData, 1);
	
	//8.使能嵌入功能
	writeData = 0x04;
	lsm6dsl_write_reg(LSM6DSL_CTRL10_C, &writeData, 1);
	
	do{
		//9.使能 SDx/SCx 线上的内部上拉  传感器集合(sensor hub)触发信号为 XL 数据准备就绪
		writeData = 0x09;
		lsm6dsl_write_reg(LSM6DSL_MASTER_CONFIG, &writeData, 1);
		
		//10.开启加速度计(以获取触发信号)
		writeData = 0x80;
		lsm6dsl_write_reg(LSM6DSL_CTRL1_XL, &writeData, 1);
		
		//11.等待传感器集合通信结束 
		//12.SENSORHUB_END_OP = 0,转到 9
		lsm6dsl_read_reg(LSM6DSL_FUNC_SRC1, (uint8_t *)&readData, 1);
	} while(!readData.sensorhub_end_op);
	
	//13.禁用嵌入功能
	writeData = 0x00;
	lsm6dsl_write_reg(LSM6DSL_CTRL10_C, &writeData, 1);
	
	//14.禁用辅助 I2C 主线
	writeData = 0x00;
	lsm6dsl_write_reg(LSM6DSL_MASTER_CONFIG, &writeData, 1);
	
	//15.关闭加速度计
	writeData = 0x00;
	lsm6dsl_write_reg(LSM6DSL_CTRL1_XL, &writeData, 1);
	
	//16.使能对嵌入功能寄存器的访问(A 区)
	writeData = 0x80;
	lsm6dsl_write_reg(LSM6DSL_FUNC_CFG_ACCESS, &writeData, 1);
	
	//17.LIS2MDL 从设备地址 = 0011110b
	writeData = 0x3dU;
	lsm6dsl_write_reg(LSM6DSL_SLV0_ADD, &writeData, 1);
	
	//18. 68h 为待读取的第一个 LIS2MDL 输出寄存器
	writeData = 0x68;
	lsm6dsl_write_reg(LSM6DSL_SLV0_SUBADD, &writeData, 1);
	
	//19. 无抽取;连接了 1 个外部传感器
	writeData = 0x06;
	lsm6dsl_write_reg(LSM6DSL_SLAVE0_CONFIG, &writeData, 1);
	
	//20~34
	uint8_t mag_off[6] = {0x20, 0xFF, 0x54, 0x00, 0xB4, 0xFF};
	uint8_t mag_si[9] = {0x0A, 0x01, 0x00, 0x01, 0x08, 0x81, 0x00, 0x81, 0x0A};
	lsm6dsl_write_reg(LSM6DSL_MAG_OFFX_L, mag_off, 6);
	lsm6dsl_write_reg(LSM6DSL_MAG_SI_XX, mag_si, 9);
	
	//35.禁用对嵌入功能寄存器的访问(A 区)
	writeData = 0x00;
	lsm6dsl_write_reg(LSM6DSL_FUNC_CFG_ACCESS, &writeData, 1);
	
	//36.使能嵌入功能
	writeData = 0x04;
	lsm6dsl_write_reg(LSM6DSL_CTRL10_C, &writeData, 1);
	
	//37.使能 SDx/SCx 线上的内部上拉
	writeData = 0x0b;
	lsm6dsl_write_reg(LSM6DSL_MASTER_CONFIG, &writeData, 1);
	
	//38.使能软磁校准
	writeData = 0x04;
	lsm6dsl_write_reg(LSM6DSL_CTRL9_XL, &writeData, 1);
	
	//39.开启加速度计(以获取触发信号)
	writeData = 0x80;
	lsm6dsl_write_reg(LSM6DSL_CTRL1_XL, &writeData, 1);
}

And read the register, but the value obtained has not changed

	lsm6dsl_read_reg(LSM6DSL_SENSORHUB13_REG, caliMag, 6);
	lsm6dsl_read_reg(LSM6DSL_SENSORHUB1_REG, cali2Mag, 6);
	lsm6dsl_read_reg(LSM6DSL_OUT_MAG_RAW_X_L, rawMag, 6);

I also refer to the official "STM32CubeExpansion_MEMS-XT1_V4.4.0" example, but it doesn't seem to help my project.

This post is from MEMS sensors

Latest reply

So the data reading is normal now, right? For attitude fusion, check the 8-character calibration and the direction setting of each axis of the sensor.  Details Published on 2022-3-18 16:08
 
 

9717

Posts

24

Resources
2
 

Can you make sure that the hardware is working properly? For example, can the LIS2MDL be read by the microcontroller alone? Are the I2C resistors soldered?

This post is from MEMS sensors

Comments

Soldered, tried lsm6dsl and lis2mdl can work separately  Details Published on 2022-3-18 10:13
Soldered, tried lsm6dsl and lis2mdl can work separately  Details Published on 2022-3-18 10:12
 
 
 

17

Posts

0

Resources
3
 
littleshrimp posted on 2022-3-18 10:03 Can you confirm that the hardware is working properly now? For example, is the lis2mdl read normally through the microcontroller alone, and are the I2C resistors soldered?

Soldered, tried lsm6dsl and lis2mdl can work separately

This post is from MEMS sensors
 
 
 

17

Posts

0

Resources
4
 
littleshrimp posted on 2022-3-18 10:03 Can you confirm that the hardware is working properly now? For example, is the lis2mdl read normally through the microcontroller alone, and are the I2C resistors soldered?

When I was writing the question just now, I thought of initializing the lsm6dsl first and then starting the sensor hub mode, but it seems that nothing changed.

This post is from MEMS sensors

Comments

Can I get the correct data by using lsm6dsl to read the WHO_AM_I register of lis2mdl?  Details Published on 2022-3-18 11:07
 
 
 

17

Posts

0

Resources
5
 

Initialize lsm6dsl first and then use the configuration of the routine to obtain the magnetic data in the register.

This post is from MEMS sensors

Comments

You said that you can read magnetic data. Will this data still not be affected by the magnetic field?  Details Published on 2022-3-18 11:32
 
 
 

9717

Posts

24

Resources
6
 
wfagly posted on 2022-3-18 10:13 When I wrote the question just now, I thought of initializing the lsm6dsl first and then starting the sensor hub mode, but it seems that nothing has changed

Can I get the correct data by using lsm6dsl to read the WHO_AM_I register of lis2mdl?

This post is from MEMS sensors

Comments

uint8_t whoamI = 0; lsm6dsl_read_lis2mdl_cx(LIS2MDL_ADDR_CHIPID, &whoamI, 1); printf("whoamI is %x\r\n", whoamI); The value read is 40, which is correct  Details Published on 2022-3-18 11:20
 
 
 

17

Posts

0

Resources
7
 
littleshrimp posted on 2022-3-18 11:07 Can I get the correct data by using lsm6dsl to read the WHO_AM_I register of lis2mdl?

uint8_t whoamI = 0;
lsm6dsl_read_lis2mdl_cx(LIS2MDL_ADDR_CHIPID, &whoamI, 1);
printf("whoamI is %x\r\n", whoamI);

The reading is 40, which is correct.

This post is from MEMS sensors
 
 
 

9717

Posts

24

Resources
8
 
wfagly posted on 2022-3-18 10:55 First initialize lsm6dsl and then use the configuration of the routine to obtain the magnetic data in the register

You said that you can read magnetic data. Will this data still not be affected by the magnetic field?

This post is from MEMS sensors

Comments

The data read is affected by magnetic force, but the heading angle I get using the MadgwickAHRSupdate algorithm is not accurate.  Details Published on 2022-3-18 14:17
 
 
 

1w

Posts

25

Resources
9
 

Is the magnetometer enable bit set?

This post is from MEMS sensors

Comments

Enabled, continuous mode turned on  Details Published on 2022-3-18 14:18
 
 
 

17

Posts

0

Resources
10
 
littleshrimp posted on 2022-3-18 11:32 You said that you can read magnetic data. Is this data still not affected by the magnetic field?

The data read is affected by magnetic force , but the heading angle I get using the MadgwickAHRSupdate algorithm is not accurate.

This post is from MEMS sensors

Comments

So the data reading is normal now, right? For attitude fusion, check the 8-character calibration and the direction setting of each axis of the sensor.  Details Published on 2022-3-18 16:08
 
 
 

17

Posts

0

Resources
11
 
dcexpert posted on 2022-3-18 11:44 Is the enable bit of the magnetometer set?

Enabled, continuous mode turned on

This post is from MEMS sensors
 
 
 

9717

Posts

24

Resources
12
 
wfagly posted on 2022-3-18 14:17 The data read is affected by magnetic force, but the heading angle I get using the MadgwickAHRSupdate algorithm is not accurate

So the data reading is normal now, right?
For attitude fusion, check the 8-character calibration and the direction setting of each axis of the sensor.

This post is from MEMS sensors

Comments

The direction of the axis has been adjusted when driving a single drive. Now I am still looking at which unit the algorithm needs for the magnetometer, accelerometer, and gyroscope, Gauss or uT, m/s or something, rad/s, etc.  Details Published on 2022-3-18 17:07
 
 
 

17

Posts

0

Resources
13
 
littleshrimp posted on 2022-3-18 16:08 So the data reading is normal now, right? For attitude fusion, take a look at the 8-character calibration and the direction settings of the sensor axes.

The direction of the axis has been adjusted when driving a single drive. Now I am still looking at which unit the algorithm needs for the magnetometer, accelerometer, and gyroscope, Gauss or uT, m/s or something, rad/s, etc.

This post is from MEMS sensors
 
 
 

Find a datasheet?

EEWorld Datasheet Technical Support

Featured Posts
High-frequency power transformer design principles, requirements and procedures

Xu Zewei, editor of International Electronic Transformer    Abstract: Starting from the high-frequency power transfor ...

PCB LAYOUT Manual

PCB Design Documentation PCB LAYOUT Manual

Research on the difference between left and right channel signals of audio

This post was last edited by bqgup on 2020-9-18 14:31 # Exploration of the difference between left and right channel s ...

[Raspberry Pi Pico Review]——by fxyc87

@fxyc87 - Unboxing + Download - Start Programming - Start compiling the program 2 - How to save the written progra ...

[Sipeed LicheeRV 86 Panel Review] Using crosstool-ng to build a compiler for riscv64

Use crosstool-ng to build the compiler for riscv64 crosstool-ng, the full name is crosstool Next Generation, which is t ...

Recruiting a product development manager, based in Shenzhen

Job Responsibilities: 1. Gain insight into the market, understand product user needs, develop product plans, and be res ...

MOS tube selection problem

I want to use a SOT23 MOS tube to drive a 24V/180MA solenoid valve. The maximum power dissipation here is 2.5W, but 24*0 ...

【MSPM0L1306 LaunchPad Development Kit】2. Configure the development environment and download and run the first program

If you want to quickly understand a new board, the first step is to obtain some basic information. In this usage activit ...

First release! Allwinner T527 first core board, high-performance 8-core processor with AI NPU

Today, Mir Electronics and its strategic partner Allwinner Technology have jointly launched the first T527 core board an ...

Silicon integrated circuit process fundamentals

The book has a total of ten chapters. The first chapter briefly describes the crystal structure of silicon. Chapters 2 t ...

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list