Reading from Accelerometer via i2c on STM32F3 Discovery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-27 3: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.
- Labels:
-
I2C
-
STM32F3 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-27 5: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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-07-27 5: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:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-14 3: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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-14 4:40 PM
You probably want to use HAL_I2C_Mem_Write to write to a memory address.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-15 5: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-08-15 5: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.
