# Having trouble reading from registers with STM32F4 HAL_I2C libraries

I'm new to STM32 programming and am programming on a STM32F429 Microcontroller. My main goal is to integrate a Sparkfun UV sensor VEML6075 into the microcontroller as an external payload.

TLDR: Tried to send commands into the i2c line to initialise the sensor and take readings from its registers, code below utilising HAL_I2C library methods does not work at all.

To begin doing so, I researched on how to program and take readings directly from the UV sensor itself in Arduino without using the Sparkfun library provided. This was done easily enough, simply using the Wire library to write and read from the I2C line.

Now the hard part: translating this over to STM32, which was where I got stuck. The datasheet gets a little confusing as it only mentions commands and not register values, so I'm confused as to how the process goes.

From reading through the datasheet of the VEML6075 sensor, my understanding of how to initialise and take readings from this sensor is as such:

1) Set the base register, UV_CONF to set the desired functioning parameters as seen from the table:

Where I perceive that I need to send a command of 0x10 to the CONF register 0x00 which initialises the sensor with timing 100ms.

2) Send commands to the registers to read from the values stored on the registers:

To which I want to try a simple reading of UVA, so I should write(0x07) and read from the register 0x07??

The codes I came up with subsequently is as follows:

The slave device address is 0x10.

Init function:

    void VEML6075_init(uint8_t register_pointer, uint8_t register_value)
{
HAL_StatusTypeDef status = HAL_OK;

status = HAL_I2C_Mem_Write(&hi2c3, 0x10, (uint16_t)register_pointer, I2C_MEMADD_SIZE_8BIT,  (uint8_t*)(&register_value), 1, 10 );

if(status != HAL_OK){
fprintf(SYSCON, "UV sensor init not successful");
}
}


    uint16_t VEML6075_Fetch_RawUV(uint8_t register_pointer)
{
HAL_StatusTypeDef status = HAL_OK;
uint16_t return_value = 0;

if(status == HAL_OK){
}
return return_value;
}


Overall main calling code:

// VEML6075 init variables
uint8_t register_pointer_init = 0x00;
uint8_t register_init_command = 0x10;