Skip to main content
DrAK
Associate
November 12, 2021
Question

Hi, I need to communicate the LSM202AGR accelerometer with I2C . Can you help? Some hints ? The info included in datasheet is not very usefull.

  • November 12, 2021
  • 5 replies
  • 4143 views

..

This topic has been closed for replies.

5 replies

Peter BENSCH
Technical Moderator
November 12, 2021

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DrAK
DrAKAuthor
Associate
November 13, 2021

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:

0693W00000GXTgBQAX.pngMy board is nucleo-G071RB

Here

0693W00000GXTg1QAH.pngI do not see stm32f4xx_hal.h

Can you advice ??

DrAK
DrAKAuthor
Associate
November 12, 2021

och, indeed I meant LSM303AGR.

The driver alone won't help me much. I need an example how to use it.

thanks anyway,

Peter BENSCH
Technical Moderator
November 15, 2021

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DrAK
DrAKAuthor
Associate
November 15, 2021
I did what you did and that does not work: [image: image.png] I do not see the *stm32f4xx_hal.h* file anywhere. should one not *#include* to avoid the last warning ?? pon., 15 lis 2021 o 08:33 ST Community napisał(a):
DrAK
DrAKAuthor
Associate
November 18, 2021

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:

0693W00000GY4MNQA1.png 

Well, the variable hi2c1 is defined here:

0693W00000GY4NuQAL.pngin 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.

DrAK
DrAKAuthor
Associate
November 23, 2021

Hi, Peter,

will you try to answer my question, please?

I tried to buy the board NUCLEO-F411RE but they are out of store:

0693W00000GYbPkQAL.pngwe 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.

Peter BENSCH
Technical Moderator
November 23, 2021

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

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
DrAK
DrAKAuthor
Associate
November 23, 2021

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.

So you could write it immediately. I was waiting for you answer and I thought you need time to make an appropriate research.

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.

So you are telling me that in order to drink a glass of milk, I must buy a cow or better the whole herd ??

I would not call this way as "support" and this does not encourage fro working with your products !!

Besides I din not find the information included in the links you included as useful but rather as worthless.

The main site also contains an example .ioc file for the NucleoF411, see here, which can be used as a template.

are you sure I may use .ioc targeted for NucleoF411 with G071RB ??

And you did not answer the last question. What with the variable hi2c1 ??

Just read carefully what - I asked about that at the very end.

DrAK
DrAKAuthor
Associate
November 24, 2021

well, I as so that you're an ST Employee, I was convinced it is just the case that you want to support me on behalf of your company. Just cancel your title, and such misunderstandings will not happen. I wasted almost a fortweek waiting for a sensible answer/solution of my problem, Peter. And my boss demands progress and insists !

regards,

Peter BENSCH
Technical Moderator
November 24, 2021

By the way - because you mentioned that you wanted to use many of the NUCLEO boards: to avoid problems later, you and your boss should read the Evaluation Board Terms of Use of the NUCLEO-G071RB. Under Restrictions and Warnings you will find (excerpt):

The Evaluation Board offers limited features and is conceived to be used only to evaluate and test ST products in a research and development setting.

[...]

The Evaluation Board shall not be, in any case, directly or indirectly assembled as a part in any production of Yours as it is solely developed to serve evaluation and testing purposes and has no direct function and is not a finished product.

[...]

You shall not use, in whole or in part, the Evaluation Board in a production system. Except as provided in this Agreement or as explicitly permitted in the documentation of the Evaluation Board, You may not reproduce the Evaluation Board or modify, reverse engineer, de-compile or disassemble its software and/or firmware, in whole or in part.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.