Skip to content

New sensor driver SI72XX #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Doc/drivers/si72xx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# SI72XX - Hall Effect Magnetic Position and Temperature Sensor Driver

The Si7210 family of Hall effect magnetic sensors from Silicon Labs combines a
chopper-stabilized Hall element with a low-noise analog amplifier, 13-bit
analog-to-digital converter, and an I2C interface. Leveraging Silicon Labs' proven
CMOS design techniques, the Si7210 family incorporates digital signal processing
to provide precise compensation for temperature and offset drift.

## Sources
- Datasheet: https://www.silabs.com/documents/public/data-sheets/si7210-datasheet.pdf
- Application Note AN1018: https://www.silabs.com/documents/public/application-notes/an1018-si72xx-sensors.pdf

## Setup the SI72XX
As all the drivers you need to enable it and setup it in the _configDrivers.h_

## Using the SI72XX

### SI72XX HW versions


Constant declared in `drivers/hall/si72xx/si72xx.h`

```C
#define SI72XX_ADDR_0 0x30
#define SI72XX_ADDR_1 0x31
#define SI72XX_ADDR_2 0x32
#define SI72XX_ADDR_3 0x33
```

Based on the sensor version must be used proper I2C address:
- SI72XX_ADDR_0 (0x30):
- Si7210-B-00-IV(R)
- Si7210-B-01-IV(R)
- Si7210-B-10-IM2(R)
- Si7210-B-11-IM2(R)
- SI72XX_ADDR_1 (0x31):
- Si7210-B-02-IV(R)
- Si7210-B-12-IM2(R)
- SI72XX_ADDR_2 (0x32):
- Si7210-B-03-IV(R)
- Si7210-B-13-IM2(R)
- SI72XX_ADDR_3 (0x33):
- Si7210-B-04-IV(R)
- Si7210-B-05-IV(R)
- Si7210-B-14-IM2(R)
- Si7210-B-15-IM2(R)


### Measurement of magnetic field

Read magnetic field with sensor SI72XX_ADDR_0 and go to sleep.

```C
...

int16_t data = 0;

if (Si72xx_ReadMagFieldDataAndSleep(SI72XX_ADDR_0, SI7210_20MT, SI72XX_SLEEP_MODE, &data) == __SI72XX_OK)
{
return __SI72XX_ERROR;
}

return data;

...
```

### Measurement of temperature

Read temperature with sensor SI72XX_ADDR_0 and go to sleep.

```C
...

int32_t temp_mC = 0; /* output in milli Celsius */

if (Si72xx_ReadTemperatureAndSleep(SI72XX_ADDR_0, &temp_mC) != __SI72XX_OK)
{
return __SI72XX_ERROR;
}

return temp_mC;

...
```
154 changes: 154 additions & 0 deletions Inc/drivers/hall/si72xx/si72xx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/* ==========================================================
* si72xx.h - Driver for the Si72xx Hall Effect Sensor
* ----------------------------------------------------------
*
* Created on: 21 dec 2021
* Author: Zbynek Kocur
* ----------------------------------------------------------
* Copyright (C) 2021 CTU in Prague
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU LESSER General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* ==========================================================
* Datasheet - https://www.silabs.com/documents/public/data-sheets/si7210-datasheet.pdf
* App Note - AN1018: Using the Si72xx Hall-effect Magnetic Position Sensors - https://www.silabs.com/documents/public/application-notes/an1018-si72xx-sensors.pdf
*
* ==========================================================
* Some peaces of that code directly comes from Silicon Laboratories Inc.
* and identified with << Copyright 2018 Silicon Laboratories Inc. www.silabs.com >>
*
* ==========================================================
*/

#ifndef DRIVERS_HALL_SI72XX_SI72XX_H
#define DRIVERS_HALL_SI72XX_SI72XX_H

/*******************************************************************************
******************************* DEFINES ***********************************
******************************************************************************/

/** I2C device address for Si72xx */
#define SI72XX_ADDR_0 0x30
#define SI72XX_ADDR_1 0x31
#define SI72XX_ADDR_2 0x32
#define SI72XX_ADDR_3 0x33

/** I2C registers for Si72xx */
#define SI72XX_HREVID 0xC0
#define SI72XX_DSPSIGM 0xC1
#define SI72XX_DSPSIGL 0xC2
#define SI72XX_DSPSIGSEL 0xC3
#define SI72XX_POWER_CTRL 0xC4
#define SI72XX_ARAUTOINC 0xC5
#define SI72XX_CTRL1 0xC6
#define SI72XX_CTRL2 0xC7
#define SI72XX_SLTIME 0xC8
#define SI72XX_CTRL3 0xC9
#define SI72XX_A0 0xCA
#define SI72XX_A1 0xCB
#define SI72XX_A2 0xCC
#define SI72XX_CTRL4 0xCD
#define SI72XX_A3 0xCE
#define SI72XX_A4 0xCF
#define SI72XX_A5 0xD0
#define SI72XX_OTP_ADDR 0xE1
#define SI72XX_OTP_DATA 0xE2
#define SI72XX_OTP_CTRL 0xE3
#define SI72XX_TM_FG 0xE4

#define SI72XX_OTP_20MT_ADDR 0x21
#define SI72XX_OTP_200MT_ADDR 0x27

/*******************************************************************************
******************************** ENUMS ************************************
******************************************************************************/
/** Si72xx magnetic field full-scales */
typedef enum {
SI7210_20MT,
SI7210_200MT
} Si72xxFieldScale_t;

/** Si72xx sleep modes */
typedef enum {
SI72XX_SLEEP_MODE,
SI72XX_SLTIMEENA_MODE,
SI72XX_IDLE_MODE
} Si72xxSleepMode_t;


/*!
* @brief Si72xx API status result code.
*/
typedef enum drivers_si72xx_ret_e
{
__SI72XX_OK = 0,
__SI72XX_ERROR = 1,
__SI72XX_BUSY = 2,
__SI72XX_TIMEOUT = 3, /* until here, I2C errors (cf. _I2C_Status) */
__SI72XX_NODATA = 4,
__SI72XX_MISCALIB = 5,
__SI72XX_UNKNOWN = 6,
__SI72XX_INVALID_ARG = 7
} drivers_si72xx_ret_e;

/*******************************************************************************
***************************** PROTOTYPES **********************************
******************************************************************************/

drivers_si72xx_ret_e Si72xx_WakeUpAndIdle(uint8_t addr);
drivers_si72xx_ret_e Si72xx_Read_MagField_Data(uint8_t addr,
int16_t *magData);
drivers_si72xx_ret_e Si72xx_FromIdle_GoToSleep(uint8_t addr);
drivers_si72xx_ret_e Si72xx_FromIdle_GoToSltimeena(uint8_t addr);

drivers_si72xx_ret_e Si72xx_Set_mT_Range(uint8_t addr,
Si72xxFieldScale_t mTScale);
drivers_si72xx_ret_e Si72xx_ReadMagFieldDataAndSleep(uint8_t addr,
Si72xxFieldScale_t mTScale,
Si72xxSleepMode_t sleepMode,
int16_t *magFieldData);
drivers_si72xx_ret_e Si72xx_EnterSleepMode(uint8_t addr,
Si72xxSleepMode_t sleepMode);
drivers_si72xx_ret_e Si72xx_EnterLatchMode (uint8_t addr);
drivers_si72xx_ret_e Si72xx_ReadTemperatureAndSleep(uint8_t addr,
int32_t *rawTemp);
drivers_si72xx_ret_e Si72xx_ReadCorrectedTempAndSleep(uint8_t addr,
int16_t offsetData,
int16_t gainData,
int32_t *correctedTemp);
drivers_si72xx_ret_e Si72xx_ReadTempCorrectionDataAndSleep(uint8_t addr,
int16_t *offsetValue,
int16_t *gainValue);

drivers_si72xx_ret_e Si72xx_IdentifyAndSleep(uint8_t addr,
uint8_t *partId,
uint8_t *partRev);
drivers_si72xx_ret_e Si72xx_ReadVariantAndSleep(uint8_t addr,
uint8_t *basePn,
uint8_t *pnVariant);
drivers_si72xx_ret_e Si72xx_SelfTest(uint8_t addr);


// =============================================================================================

int32_t Si72xx_ConvertDataCodesToMagneticField(Si72xxFieldScale_t fieldScale, int16_t dataCode);

drivers_si72xx_ret_e Si72xx_Set_Threshold (uint8_t addr,
Si72xxFieldScale_t mTScale,
float threshold);
drivers_si72xx_ret_e Si72xx_Set_Hysteresis (uint8_t addr,
Si72xxFieldScale_t mTScale,
float hysteresis);
drivers_si72xx_ret_e Debug_Si72xx_register (uint8_t addr);

#endif /* DRIVERS_HALL_SI72XX_SI72XX_H */
9 changes: 6 additions & 3 deletions Inc/drivers/lorawan/utilities.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ typedef uint32_t TimerTime_t;
* \param [IN] b 2nd value
* \retval minValue Minimum value
*/
#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#ifndef MIN
#define MIN( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) )
#endif

/*!
* \brief Returns the maximum value between a and b
Expand All @@ -79,8 +81,9 @@ typedef uint32_t TimerTime_t;
* \param [IN] b 2nd value
* \retval maxValue Maximum value
*/
#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )

#ifndef MAX
#define MAX( a, b ) ( ( ( a ) > ( b ) ) ? ( a ) : ( b ) )
#endif
/*!
* \brief Returns 2 raised to the power of n
*
Expand Down
13 changes: 13 additions & 0 deletions Inc/it_sdk/configDrivers.h.template
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,18 @@
#define ITSDK_DRIVERS_SL353_INT_BANK __BANK_A // HALL pin configuration
#define ITSDK_DRIVERS_SL353_INT_PIN __LP_GPIO_0 // __LP_GPIO_NONE if not used

// ------------------------------------------------------------------------
// Hall : SI72XX

#define ITSDK_DRIVERS_SI72XX __DISABLE // Si72xx Hall Effect Sensor
#if ITSDK_DRIVERS_SI72XX == __ENABLE
#ifndef __I2C_INCLUDED
#define __I2C_INCLUDED
#include "i2c.h"
#endif
#include <drivers/hall/si72xx/si72xx.h>
#endif
#define ITSDK_DRIVERS_SI72XX_I2C hi2c1 // I2C port to be used for communications


#endif /* INC_IT_SDK_CONFIGDRIVERS_H_ */
Loading