Help with I2C + VEML6030

Hello,

I’m interconnecting the microcontroller STM32 and the VEML6030 I have problems with the I2C communication because I’m writing the configuration into the register 0, and when I read it, the sensor allways return 0. Why?

Inside the main, I have the following code:

  if (HAL_I2C_IsDeviceReady(&hi2c2,AddrVEML6030, 2, 20)== HAL_OK)            // Check if the devide is ready
  	  {
	  sprintf(Cadena, "\n\rVEML6030 Communication READY!\n\r");
	  HAL_UART_Transmit(&huart2, Cadena, (uint16_t)strlen(Cadena), 500 );
 	}

  while(1)

  {
	  HAL_Delay(100);
	  VEML6030_WrWord_index8b(AddrVEML6030, 0x00, 0b0001100011000000);					//Register 0 config

	  HAL_Delay(100);
	  VEML6030_RdWord_index8b(AddrVEML6030, 0x00, &wordData);

	  sprintf(buff, "Register 0: 0x%X\n\r", wordData);
	  HAL_UART_Transmit(&huart2, buff, (uint16_t)strlen(buff), 500 );
  }

The function HAL_I2C_IsDeviceReady always return HAL_OK and then the divice is ready. Also I check the SDA and SCL and they have a good shape.

/********************* WRITE WORD ****************/
int8_t VEML6030_WrWord_index8b(uint16_t dev, uint8_t index, uint16_t data)
{
	uint8_t i2cDataTX[3];								// 1 Byte for command code + 2 bytes for data
	uint8_t Status;

	i2cDataTX[0] = index;								// Command code
	i2cDataTX[1] = (uint8_t) data & 0x00FF;				// Data Byte Low
	i2cDataTX[2] = (uint8_t) (data >> 8) & 0x00FF;		// Data Byte High

	Status = HAL_I2C_Master_Transmit(&hi2c2 , dev ,i2cDataTX , 3, 10);		// Write Word

	return Status;
}


/********************* READ WORD ****************/
int8_t VEML6030_RdWord_index8b(uint16_t dev, uint8_t index, uint16_t *data)
{

	uint8_t i2cDataTX[1];
	uint8_t i2cDataRX[2];
	int8_t status;

	i2cDataTX[0] = index;													// Command code ( 1 Byte)

	status = HAL_I2C_Master_Transmit(&hi2c2 , dev ,i2cDataTX , 1, 10);		// Send command code (1 Byte)
	status = HAL_I2C_Master_Receive(&hi2c2, dev , &i2cDataRX[0] , 2, 10);	// Read 2 Bytes

	*data = (uint16_t) (i2cDataRX[1] <<8 | i2cDataRX[0]);					// Convert string to Word

	return status;
}

Maybe your issue is not the I2C code but the fact that some registers (like 00) are WRITE only and others are READ only (page 7 of the datasheet).

Hi Paul,

yes, I thought the same as you, but after analyze this example is obvious that this register can be readable:

https://github.com/sparkfun/SparkFun_Am … Basics.ino

  Serial.println("Reading settings..."); 
  Serial.print("Gain: ");
  float gainVal = light.readGain();
  Serial.print(gainVal, 3); 
  Serial.print(" Integration Time: ");
  int timeVal = light.readIntegTime();
  Serial.println(timeVal);

Thanks for your help!

hmmm… interesting datasheet :-).

What happens if you just try to read the other registers?

What happens if you try to write and then read another register ?

I assume the I2C pull-up resistors are still in place?

Hello Paul,

the behaviour is always the same :? Any data from the sensor is always zero.

I tried to write other registers and the result is the same, and yes, I placed the pull up resistors.

I have an other sensor exactly equal that makes the same… I’m completely lost. Any suggestion/idea are welcome!

Thanks!

Does reducing the I2C speed has an impact?

does the returned status of HAL_I2C_Master_Transmit() or HAL_I2C_Master_Receive() bring some info ?

is a printf of the content of i2cDataTX buffer in writing what you would expect ?

Hi Paul,

  • Right now I’m working at 100KHz after reduce the initial speed of 400KHz.

  • HAL_I2C_Master_Transmit() and HAL_I2C_Master_Receive() always return HAL_OK (ACK from Sensor).

  • The content of the i2cDataTX buffer is correct, I checked it with my oscilloscope.

I will definitely have to buy an arduino because all the libraries are designed for arduino… :lol:

Thanks for your ideas!