cancel
Showing results for 
Search instead for 
Did you mean: 

How to use VD6283TX driver?

BChav.1
Associate III

Hi ,

Can anyone help to understand how to use the available driver for vd6283TX ambient light sensor as i was able to read the device id and revision id of the device from the driver but the data ready flag is not in a state to read the data,and hence there is no data when i call "VD6283TX_GetValues()".

Any reference document i should refer?

Here is the sequence of API's i am using:

VD6283TX_Object_t LSstruct;

uint32_t data[6];

 LSstruct.handle = &hi2c1;

 uint8_t ret = VD6283TX_Init(&LSstruct);

 VD6283TX_Start(&LSstruct,0);

 ret = VD6283TX_GetValues(&LSstruct,data);

TIA,

Bipin Chavan

1 ACCEPTED SOLUTION

Accepted Solutions
John E KVAM
ST Employee

I'm thinking the code should look more like:

static void MX_VD6283A1_ALSValues_Process(void)
{
  uint8_t channel;
  uint32_t current_gain;
  uint32_t current_exposure;
  uint32_t current_imt; /* inter-measurement time */
 
  /* initialize exposure time */
  VD6283A1_LIGHT_SENSOR_SetExposureTime(LIGHT_SENSOR_INSTANCE_0, 100000); /* microseconds */
  VD6283A1_LIGHT_SENSOR_GetExposureTime(LIGHT_SENSOR_INSTANCE_0, &current_exposure);
  printf("Exposure set to %lu us\n", current_exposure);
 
  /* initialize gains */
  for (channel = 0; channel < LIGHT_SENSOR_MAX_CHANNELS; channel++)
  {
    VD6283A1_LIGHT_SENSOR_SetGain(LIGHT_SENSOR_INSTANCE_0, channel, 256);
    VD6283A1_LIGHT_SENSOR_GetGain(LIGHT_SENSOR_INSTANCE_0, channel, &current_gain);
    printf("Channel %d gain set to", channel + 1);
    display_gain(current_gain);
  }
 
  /* initialize inter measurement time */
  VD6283A1_LIGHT_SENSOR_SetInterMeasurementTime(LIGHT_SENSOR_INSTANCE_0, 500000); /* 100 ms */
  VD6283A1_LIGHT_SENSOR_GetInterMeasurementTime(LIGHT_SENSOR_INSTANCE_0, &current_imt);
 
  /* start ALS capture on all channels in continuous mode */
  VD6283A1_LIGHT_SENSOR_Start(LIGHT_SENSOR_INSTANCE_0, LIGHT_SENSOR_MODE_CONTINUOUS);
 
  while (!is_quit_requested)
  {
    /* wait for interrupt event */
    if (ALS_EventDetected != 0U)
    {
      ALS_EventDetected = 0U;
 
      status = VD6283A1_LIGHT_SENSOR_GetValues(LIGHT_SENSOR_INSTANCE_0, AlsResults);
 
      if (status == BSP_ERROR_NONE)
      {
        /* display ALS values */
        for (channel = 0; channel < LIGHT_SENSOR_MAX_CHANNELS; channel++)
        {
          if (is_dark_enabled && (channel == LIGHT_SENSOR_VISIBLE_CHANNEL))
            printf("Channel %u - %8s", channel + 1, "DARK");
          else
            printf("Channel %u - %8s", channel + 1, AlsChannelStr[channel]);
 
          printf("\tValue: %lu\n", AlsResults[channel]);
        }
        printf("\n\n");
      }
    }
 
    handle_cmd(get_key());
  }
 
  VD6283A1_LIGHT_SENSOR_Stop(LIGHT_SENSOR_INSTANCE_0);
  VD6283A1_LIGHT_SENSOR_DeInit(LIGHT_SENSOR_INSTANCE_0);
 
  printf("Quitting the demo...\n");
  while (1);
}

This code is from a slightly different project than yours so the calls are a bit different.

But what I see in mine is different from yours in that I wait for done.

It takes a bit for the sensor to integrate the light and have an answer ready to go.

So you need some 'Are you done yet?' call. (In my code, I'm waiting for an interrupt.)

And I think that is what you are missing.

Sorry for the slow reply, I somehow didn't see you there. I'm blaming the holidays, but I'm sure it's my fault.

  • john

Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'

View solution in original post

1 REPLY 1
John E KVAM
ST Employee

I'm thinking the code should look more like:

static void MX_VD6283A1_ALSValues_Process(void)
{
  uint8_t channel;
  uint32_t current_gain;
  uint32_t current_exposure;
  uint32_t current_imt; /* inter-measurement time */
 
  /* initialize exposure time */
  VD6283A1_LIGHT_SENSOR_SetExposureTime(LIGHT_SENSOR_INSTANCE_0, 100000); /* microseconds */
  VD6283A1_LIGHT_SENSOR_GetExposureTime(LIGHT_SENSOR_INSTANCE_0, &current_exposure);
  printf("Exposure set to %lu us\n", current_exposure);
 
  /* initialize gains */
  for (channel = 0; channel < LIGHT_SENSOR_MAX_CHANNELS; channel++)
  {
    VD6283A1_LIGHT_SENSOR_SetGain(LIGHT_SENSOR_INSTANCE_0, channel, 256);
    VD6283A1_LIGHT_SENSOR_GetGain(LIGHT_SENSOR_INSTANCE_0, channel, &current_gain);
    printf("Channel %d gain set to", channel + 1);
    display_gain(current_gain);
  }
 
  /* initialize inter measurement time */
  VD6283A1_LIGHT_SENSOR_SetInterMeasurementTime(LIGHT_SENSOR_INSTANCE_0, 500000); /* 100 ms */
  VD6283A1_LIGHT_SENSOR_GetInterMeasurementTime(LIGHT_SENSOR_INSTANCE_0, &current_imt);
 
  /* start ALS capture on all channels in continuous mode */
  VD6283A1_LIGHT_SENSOR_Start(LIGHT_SENSOR_INSTANCE_0, LIGHT_SENSOR_MODE_CONTINUOUS);
 
  while (!is_quit_requested)
  {
    /* wait for interrupt event */
    if (ALS_EventDetected != 0U)
    {
      ALS_EventDetected = 0U;
 
      status = VD6283A1_LIGHT_SENSOR_GetValues(LIGHT_SENSOR_INSTANCE_0, AlsResults);
 
      if (status == BSP_ERROR_NONE)
      {
        /* display ALS values */
        for (channel = 0; channel < LIGHT_SENSOR_MAX_CHANNELS; channel++)
        {
          if (is_dark_enabled && (channel == LIGHT_SENSOR_VISIBLE_CHANNEL))
            printf("Channel %u - %8s", channel + 1, "DARK");
          else
            printf("Channel %u - %8s", channel + 1, AlsChannelStr[channel]);
 
          printf("\tValue: %lu\n", AlsResults[channel]);
        }
        printf("\n\n");
      }
    }
 
    handle_cmd(get_key());
  }
 
  VD6283A1_LIGHT_SENSOR_Stop(LIGHT_SENSOR_INSTANCE_0);
  VD6283A1_LIGHT_SENSOR_DeInit(LIGHT_SENSOR_INSTANCE_0);
 
  printf("Quitting the demo...\n");
  while (1);
}

This code is from a slightly different project than yours so the calls are a bit different.

But what I see in mine is different from yours in that I wait for done.

It takes a bit for the sensor to integrate the light and have an answer ready to go.

So you need some 'Are you done yet?' call. (In my code, I'm waiting for an interrupt.)

And I think that is what you are missing.

Sorry for the slow reply, I somehow didn't see you there. I'm blaming the holidays, but I'm sure it's my fault.

  • john

Our community relies on fruitful exchanges and good quality content. You can thank and reward helpful and positive contributions by marking them as 'Accept as Solution'. When marking a solution, make sure it answers your original question or issue that you raised.

ST Employees that act as moderators have the right to accept the solution, judging by their expertise. This helps other community members identify useful discussions and refrain from raising the same question. If you notice any false behavior or abuse of the action, do not hesitate to 'Report Inappropriate Content'