2023-09-27 12:31 PM - edited 2023-09-27 01:39 PM
Hi!
I'm exploring the X-NUCLEO-IKS02A1 with the IIS2MDC magnetometer.
My purpose is read the output data, but I haven't even been able to read the temperature. I'm using I2C through PB8 and PB9 pins, and I have communication cuz' the sensor responds to the command "Who Am I"
After hours of trying, I thought I would read configuration registers A, B and C and I noticed that these are not being affected with my previous writing.
Even worse, register A always reads bits MD0 and MD1 to 1, which means idle mode.
Could the board be locked for use without libraries? The same thing happens with the rest of the sensors.
2023-09-28 02:53 AM
Hello @AraceliGuerrero ,
Could you please try this :
uint8_t temp [2] = {0x2B,0x2C}; /* temperrature registers */
HAL_I2C_Mem_Read(&hi2c1, ,DevAddress, temp ,2, Buffer, 2);
Also you can check this lib :stm32-iis2mdc/iis2mdc_reg.c at main · STMicroelectronics/stm32-iis2mdc · GitHub
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-09-28 08:15 AM
Hi Foued,
The temperature continues to read 0. Thanks for the lib, I'll explore it.
2023-09-28 08:43 AM
Hi @AraceliGuerrero ,
Could you please share with me the main.c file
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-09-28 09:00 AM - edited 2023-09-28 09:02 AM
The structure of my code is strange, but I share the functions with you:
void IIS2DMC_DeviceConfig(void)
{
//The following general-purpose sequence can be used to configure the device
//The device needs 20 ms aprox to downlodad calibration coefficients from the embedded flash
//Enable temperature compensation | Output data rate = 10 Hz | Continuous mode
HAL_I2C_Mem_Write(&hi2c1, WRITE_magneto, CFG_REG_A, 1, (uint8_t *)0x80, 1, I2C_timeout);
//When the boot procedure is completed, the magnetometer enters Idle mode
HAL_I2C_Mem_Write(&hi2c1, WRITE_magneto, CFG_REG_C, 1, (uint8_t *)0x11, 1, I2C_timeout);
//Mag data-ready interrupt enable | BDU
//Who Am I?
HAL_I2C_Mem_Read(&hi2c1, READ_magneto, WHO_AM_I, 1, (uint8_t *)&IIS2DMC_data.ucWhoAmI, 1, I2C_timeout);
}
#define I2C_address_magneto 0x3C
#define READ_magneto 0x3D
#define WRITE_magneto I2C_address_magneto
typedef enum
{
WHO_AM_I = 0x4F,
CFG_REG_A = 0x60,
CFG_REG_B,
CFG_REG_C,
INT_CTRL_REG,
INT_SOURCE_REG,
INT_THS_L_REG,
INT_THS_H_REG,
STATUS_REG,
OUTX_L_REG,
OUTX_H_REG,
OUTY_L_REG,
OUTY_H_REG,
OUTZ_L_REG,
OUTZ_H_REG,
TEMP_OUT_L_REG,
TEMP_OUT_H_REG
}IIS2DMC_Registers_e;
void IIS2DMC_ReadTemperature(void)
{
HAL_I2C_Mem_Read(&hi2c1, READ_magneto, TEMP_OUT_L_REG, 1, (uint8_t *)&IIS2DMC_data.uiTemperature.byte[0], 1, I2C_timeout);
HAL_I2C_Mem_Read(&hi2c1, READ_magneto, TEMP_OUT_H_REG, 1, (uint8_t *)&IIS2DMC_data.uiTemperature.byte[1], 1, I2C_timeout);
}
And the execution is as follows:
After approximately 30 ms since the program starts, I invoke the configuration of registers, then in the RTOS every 200 ms I send the temperature reading command.
2023-09-29 06:44 AM
and if you try to read the temperature with one command :
HAL_I2C_Mem_Read(&hi2c1, READ_magneto, TEMP_OUT_H_REG, 1,IIS2DMC_data.uiTemperature.byte, 1, I2C_timeout);
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-09-29 10:19 AM
Looks like it works... but when I try to read the "L" register, the read freezes. Another problem is that, since it is not in continuous mode, I only get a reading when energizing. And in debug the value remains static.
2023-09-29 12:27 PM
Additionally, the configuration that I cannot modify indicates swapping the bytes, so when reading the H register I am reading the L