8.2.1. SFH7773 (OSRAM Opto)

8.2.1.1. Introduction

The SFH 7773 combines a digital ambient light sensor and a proximity sensor (emitter + detector) within one package. Additionally the sensor provides an I2C-bus interface and an interrupt pin to connect it to an microcontroller. It consists of an 850 nm infrared (IR) LED and an ultra-low power ASIC which performs the signal processing and provides the I2C-bus interface as well as an interrupt alert function. Additionally the ASIC contains the two photodiodes for proximity and ambient light sensing.

Proximity Sensor (PS) has a detection range up to 150 mm. Sensor output is 0-254. Ambient Light Sensor (ALS) has a range of 0.03 lx - 65000 lx. Sensor output is 0-65535. I2C interface is programmable in three modes with low current consumption in standby mode.

8.2.1.2. Applications

Typical application areas are mobile phones, PDAs, notebooks, cameras and other consumer products. Common tasks for the integrated ambient light sensor are display brightness adjustments, whereas the proximity sensor is usually employed to detect objects and motions.

8.2.1.3. Resources

8.2.1.4. Platform Integration

The sensor can be enabled by defining compile-time flag PLTFRM_SFH_7773_SENSOR_ENA.

8.2.1.4.1. Functions

PLTFRM_sts_t SFH_7773_init(UINT8_t devId)

Initializes the sensor and puts in SFH_7773_OPN_MODE_STAND_BY mode. This function is typically called during platform initialization.

Parameters:
  • devId – Identity of the device.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. One possible error is PLTFRM_STS_INV_DEV_ID.

PLTFRM_sts_t SFH_7773_swReset(UINT8_t devId)

Performs a software reset of the device. If successful, device context is update with mode as SFH_7773_OPN_MODE_STAND_BY. If not, mode is updated as SFH_7773_OPN_MODE_UNKNOWN.

Parameters:
  • devId – Identity of the device.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

PLTFRM_sts_t SFH_7773_startALSConv(UINT8_t devId, SINT32_t *luxVal_p, UINT16_t *tmoVal_p)

Trigger the sensor to start sensing and conversion of ambient light intensity. If device is in SFH_7773_OPN_MODE_FREE_RUNNING mode, value is returned immediately. If device is in SFH_7773_OPN_MODE_TRIGGERED mode, conversion is triggered. Time to wait for data is returned to caller.

Parameters:
  • devId – Identity of the device.
  • luxVal_p – Points to location where luminance value is returned. This is applicable in SFH_7773_OPN_MODE_FREE_RUNNING mode.
  • tmoVal_p – Points to location where sensor integration time is returned. This is applicable in SFH_7773_OPN_MODE_TRIGGERED mode. Caller may use this value to implement a timer and callback function to read the value once it is available. This time is in milliseconds.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. One possible error is PLTFRM_STS_INV_DEV_ID.

PLTFRM_sts_t SFH_7773_cfgALSOpnMode(UINT8_t devId, SFH_7773_mode_t reqOpnMode, UINT16_t *opnTime_p)

Configures the sensor in a certain operation mode. Please note that write cycle on I2C interface happens only if there is a change in mode. When there is a change in mode, time duration required to make this transition is returned to the caller.

Parameters:
  • devId – Identity of the device.
  • reqOpnMode – Specifies the mode in which the device is to be configured. This can be SFH_7773_OPN_MODE_TRIGGERED or SFH_7773_OPN_MODE_FREE_RUNNING. For other values, default configuration SFH_7773_PS_OPN_MODE_STAND_BY_1_ENC is used.
  • opnTime_p – Points to location where the transition time is returned. Time is in milliseconds.
Returns:

PLTFRM_STS_SUCCESS is returned when there is no change in mode. If there is a change in mode and it is initiated correctly, PLTFRM_STS_OPN_IN_PROGRESS is returned. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

SFH_7773_mode_t SFH_7773_getOpnMode(UINT8_t devId)

Get the operation mode of the sensor.

Parameters:
  • devId – Identity of the device.
Returns:

Operation mode is returned. If device context is not found, SFH_7773_OPN_MODE_UNKNOWN is returned.

PLTFRM_sts_t SFH_7773_getALSOutput(UINT8_t devId, SINT32_t *luxVal_p)

This function interfaces with the sensor and gets the light intensity value.

Parameters:
  • devId – Identity of the device.
  • luxVal_p – Points to location where light intensity value is returned.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Possible errors are PLTFRM_STS_INV_DEV_ID, PLTFRM_STS_INV_PARAM and PLTFRM_STS_I2C_BUS_WR_ERROR.

8.2.1.4.2. Macros

/*
 * Looks like there can be only one SFH 7773 on a bus at address
 * 000b.
 */
#define SFH_7773_I2C_ADDR_PREFIX   0x38   // 0 0111 000

#define SFH_7773_PART_NUMBER_ID  0x9

#define SFH_7773_SENSOR_OUTPUT_VALUE_SZ   4

/*
 * SFH 7773 register list
 */

#define SFH_773_PART_NR_AND_REV_REG_ADDR         0x8a    // R/O
#define SFH_773_MFR_ID_REG_ADDR                  0x8b    // R/O
#define SFH_773_INTERRUPT_REG_ADDR               0x92    // R/W
#define SFH_7773_SW_RST_CTRL_REG_ADDR            0x80    // R/W

#define SFH_7773_ALS_CTRL_REG_ADDR               0x80    // R/W
#define SFH_7773_ALS_MCU_TRIGGER_REG_ADDR        0x84    // R/W
#define SFH_7773_ALS_TIME_INTERVAL_REG_ADDR      0x86    // R/W
#define SFH_7773_ALS_DATA_LSB_REG_ADDR           0x8c    // R/O
#define SFH_7773_ALS_DATA_MSB_REG_ADDR           0x8d    // R/O
#define SFH_773_ALS_DATA_STATUS_REG_ADDR         0x8e    // R/O
#define SFH_773_ALS_UPPER_THLD_LSB_REG_ADDR      0x96    // R/W
#define SFH_773_ALS_UPPER_THLD_MSB_REG_ADDR      0x97    // R/W
#define SFH_773_ALS_LOWER_THLD_LSB_REG_ADDR      0x98    // R/W
#define SFH_773_ALS_LOWER_THLD_MSB_REG_ADDR      0x99    // R/W


#define SFH_7773_PS_CTRL_REG_ADDR                0x81    // R/W
#define SFH_7773_EMITTER_CURRENT_CTRL_REG_ADDR   0x82    // R/W
#define SFH_7773_PS_MCU_TRIGGER_REG_ADDR         0x84    // R/W
#define SFH_7773_PS_TIME_INTERVAL_REG_ADDR       0x86    // R/W
#define SFH_7773_PS_DATA_STATUS_REG_ADDR         0x8e    // R/O
#define SFH_7773_PS_MEAS_DATA_REG_ADDR           0x8f    // R/O
#define SFH_7773_PS_THLD_LEVEL_REG_ADDR          0x93    // R/W

#define SFH_7773_ALS_OPN_MODE_TRANSITION_TIME    10   // In milliseconds

#define SFH_7773_ALS_DFLT_INTEGRATION_TIME   100     // In milliseconds

#define SFH_7773_ALS_MIN_INTEGRATION_TIME    10     // In milliseconds
#define SFH_7773_ALS_MAX_INTEGRATION_TIME    1000   // In milliseconds

#define SFH_7773_PS_MIN_INTEGRATION_TIME    100     // In microseconds
#define SFH_7773_PS_MAX_INTEGRATION_TIME    2500    // In microseconds

#define SFH_7773_STANDBY_CURRENT_TYPICAL   2   // In micro amps
#define SFH_7773_STANDBY_CURRENT_MAX       2   // In micro amps

// Register 0x80 (RST_AND_ALS_CTRL_REG_ADDR)
#define SFH_7773_ALS_MODE_BIT_MSK   0x3
#define SFH_7773_SW_RESET_TRIGGER_BIT_MSK  0x4

// Register 0x84
#define SFH_7773_ALS_MEAS_TRIGGER_BIT_MSK  0x2
#define SFH_7773_PS_MEAS_TRIGGER_BIT_MSK   0x1

// Register 0x8a
#define SFH_7773_PART_NR_SHIFT  4
#define SFH_7773_PART_NR_SHIFT_BIT_MSK  0xf

#define SFH_7773_ALS_OPN_MODE_STAND_BY_0_ENC     0x0
#define SFH_7773_ALS_OPN_MODE_STAND_BY_1_ENC     0x1
#define SFH_7773_ALS_OPN_MODE_TRIGGERED_ENC      0x2
#define SFH_7773_ALS_OPN_MODE_FREE_RUNNING_ENC   0x3

// Register 0x81 (PS_CTRL_REG_ADDR)
#define SFH_7773_PS_OPN_MODE_STAND_BY_0_ENC     0x0
#define SFH_7773_PS_OPN_MODE_STAND_BY_1_ENC     0x1
#define SFH_7773_PS_OPN_MODE_TRIGGERED_ENC      0x2
#define SFH_7773_PS_OPN_MODE_FREE_RUNNING_ENC   0x3

8.2.1.4.3. Type Definitions

typedef enum
{
   SFH_7773_OPN_MODE_UNKNOWN,       // Implementation specific

   /*
    * IDD is below 2mA and the device is inactive. Other units may use
    * the I2C bus without any restrictions; I/O pins and INT are in Z state.
    * There is no sink current through the LED
    */
   SFH_7773_OPN_MODE_OFF,

   /*
    * This is the initial mode after power-up. IDD is below 5mA. No
    * measurement is performed. Device can be activated by I2C bus
    * communication. Data registers can be read and written. The data
    * will be stored in the registers when the device goes from TRIGGERED
    * or FREE-RUNNING to STAND-BY.
    */
   SFH_7773_OPN_MODE_STAND_BY,

   /*
    * Every measurement is separately initiated by MCU. This mode
    * can be used for ambient light sensor and proximity sensor.
    * Measurement data are available in the registers after a
    * defined delay time.
    */
   SFH_7773_OPN_MODE_TRIGGERED,

   /*
    * Measurements are triggered internally by SFH7773. This mode can
    * also be used for ambient light sensor and proximity sensor. The
    * measurement repetition rate and current through the LED is defined
    * by MCU. Measurement results can be read from the data register, the
    * status from the interrupt register.
    */
   SFH_7773_OPN_MODE_FREE_RUNNING
} SFH_7773_mode_t;


typedef struct
{
   UINT8_t devId;
   SFH_7773_mode_t opnMode;
} SFH_7773_cntxt_s;