I'm trying to use a L3GD20H gyro module with I2C. I'm using this code for trying I2C:

HAL_I2C_Master_Transmit(&hi2c1, 0xD5,0x28, 1, 1000);
HAL_I2C_Master_Receive(&hi2c1,0xD5,(uint8_t *)buffer,6,1000);

This is the logic analyzer result. It's not sending a register adress. Sometimes the SDA pin is always low. I don't understand what the problem is.

enter image description here

edit: I change the code.

 uint8_t dataBuffer[10] = {0x28};
  HAL_I2C_Master_Transmit(&hi2c1, 0xD5,dataBuffer, 1, 1000);
  HAL_I2C_Master_Receive(&hi2c1,0xD5,(uint8_t *)buffer,6,1000);

now i can send register addres but it gives consant value. enter image description here

  • 1
    \$\begingroup\$ Here you find additional info how to use the API functions. \$\endgroup\$
    – Velvet
    Aug 11, 2022 at 9:22

1 Answer 1


It does exactly what you tell it to do.

The transmit function takes in a pointer from where to send data, just like the receive function takes in a pointer where to receive data.

You tell the API to send one byte from memory address 0x28 which happens to be 0x00. That is likely something you don't want to do.

You might want to send one byte from some memory address that does contain 0x28, such as from a buffer or a variable.

  • \$\begingroup\$ Is expect that the OP's compiler is giving a warning on that line which they're just ignoring ... \$\endgroup\$
    – brhans
    Aug 11, 2022 at 9:59
  • \$\begingroup\$ @justme ı changed the code.I can send addres but it take constant values \$\endgroup\$
    – ybi
    Aug 11, 2022 at 10:56
  • 1
    \$\begingroup\$ Well, the original issue about how to use STM32 HAL properly is solved. That's a different and new problem then, that may be better to ask in a new question. It may require in-depth analysis of the gyro datasheet about what kind of transactions are supported and how to perform these transactions. \$\endgroup\$
    – Justme
    Aug 11, 2022 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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