0
\$\begingroup\$

I am attempting to implement I2C interface on the STM32F7-Discovery Board using the a VEML 6070 UV light sensor (https://www.vishay.com/docs/84277/veml6070.pdf).

The 7-bit slave address for the device is 0x38. The addresses for data access are 0x71(LSB) and 0x73(MSB)

I am not able to write or read any data from the master. When I check the HAL_Status it returns HAL_Timeout.

Some of my code is shown below:

EDIT:

void VEML6070_Init(void){

char data[1];

HAL_I2C_Master_Receive(&hi2c1, 0x18<<1, data, 1, 150); 

data[0] = 0x06;

HAL_I2C_Master_Transmit(&hi2c1, 0x38<<1, data, 1, 150);

}

int main(void)  {  
 unsigned int rawUV;
 char lcd_buf[5]
 uint8_t address[1];
 uint8_t MSBdata[1];
 uint8_t LSBdata[1];
 SystemClock_Config();
 MX_I2C1_Init();
 MX_GPIO_Init();

 VEML6070_Init();

 address[0] = 0x02;

 HAL_I2C_Mem_Write(&hi2c1, 0x38<<1, 0x70, I2C_MEMADD_SIZE_8BIT, address, 1, 150)

 HAL_I2C_Mem_Read(&hi2c1, 0x38<<1, 0x73, I2C_MEMADD_SIZE_8BIT, MSBdata, 1, 150)

 HAL_I2C_Mem_Read(&hi2c1, 0x38<<1, 0x71, I2C_MEMADD_SIZE_8BIT, LSBdata, 1, 150)

 rawUV = MSBdata[0]<<8 | LSBdata[0];
 sprintf(lcd_buf, "%d ", rawUV);
 //GLCD_DrawString (0, 7*24, lcd_buf);
}

Does anybody have experience of implementing I2C with the STM32F7 boards, and if so are you able to shed any light on why I may be getting 'HAL_TIMEOUT'? Is it a case of me using the wrong register addresses, or is it something more complex?

Thanks.

Edit:

I have now altered the code to use the correct protocol, but I am still finding a 'HAL_TIMEOUT'.

HAL_I2C_Master_Transmit(&hi2c1, 0x38<<1, address, 1, 150);

HAL_I2C_Master_Receive(&hi2c1, 0x39<<1, MSBdata, 1, 150);

HAL_I2C_Master_Receive(&hi2c1, 0x38<<1, LSBdata, 1, 150);

Any other suggestions?

\$\endgroup\$
  • 1
    \$\begingroup\$ You're probably at a point where it would be good to get a scope or logic analyzer on the signals and see what is happening, especially if you have a known working configuration (some off-the-shelf Arduino example sketch?) to compare to. Even without a reference some problems like I/O pins not configured to the point where they toggle at all will be obvious, and others can be figured out with the help of a protocol decoder built into modern instruments, or carefully studying and manually interpreting the plot. What's your pull-up resistor situation? \$\endgroup\$ – Chris Stratton Apr 10 at 19:03
0
\$\begingroup\$

The protocol is wrong. It is not register based to a single slave address so you can't use the Mem_Write and Mem_Read functions. What you have is there are three different slave addresses for single byte for command, MSB and LSB data.

\$\endgroup\$
  • \$\begingroup\$ Hi, thank for your response. Would the 'HAL_I2C_Master_Transmit' and 'HAL_I2C_Master_Receive' be the correct protocols? \$\endgroup\$ – McDingle94 Apr 9 at 14:25
  • \$\begingroup\$ Yes, that would be correct. \$\endgroup\$ – Justme Apr 9 at 14:26
  • \$\begingroup\$ Thank you for your help, unfortunately I am still experiencing the problem. \$\endgroup\$ – McDingle94 Apr 9 at 15:06
  • \$\begingroup\$ Sorry to ask again, but I still haven't solved the issue. Do the protocols in my edit look correct now? \$\endgroup\$ – McDingle94 Apr 10 at 11:26
  • \$\begingroup\$ Maybe, but you don't say which of those operations times out, and you don't show if you have initialized the chip with the sequence found in datasheets and application notes before it responds correctly. \$\endgroup\$ – Justme Apr 10 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.