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;
}