2.7 I2C Color Sensor VEML3328 Driver

2.7.1 Introduction

The MPLAB® Code Configurator Melody I2C Color Sensor VEML3328 Library allows quick and easy configuration and code generation to enable microcontrollers to interface with the off-chip VEML3328 Color Sensor using the I2C protocol.

2.7.2 How to Host Multiple Clients on a Single I2C Bus

  1. Launch MCC and select MCC Melody
  2. Load at least two I2C-dependent modules (in the case illustrated by Figure 2-11), without assigning any I2C instance in the I2C Host Dependency selector.
    Figure 2-11. I2C Temp Sensor MCP98xx and I2C Color Sensor VEML3328 Default Setup
  3. Assign an I2C instance to only one of the loaded I2C-dependent modules (refer to Figure 2-12).
    Figure 2-12. Assigning an I2C instance on I2C Temp Sensor MCP98xx
  4. If there are more than one I2C instance on the device, keep the I2C Host Dependency selector on the second I2C-dependent module (I2C Color Sensor VEML3328) on “None”.
  5. Check the notifications on the second I2C-dependent module for instructions on how to assign the same I2C instance in the generated C-code. Ignore this warning when generating the code.
    Figure 2-13. Notifications on I2C Color Sensor VEML3328
  6. Generate the code.
  7. Modify the generated C-code by assigning the generated I2C driver APIs.
    Figure 2-14. Generated Code for I2C Color Sensor VEML3328

2.7.3 I2C Color Sensor VEML3328 Driver Documentation

2.7.3.1 Module Documentation

2.7.3.1.1 VEML3328

This file contains API declarations for the I2C Color Sensor VEML3328 driver.

Module description

This file contains API declarations for the I2C Color Sensor VEML3328 driver.

Version: I2C Color Sensor VEML3328 Driver Version 1.0.0
Data structures
  • struct VEML3328_INITIAL_CONFIG

    An instance of VEML3328_DEVICE_INIT_t for the VEML3328 Color Sensor driver.

  • struct VEML3328_DEVICE_CONTEXT

    Structure containing the VEML3328 Color Sensor driver context used in the API routines.

  • struct VEML3328_DEVICE_INIT

    Structure containing the VEML3328 Color Sensor Command register settings for the driver initialization.

Enumerations
Functions
Definition Documentation
VEML3328_CLIENT_ADDRESS

#define VEML3328_CLIENT_ADDRESS (0x10U)

VEML3328 Color Sensor Client address for I2C operations.

Function Documentation
VEML3328_ActiveForceModeSet()

VEML3328_STATUS_t VEML3328_ActiveForceModeSet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr)

Sets the Measurement mode to Active Force (Single).

Precondition:

Initialize the VEML3328 Color Sensor.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

Returns:

VEML3328 status code.

VEML3328_AutoModeSet()

VEML3328_STATUS_t VEML3328_AutoModeSet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr)

Sets the Measurement mode to Auto (Continuous).

Precondition:

Initialize the VEML3328 Color Sensor.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

Returns:

VEML3328 status code.

VEML3328_BlueChannelDataGet()

VEML3328_STATUS_t VEML3328_BlueChannelDataGet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr, uint16_t * readBuffer)

Reads the Blue channel data of the VEML3328 Color Sensor.

Precondition:

Initialize the VEML3328 Color Sensor. If the driver uses the Active Force (Single) Measurement mode, execute the VEML3328_SingleMeasurementTrigger routine.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

uint16_t*

readBuffer - Pointer to a user-defined variable that will contain the channel data.

Returns:

VEML3328 status code.

VEML3328_ClearChannelDataGet()

VEML3328_STATUS_t VEML3328_ClearChannelDataGet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr, uint16_t * readBuffer)

Reads the Clear channel data of the VEML3328 sensor.

Precondition:

Initialize the VEML3328 Color Sensor. If the driver uses the Active Force (Single) Measurement mode, execute the VEML3328_SingleMeasurementTrigger routine.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

uint16_t*

readBuffer - Pointer to a user-defined variable that will contain the channel data.

Returns:

VEML3328 status code.

VEML3328_DeviceIdGet()

VEML3328_STATUS_t VEML3328_DeviceIdGet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr, uint16_t * readBuffer)

Reads the device ID of the VEML3328 Color Sensor.

Precondition:

Initialize the I2C Host driver.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

uint16_t*

readBuffer - Pointer to a user-defined variable that will contain the device ID.

Returns:

VEML3328 status code.

VEML3328_GreenChannelDataGet()

VEML3328_STATUS_t VEML3328_GreenChannelDataGet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr, uint16_t * readBuffer)

Reads the Green channel data of the VEML3328 Color Sensor.

Precondition:

Initialize the VEML3328 Color Sensor. If the driver uses the Active Force (Single) Measurement mode, execute the VEML3328_SingleMeasurementTrigger routine.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

uint16_t*

readBuffer - Pointer to a user-defined variable that will contain the channel data.

Returns:

VEML3328 status code.

VEML3328_Initialize()

VEML3328_STATUS_t VEML3328_Initialize (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr, VEML3328_DEVICE_INIT_t deviceInit)

Initializes the VEML3328 Color Sensor.

Global API Declarations

Precondition:

Initialize the I2C Host driver.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

VEML3328_DEVICE_INIT_t

deviceInit - An instance of VEML3328_DEVICE_INIT_t.

Returns:

VEML3328 status code.

VEML3328_IrChannelDataGet()

VEML3328_STATUS_t VEML3328_IrChannelDataGet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr, uint16_t * readBuffer)

Reads the Infrared (IR) channel data of the VEML3328 Color Sensor.

Precondition:

Initialize the VEML3328 Color Sensor. If the driver uses the Active Force (Single) Measurement mode, execute the VEML3328_SingleMeasurementTrigger routine.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

uint16_t*

readBuffer - Pointer to a user-defined variable that will contain the channel data.

Returns:

VEML3328 status code.

VEML3328_RedChannelDataGet()

VEML3328_STATUS_t VEML3328_RedChannelDataGet (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr, uint16_t * readBuffer)

Reads the Red channel data of the VEML3328 Color Sensor.

Precondition:

Initialize the VEML3328 Color Sensor. If the driver uses the Active Force (Single) Measurement mode, execute the VEML3328_SingleMeasurementTrigger routine.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

uint16_t*

readBuffer - Pointer to a user-defined variable that will contain the channel data.

Returns:

VEML3328 status code.

VEML3328_SingleMeasurementTrigger()

VEML3328_STATUS_t VEML3328_SingleMeasurementTrigger (VEML3328_DEVICE_CONTEXT_PTR deviceContextPtr)

Triggers single cycle measurement on the VEML3328 sensor.

Precondition:

Initialize the VEML3328 Color Sensor with Active Force (Single) Measurement mode.

Parameters:
VEML3328_DEVICE_CONTEXT_PTR

deviceContextPtr - Pointer to an instance of VEML3328_DEVICE_CONTEXT.

Returns:

VEML3328 status code.

Enumeration Type Documentation
VEML3328_AF

enum VEML3328_AF

Enumeration of the VEML3328 Color Sensor Measurement mode options.

AUTO

Sets the sensor Measurement mode to Auto.

ACTIVE_FORCE

Sets the sensor Measurement mode to Active Force.

VEML3328_DG

enum VEML3328_DG

Enumeration of the VEML3328 Color Sensor Differential Gain values.

DG_X1

Sets the sensor Differential Gain to x1.

DG_X2

Sets the sensor Differential Gain to x2.

DG_X4

Sets the sensor Differential Gain to x4.

VEML3328_GAIN

enum VEML3328_GAIN

Enumeration of the VEML3328 Color Sensor Gain values.

GAIN_X_HALF

Sets the sensor Gain to x0.5.

GAIN_X1

Sets the sensor Gain to x1.

GAIN_X2

Sets the sensor Gain to x2.

GAIN_X4

Sets the sensor Gain to x4.

VEML3328_IT

enum VEML3328_IT

Enumeration of the VEML3328 Color Sensor Integration Time values.

MS_50

Sets the sensor Integration Time to 50 ms.

MS_100

Sets the sensor Integration Time to 100 ms.

MS_200

Sets the sensor Integration Time to 200 ms.

MS_400

Sets the sensor Integration Time to 400 ms.

VEML3328_SD

enum VEML3328_SD

Enumeration of the VEML3328 Color Sensor Power options.

POWER_ON

Sets the sensor Power to Power-on.

SHUTDOWN

Sets the sensor Power to Shutdown x1.

VEML3328_SD_ALS

enum VEML3328_SD_ALS

Enumeration of the VEML3328 Color Sensor Power-on Channel options.

ALL_CHANNELS

Sets the sensor Power-on for all channels.

POWER_ON_G_C_IR

Sets the sensor Power-on for Green, Clear and IR channels only.

VEML3328_SENS

enum VEML3328_SENS

Enumeration of the VEML3328 Color Sensor Sensitivity values.

HIGH_SENSITVITY

Sets the sensor Sensitivity to High.

LOW_SENSITVITY

Sets the sensor Sensitivity to Low (1/3).

VEML3328_STATUS

enum VEML3328_STATUS

Enumeration of the VEML3328 Color Sensor driver status codes.

VEML3328_NO_ERROR
VEML3328_ERROR
VEML3328_INVALID_PARAMETER
VEML3328_NULL_ERROR
VEML3328_COM_ERROR

2.7.3.1.2 VEML3328_I2C

This file contains constants and API declarations for the VEML3328 Color Sensor interface.

Module description

This file contains constants and API declarations for the VEML3328 Color Sensor interface.

To ensure that the C driver runs properly, do not modify the I2C API prototypes. Refer to veml3328_i2c.c to configure the I2C interface implementation.

Version: I2C Color Sensor VEML3328 Driver Version 1.0.0
Data structures
  • struct VEML3328_I2C_Host

    Structure that creates an instance of the I2C Host driver interface for the VEML3328 Color Sensor.

Functions
  • uint8_t VEML3328_WordSend (uint16_t writeData)

    Sends a 16-bit word to the VEML3328 Color Sensor Command register.

  • uint8_t VEML3328_WordReceive (uint8_t command, uint16_t *readData)

    Sends an 8-bit command code and receives a 16-bit word from the VEML3328 Color Sensor Data registers.

Function Documentation
VEML3328_WordReceive()

uint8_t VEML3328_WordReceive (uint8_t command, uint16_t * readData)

Sends an 8-bit command code and receives a 16-bit word from the VEML3328 Color Sensor Data registers.

Precondition:

Initialize the I2C Host and the VEML3328 Color Sensor.

Parameters:
uint8_t

command - Command code that determines which Data register to read.

uint16_t

*readData - Pointer to a data buffer.

Returns:

VEML3328 Color Sensor I2C status code.

VEML3328_WordSend()

uint8_t VEML3328_WordSend (uint16_t writeData)

Sends a 16-bit word to the VEML3328 Color Sensor Command register.

Precondition:

Initialize the I2C Host and the VEML3328 Color Sensor.

Parameters:
uint16_t

writeData - Command register settings.

Returns:

VEML3328 Color Sensor I2C status code.

2.7.3.2 Class Documentation

2.7.3.2.1 VEML3328_DEVICE_CONTEXT Struct Reference

Structure containing the VEML3328 Color Sensor driver context used in the API routines.

Member Data Documentation

The documentation for this struct was generated from the following file:

source/

veml3328_types.h

commandCodeConfig

uint16_t VEML3328_DEVICE_CONTEXT::commandCodeConfig

diffGain

uint8_t VEML3328_DEVICE_CONTEXT::diffGain

gain

uint8_t VEML3328_DEVICE_CONTEXT::gain

integrationTime

uint8_t VEML3328_DEVICE_CONTEXT::integrationTime

measurementMode

uint8_t VEML3328_DEVICE_CONTEXT::measurementMode

powerOn

uint8_t VEML3328_DEVICE_CONTEXT::powerOn

sd0Val

uint8_t VEML3328_DEVICE_CONTEXT::sd0Val

sd1Val

uint8_t VEML3328_DEVICE_CONTEXT::sd1Val

sensivity

uint8_t VEML3328_DEVICE_CONTEXT::sensivity

trigger

uint8_t VEML3328_DEVICE_CONTEXT::trigger

2.7.3.2.2 VEML3328_DEVICE_INIT Struct Reference

Structure containing the VEML3328 Color Sensor Command register settings for the driver initialization.

Member Data Documentation

The documentation for this struct was generated from the following file:

source/

veml3328_types.h

diffGain

uint8_t VEML3328_DEVICE_INIT::diffGain

gain

uint8_t VEML3328_DEVICE_INIT::gain

integrationTime

uint8_t VEML3328_DEVICE_INIT::integrationTime

measurementMode

uint8_t VEML3328_DEVICE_INIT::measurementMode

powerOn

uint8_t VEML3328_DEVICE_INIT::powerOn

sd0Val

uint8_t VEML3328_DEVICE_INIT::sd0Val

sd1Val

uint8_t VEML3328_DEVICE_INIT::sd1Val

sensivity

uint8_t VEML3328_DEVICE_INIT::sensivity

2.7.3.2.3 VEML3328_I2C_Host Struct Reference

Structure that creates an instance of the I2C Host driver interface for the VEML3328 Color Sensor.

Detailed Description

Structure that creates an instance of the I2C Host driver interface for the VEML3328 Color Sensor.

The documentation for this struct was generated from the following file:

source/src/

veml3328_i2c.c

2.7.3.2.4 VEML3328_INITIAL_CONFIG Struct Reference

An instance of VEML3328_DEVICE_INIT_t for the VEML3328 Color Sensor driver.

Detailed Description

An instance of VEML3328_DEVICE_INIT_t for the VEML3328 Color Sensor driver.

Include Headers

#include <veml3328.h>

The documentation for this struct was generated from the following file:

source/

veml3328.h

2.7.3.3 File Documentation

2.7.3.3.1 source/src/veml3328.c File Reference

Contains API definitions for the I2C Color Sensor VEML3328 driver.

#include "../veml3328.h"
#include "../veml3328_config.h"
#include "../veml3328_i2c.h"
Functions
Detailed Description

Contains API definitions for the I2C Color Sensor VEML3328 driver.

I2C Color Sensor VEML3328 generated driver source file.

Version: I2C Color Sensor VEML3328 Driver Version 1.0.0

2.7.3.3.2 source/src/veml3328_i2c.c File Reference

This file contains API definitions for the I2C Color Sensor VEML3328 interface. Users can modify this file to support other I2C drivers.

#include "../../i2c_host/twi0.h"
#include "../veml3328_i2c.h"
#include "../veml3328_config.h"
Functions
  • uint8_t VEML3328_WordSend (uint16_t writeData)

    Sends a 16-bit word to the VEML3328 Color Sensor Command register.

  • uint8_t VEML3328_WordReceive (uint8_t command, uint16_t *readData)

    Sends an 8-bit command code and receives a 16-bit word from the VEML3328 Color Sensor Data registers.

Detailed Description

This file contains API definitions for the I2C Color Sensor VEML3328 interface. Users can modify this file to support other I2C drivers.

I2C Color Sensor VEML3328 generated driver I2C interface source file.

Version: I2C Color Sensor VEML3328 Driver Version 1.0.0
Macro Definition Documentation
ADDRESS_LENGTH

#define ADDRESS_LENGTH (1U)

READ_WORD_SIZE

#define READ_WORD_SIZE (2U)

SEND_WORD_SIZE

#define SEND_WORD_SIZE (3U)

Variable Documentation
VEML3328_I2C_Host

const i2c_host_interface_t VEML3328_I2C_Host

Initial value:

= {
    .Write = TWI0_Write,
    .WriteRead = TWI0_WriteRead,
    .IsBusy = TWI0_IsBusy,
    .Tasks = TWI0_Tasks,
}

2.7.3.3.3 source/veml3328.h File Reference

#include <stdint.h>
#include "veml3328_i2c.h"
#include "veml3328_types.h"
Functions
Detailed Description

I2C Color Sensor VEML3328 generated driver header file.

2.7.3.3.4 source/veml3328_config.h File Reference

This file contains device-specific constants for the I2C Color Sensor VEML3328 driver.

Command Register Macros

Bit position and bit masks for the VEML3328 Color Sensor Command register settings.

Detailed Description

This file contains device-specific constants for the I2C Color Sensor VEML3328 driver.

I2C Color Sensor VEML3328 generated driver configuration header file.

Version: I2C Color Sensor VEML3328 Driver Version 1.0.0
Macro Definition Documentation
CMD_READ_BLUE_CHANNEL

#define CMD_READ_BLUE_CHANNEL (0x07U)

CMD_READ_CLEAR_CHANNEL

#define CMD_READ_CLEAR_CHANNEL (0x04U)

CMD_READ_DEVICE_ID

#define CMD_READ_DEVICE_ID (0x0CU)

CMD_READ_GREEN_CHANNEL

#define CMD_READ_GREEN_CHANNEL (0x06U)

CMD_READ_IR_CHANNEL

#define CMD_READ_IR_CHANNEL (0x08U)

CMD_READ_RED_CHANNEL

#define CMD_READ_RED_CHANNEL (0x05U)

CMD_WRITE_REGISTER

#define CMD_WRITE_REGISTER (0x00U)

VEML3328_AF_MASK

#define VEML3328_AF_MASK (0x08U)

Measurement mode bit mask.

VEML3328_AF_POSITION

#define VEML3328_AF_POSITION (3U)

Measurement mode bit position.

VEML3328_DG_POSITION

#define VEML3328_DG_POSITION (13U)

Differential Gain bit position.

VEML3328_GAIN_POSITION

#define VEML3328_GAIN_POSITION (11U)

Gain bit position.

VEML3328_IT_POSITION

#define VEML3328_IT_POSITION (5U)

Integration Time bit position.

VEML3328_SD0_MASK

#define VEML3328_SD0_MASK (0x01U)

Shutdown bit 0 mask.

VEML3328_SD0_POSITION

#define VEML3328_SD0_POSITION (0U)

Shutdown bit 0 position.

VEML3328_SD1_MASK

#define VEML3328_SD1_MASK (0x8000UL)

Shutdown bit 1 mask.

VEML3328_SD1_POSITION

#define VEML3328_SD1_POSITION (15U)

Shutdown bit 1 position.

VEML3328_SD_ALS_POSITION

#define VEML3328_SD_ALS_POSITION (14U)

Channels Power-on bit position.

VEML3328_SENS_POSITION

#define VEML3328_SENS_POSITION (6U)

Sensitivity bit position.

VEML3328_TRIG_POSITION

#define VEML3328_TRIG_POSITION (2U)

Single Measurement Trigger bit position.

2.7.3.3.5 source/veml3328_i2c.h File Reference

#include <stdint.h>
#include <stddef.h>
Functions
  • uint8_t VEML3328_WordSend (uint16_t writeData)

    Sends a 16-bit word to the VEML3328 Color Sensor Command register.

  • uint8_t VEML3328_WordReceive (uint8_t command, uint16_t *readData)

    Sends an 8-bit command code and receives a 16-bit word from the VEML3328 Color Sensor Data registers.

Detailed Description

I2C Color Sensor VEML3328 generated driver I2C interface header file.

Macro Definition Documentation
VEML3328_I2C_ERROR

#define VEML3328_I2C_ERROR (1U)

VEML3328_I2C_NO_ERROR

#define VEML3328_I2C_NO_ERROR (0U)

2.7.3.3.6 source/veml3328_types.h File Reference

This file contains type definitions for the I2C Color Sensor VEML3328 driver.

Data structures
  • struct VEML3328_DEVICE_CONTEXT

    Structure containing the VEML3328 Color Sensor driver context used in the API routines.

  • struct VEML3328_DEVICE_INIT

    Structure containing the VEML3328 Color Sensor Command register settings for the driver initialization.

Typedefs
Enumerations
Detailed Description

This file contains type definitions for the I2C Color Sensor VEML3328 driver.

I2C Color Sensor VEML3328 generated driver data types header file.

Version: I2C Color Sensor VEML3328 Driver Version 1.0.0
Typedef Documentation