2021-11-12 02:24 AM
2021-11-29 07:44 AM
thank you for your answer,
Actually I need to read acceleration and magnetic components using G071RB and LSM303AGR with STM32CubeIDE.
I tried to understand anything reading the Datasheet, but it is really hard (well, I am not familiar with such devices. I rather deal with different things usually). I managed to get proper who am I values, and reading the Acceleration components and their status register give some values (they change in time). The velues of magnetometer are constantly 0 and their status is constantly 0xFF, although the reading procedures git HAL_OK as output:
I did initialize the registers as it was suggested in Datasheet:
where HAL*feed_1B is:
That is why I decided to try to use some existing solutions. Alas that what I find here is not usable.
2021-11-29 11:18 PM
Ok so it is my understandment you did not manage to use the drivers provided in the link. (https://github.com/STMicroelectronics/lsm303agr/tree/b03141c1fb94fe2d6a523d01af792184863ed0e8)
If so, what seems to be the problem with them?
Basically (from my quick read) the driver just needs you to define the body of these functions
/** Please note that is MANDATORY: return 0 -> no Error.**/
int32_t platform_write(void *handle, uint8_t Reg, const uint8_t *Bufp, uint16_t len)
int32_t platform_read(void *handle, uint8_t Reg, uint8_t *Bufp, uint16_t len)
So you, in your main I guess, must write the content of them. In this case there will be an HAL_I2C function, so read about STM32 HAL before.
It should be like that, for example:
int32_t platform_write(void *handle, uint8_t Reg, const uint8_t *Bufp, uint16_t len)
{
HAL_I2C_Mem_Write((I2C_HandleTypeDef*)handle, DEVICE_ADDR, Reg, 1U, Bufp, len, 1000);
return 0;
}
But i see you have something like that in the source you linked a few days ago, so get inspired by that.
2021-11-30 09:56 AM
Well,
the problem is that nobody nowhere wrote what I should place between the braces in the platform_(write|read). Your example is very interesting, but I see there the variable DEVICE_ADDR which is not included in the formal parameter list. I suppose that is supposed to be a slave address, but what if there are two slaves as in the case now ??
As it concerns the sources you are probably asking for, I get there compilation error and a warning that reads the compiler does knot the example function:
2021-11-30 11:23 PM
Nobody nowhere wrote it because you should be able to write your own communication function.
Or to understand those implemented in your attached source from few days ago.
One could use any function/any platform as long as it manages all the platform_(write|read) variables.
As for the multi addressing, you could use a global variable and assigning the address value before calling the sensor driver's functions.
I don't know what your main job (if you don't mind telling me, I'm curious) is, but, estabilished you're not mainly a firmware developer, I suggest to start somewhere, somewhat. Forget the fact that you have 2 sensors, forget even the sensor if you did not grasp HAL_I2C functions yet. Practice a bit. Once you understand how to use HAL and how it works, move on. My example should work.
When something works, you can improve it.
For the compiler errors I don't know. Can you leave a screenshot?
2021-11-30 11:44 PM
Listen i tried importing the files and i can correctly compile and everything so, follow me:
stmdev_ctx_t myDev;
myDev.read_reg = platform_read;
myDev.write_reg= platform_read;
myDev.handle = &hi2c1;
Then you can call the functions appropriately passing &myDev and eventually &buf.
uint8_t buf;
lsm303agr_act_threshold_get(&myDev, &buf);
If this does not at least compile, i don't know what will.