VEML6075 reading value with STM32 HAL library



  • Dear all,

    I am using VEML6075 with a NUCLEO board F030R8 using HAL Library to drive the sensor and i am facing a misterious issue:
    I am looping ID, UVB, UVA, UVD, UCOMP1, UCOMP2 data reading ( with a previous initialing configuration register of 01000000 (0x40) ) with a 5 sec pause between each reading sequence.
    The thing is that i read for each register the exact same value (!?) ID = UVB = UVA = UVD = UCOMP1 = UCOMP2.

    I have followed the reading sequence as :
    I2C write: slave address (read/write bit to 0) followed by the command code corresponding to the register code.
    I2C read: slave address (read/write bit to 1) followed by a reading of the 2 bytes of the sensor.

    Here is the oscilloscope screenshots...

    ID register reading (0x0C) whose the value read is 93
    test_6_10s_1milionpoints_10µsparpoint_PS1 --00000.csv--00000.jpg

    UVB register reading (0x09) whose the value read is 93
    test_6_10s_1milionpoints_10µsparpoint_PS1 --00000.csv--00001.jpg

    UVA register reading (0x7) whose the value read is 93
    test_6_10s_1milionpoints_10µsparpoint_PS1 --00000.csv--00002.jpg

    ...and i don't think that the rest is nessary to show..
    So, i guess there is something i do wrongly. Could you help please?
    You ll find below the piece of code i used:

    /* USER CODE BEGIN PFP */
     static const uint8_t VEML6075_ADDR = 0x10 << 1; // Use 8-bit address
     static const uint8_t REG_ID = 0x0C ;
     static const uint8_t REG_UVB = 0x09 ;
     static const uint8_t REG_UVA = 0x07 ;
     static const uint8_t REG_DARK_CURRENT = 0x08 ;
     static const uint8_t REG_VISIBLE_LIGHT = 0x0A ;
     static const uint8_t REG_IR_LIGHT = 0x0B ;
     static const uint8_t REG_UV_CONF = 0x00 ;
     static const uint8_t UV_CONF_DATA_BYTE_HIGH= 0x00 ;
     static const uint8_t UV_CONF_DATA_BYTE_LOW = 0x40 ; 
    
      buf[0] = REG_UV_CONF ; // register adresse for module configuration
       buf[1] = UV_CONF_DATA_BYTE_LOW ; // Data byte low for module configuration
       buf[2] = UV_CONF_DATA_BYTE_HIGH ; // Data byte high for module configuration
       ret = HAL_I2C_Master_Transmit(&hi2c1, VEML6075_ADDR , buf, 3, HAL_MAX_DELAY);  
       if ( ret != HAL_OK ) {
          strcpy((char*)buf, "Error Tx\r\n");
       }
    
    while (1)
      {   
        // Reading of the ID register of the VEML6075 sensor  
        buf[0] = REG_ID ;  
        // Send the Sensor I2C Address follow by the ID command register 
        ret = HAL_I2C_Master_Transmit(&hi2c1, VEML6075_ADDR , buf, 1, HAL_MAX_DELAY);  
        if ( ret != HAL_OK ) {
          strcpy((char*)buf, "Error Tx\r\n");
        } else {  
          // Read 2 bytes from the VEML6075 ID register
          ret = HAL_I2C_Master_Receive(&hi2c1, VEML6075_ADDR, buf, 2, HAL_MAX_DELAY);
          if ( ret != HAL_OK ) {
            strcpy((char*)buf, "Error Rx\r\n");
          } else {
       //Combine the bytes of the ID register to print by UART com
          val = ((int16_t)buf[1] << 8) | (buf[0] );  
          sprintf((char*)buf,
                  "%u ID et ",
                  ((unsigned int)val));     
          }  
       }      
       HAL_UART_Transmit(&huart2, buf, strlen((char*)buf), HAL_MAX_DELAY); 
    
      // Reading of the UVB register of the VEML6075 sensor  
       buf[0] = REG_UVB ;  
       ret = HAL_I2C_Master_Transmit(&hi2c1, VEML6075_ADDR , buf, 1, HAL_MAX_DELAY);  
       if ( ret != HAL_OK ) {
          strcpy((char*)buf, "Error Tx\r\n");
       } else {  
       // Read 2 bytes from the VEML6075 UVB register
          ret = HAL_I2C_Master_Receive(&hi2c1, VEML6075_ADDR, buf, 2, HAL_MAX_DELAY);
          if ( ret != HAL_OK ) {
            strcpy((char*)buf, "Error Rx\r\n");
          } else {
       //Combine the bytes
          val = ((int16_t)buf[1] << 8) | (buf[0] );  
          sprintf((char*)buf,
                  "%u UVB et ",
                  ((unsigned int)val));     
          }  
       }      
       HAL_UART_Transmit(&huart2, buf, strlen((char*)buf), HAL_MAX_DELAY);  
    
       HAL_Delay(2000) ;
    }
    

Log in to reply
 

Suggested Topics

  • 8
  • 90
  • 29
  • 2
  • 1
  • 44

23
Online

11.2k
Users

11.1k
Topics

112.5k
Posts