Ultra low-power, high performance 3-axis magnetometer.
Dependencies: ST_INTERFACES X_NUCLEO_COMMON
Dependents: HelloWorld_ST_Sensors MOTENV_Mbed mbed-os-mqtt-client DISCO-IOT01_HomeEnv ... more
Diff: lis3mdl_class.cpp
- Revision:
- 1:d85092ab306e
- Parent:
- 0:7376fbeb1d4a
- Child:
- 4:00493226e59f
--- a/lis3mdl_class.cpp Tue Sep 05 10:15:14 2017 +0000 +++ b/lis3mdl_class.cpp Thu Sep 07 12:27:45 2017 +0000 @@ -53,6 +53,17 @@ MAGNETO_StatusTypeDef LIS3MDL::LIS3MDL_Init(MAGNETO_InitTypeDef *LIS3MDL_Init) { uint8_t tmp1 = 0x00; + MAGNETO_InitTypeDef *initStructure = LIS3MDL_Init; + + if (initStructure == NULL) {// default params + MAGNETO_InitTypeDef tempInit; + tempInit.M_FullScale = LIS3MDL_M_FS_4; + tempInit.M_OperatingMode = LIS3MDL_M_MD_CONTINUOUS; + tempInit.M_XYOperativeMode = LIS3MDL_M_OM_HP; + tempInit.M_OutputDataRate = LIS3MDL_M_DO_80; + initStructure = &tempInit; + } + /* Configure the low level interface ---------------------------------------*/ if(LIS3MDL_IO_Init() != MAGNETO_OK) @@ -69,7 +80,7 @@ /* Conversion mode selection */ tmp1 &= ~(LIS3MDL_M_MD_MASK); - tmp1 |= LIS3MDL_Init->M_OperatingMode; + tmp1 |= initStructure->M_OperatingMode; if(LIS3MDL_IO_Write(&tmp1, LIS3MDL_M_CTRL_REG3_M, 1) != MAGNETO_OK) { @@ -83,11 +94,11 @@ /* Output data rate selection */ tmp1 &= ~(LIS3MDL_M_DO_MASK); - tmp1 |= LIS3MDL_Init->M_OutputDataRate; + tmp1 |= initStructure->M_OutputDataRate; /* X and Y axes Operative mode selection */ tmp1 &= ~(LIS3MDL_M_OM_MASK); - tmp1 |= LIS3MDL_Init->M_XYOperativeMode; + tmp1 |= initStructure->M_XYOperativeMode; if(LIS3MDL_IO_Write(&tmp1, LIS3MDL_M_CTRL_REG1_M, 1) != MAGNETO_OK) { @@ -101,7 +112,7 @@ /* Full scale selection */ tmp1 &= ~(LIS3MDL_M_FS_MASK); - tmp1 |= LIS3MDL_Init->M_FullScale; + tmp1 |= initStructure->M_FullScale; if(LIS3MDL_IO_Write(&tmp1, LIS3MDL_M_CTRL_REG2_M, 1) != MAGNETO_OK) {