2021-11-12 02:24 AM
2021-11-12 03:21 AM
Welcome, @DrAK, to the community!
Maybe that's a typo and you mean LSM303AGR?
You can find the driver as source code on Github.
Good luck!
If the problem is resolved, please mark this topic as answered by selecting Select as best. This will help other users find that answer faster.
/Peter
2021-11-12 08:31 AM
och, indeed I meant LSM303AGR.
The driver alone won't help me much. I need an example how to use it.
thanks anyway,
2021-11-13 09:35 AM
Hi Peter,
I found the Examples and a kind of description how to use them. There are however a few points which are not quite clear:
The first is, what shall I uncomment here:
My board is nucleo-G071RB
Here
I do not see stm32f4xx_hal.h
Can you advice ??
2021-11-14 11:32 PM
To keep it clear, the example mentioned focuses on three typical platforms and clearly shows how to use it. But it also mentions directly above in the source code at line 47:
/* STMicroelectronics evaluation boards definition
*
* Please uncomment ONLY the evaluation boards in use.
* If a different hardware is used please comment all
* following target board and redefine yours.
*/
There are currently around 55 matching NUCLEO boards, so that the source text with all its options would be too confusing.
Your board NUCLEO-G071RB is very similar to the NUCLEO_F411RE, so you might use the conditional definitions
#if defined (NUCLEO_F411RE)
as a template and copy/change them to
#if defined (NUCLEO_G071RB)
Once you understand how the NUCLEO and the sensor work, it will be easy for you to make the changes.
Regards
/Peter
2021-11-15 12:33 PM
2021-11-15 11:34 PM
Unfortunately, your picture was not inserted correctly so that nothing can be seen here.
Well, my hints weren't a recipe that you just have to paste, but hints as to which code blocks you have to make changes in.
The #define and #if defined are used to make hardware-specific settings in the source code. So you should have a look at stm32f4xx_hal.h from the repository (locally on your computer if STM32F4 firmware is installed, alternatively on Github), plus the schematics and description of the NUCLEO-F411RE.
Finally compare the NUCLEO-F411RE with your NUCLEO-G071RB (schematics, description) and make the appropriate changes to the copied blocks.
Regards
/Peter
2021-11-18 08:27 AM
Well, you did not
I did what you had suggested,. That is, I copied the fragments concerning NUCLEO-F411RE and changed them appropriately. In particular, there I got:
/* Includes ------------------------------------------------------------------*/
#include "lsm303agr_reg.h"
#include <string.h>
#include <stdio.h>
#if defined(NUCLEO_F411RE)
#include "stm32f4xx_hal.h"
#include "usart.h"
#include "gpio.h"
#include "i2c.h"
#elif defined(NUCLEO_G071RB)
#include "stm32g0xx_hal.h"
//#include "usart.h"
//#include "gpio.h"
//#include "i2c.h"
#elif defined(STEVAL_MKI109V3)
#include "stm32f4xx_hal.h"
#include "usbd_cdc_if.h"
#include "gpio.h"
#include "spi.h"
#include "tim.h"
#elif defined(SPC584B_DIS)
#include "components.h"
#endif
It turned out that without commenting out the lines 14-16 above I got messages that the h-files do not exist.
This however did not help, for after that I get the error:
Well, the variable hi2c1 is defined here:
in main but but it is not seen in the very example function .
I do enclose the ZIP with the whole src directory. please make necessary corrections and share.
2021-11-23 07:16 AM
Hi, Peter,
will you try to answer my question, please?
I tried to buy the board NUCLEO-F411RE but they are out of store:
we need more pieces than just only a few.
If I will not be able to run the LSM303ARG with NUCLEO_G071RB, we will have to give up the idea of using your boards our project (we are talking about many pieces, not only one or three).
so please, try to help me relatively quickly.
2021-11-23 08:24 AM
Sorry, I didn't see a question other than a request to correct the code. However, rarely someone will change the given code here, but will give hints on how to do it yourself.
However: if the compiler cannot find the .h files, they are not included in the project. In your case, this is due to the fact that you probably created the frame program with STM32CubeIDE, whereby the default setting in the Project Manager ensures that the code for all peripherals is put together in one main.c/.h. If you check Generate peripheral initialization as a pair... in Project Manager > Code Generator, you will get the .c/.h files you are looking for, e.g. gpio.c/.h, i2c.c/.h, etc. But every programmer does this the way he likes it and in your case it is not absolutely necessary to change this setting, just leave the missing .h files commented out.
But it would be helpful to read the introductions that you can find at the very bottom of the main Github site and at the device driver site, in your case the driver site of the LSM303AGR. The main site also contains an example .ioc file for the NucleoF411, see here, which can be used as a template.
Regards
/Peter