2020-07-27 03:26 AM
Can anyone tell me the difference between those functions:
HAL_I2C_Master_Receive
HAL_I2C_Mem_Read
The problem with HAL_I2C_Master_Receive is that it accepts too few parameters (hi2c, DevAddress, pData, Size, Timeout).
I don't know how to tell the memory address of the register in the slave to be read!!
So, in my case I am trying to read data from LSM303DLHC whose DevAddress is 0X33 and the acceleration data are to read from the following addresses: 0X28 -> 2Dh (i.e. 6 bytes).
Thanks in advance for any help or if there is a ready example project.
Solved! Go to Solution.
2020-07-27 05:38 AM
You want HAL_I2C_Mem_Read, which with both send the memory address to the slave and read the data the slave sends. HAL_I2C_Master_Receive only receives data from a slave.
One of several examples available in the Cube repository:
2020-07-27 05:38 AM
You want HAL_I2C_Mem_Read, which with both send the memory address to the slave and read the data the slave sends. HAL_I2C_Master_Receive only receives data from a slave.
One of several examples available in the Cube repository:
2020-08-14 03:08 PM
Thanks for the reply, but I dont know why I cant read the value of a register using the HAL_I2C_Mem_Read function.
So I am using the function HAL_I2C_Master_Transmit to write into a specific register and then I try to read the value using the HAL_I2C_Mem_Read function but unfortunately I get a different value.
Here is a link of my main file:
https://github.com/Ala1980/LSM303DLHC
Any help please?
2020-08-14 04:40 PM
You probably want to use HAL_I2C_Mem_Write to write to a memory address.
2020-08-15 05:29 AM
Oh, I found my mistake.
I was writing to the correct register 0x20, but reading from another register 20.
So writing to 32 decimal and reading from 20 decimal.
2020-08-15 05:37 AM
Oh, I found my mistake.
I was writing to the correct register 0x20, but reading from another register 20.
So writing to 32 decimal and reading from 20 decimal.