cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Discovery to LPS25H Example Code

tba10596
Associate II
Posted on July 22, 2015 at 14:08

All:

Is there I2C example code that can be used with the STM32F4 Discovery Board to connect to the LPS25H module?

I am running the processor at the full 168 MHz, and as far as I know, I have initialized the I2C1 port correctly.

 I have been trying to do the simplest thing - read the WhoAmI register, and I am not really sure what I should be inserting after even the I2C_GenerateSTART() function.

How much delay is needed after initialization until generating START?

Can I2C_CheckEvent() be used after START to check for condition before sending I2C Address? Lots of questions that could be solved by example code...

AN4450 App Note mentions in section 6.3 that there are examples, but is there a specific example to ''get started with LPS25H?''

Regards,

Todd Anderson 

#stm32f4 #about-lps25h
5 REPLIES 5
Nickname3482_O
Associate II
Posted on July 28, 2015 at 16:15

Hello Todd,

the closest reference code I found to match you request can be downloaded from the following page :

http://www.st.com/web/en/catalog/tools/PF261412

#

if you scroll down to the end of the page you can find a download button to get the zip.

There is basically a project coming with some reference code of STM32F4 I2C accessing LPS25H. It's not related to a Discovery platform as the one you own but you it's still an STM32F4 micro fw project (for nucleo platform) form which you can pick some code and make it work on your side after some board specific modifications. After you unzip, here is the path to the root of the project :

\STM32CubeExpansion_MEMS1_V1.3.0\Projects\Multi\Examples\DataLog

the project is ready to be used with IAR, uVision and System Workbench.

On the other hand, in starting from scratch from

the bottom you can refer to the (attached) sensor datasheet, with I2C timing diagram information and related delays coming at page 10 and bytewise transfer details at pages 16-17 through tables 10 to Regarding I2C master mode event checking you can get details within

your specific STM32F4XXXX micro's reference manual downloadable from

http://www.st.com

.

Best Regards,

Adalberto

________________

Attachments :

DM00066332.pdf : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzKM&d=%2Fa%2F0X0000000bJr%2FqLAiH7wRDr_SzA4ZbPrhsscSPEPgEowN7BChe_KsGJ4&asPdf=false
tba10596
Associate II
Posted on July 30, 2015 at 14:13

Muhuho:

Thank you for your response. 

You stated ''There is basically a project coming with some reference code of STM32F4 I2C accessing LPS25H.''

Does that mean there does not exist sample code to use I2C on the LPS25H?

We have been having a very difficult time getting the I2C interface working.

I have a STEVAL-MKI109V2 board with the STEVAL-MKI142V1 plug-in.

I am able to use that to view register contents, but I found that it uses SPI as the default interface. It does not look like the board offers an I2C option to connect to the plug-in.

At this point, I am considering using the SPI rather than I2C as the interface to the LPS25H. It does complicate things a bit, but it appears to be the more stable interface.

Regards,

Todd Anderson

Nickname3482_O
Associate II
Posted on July 31, 2015 at 17:32

Hello Todd,

the pointer I provided you in my latest answer was example code that you

can reach starting from ST main page (

http://www.st.com

) and browsing though the

following links :

Mems and sensors -> Pressure Sensors -> Software

I'm not sure why that doesn't match exactly what you expect from what you call

a ''sample code'', anyhow it is still published on the pressure sensor area and

provides a complete project to address LPS25H through I2C from the bottom up.

The main issue is that drivers can generally be split in two parts:

a higher level platform independent layer defining how to use data in an abstract

way and a platform dependent layer which implements details in order to exchange

data bytes on a specific bus (SPI or I2C in our case) and here is where implementation

details clearly change from platform to platform; would be ideally best to have at least one

project showing LPS25H access through I2C for each ST board/platform but unfortunately

today there is a really huge amount of different platforms coming from ST an we cannot

choose them all.

In your case however, since you are on the Discovery board with STM32F4 I expect the

published code to be a good reference because among other supported MCUs it comes with

an implementation for STM32F4 as well, so it might take you just some board specific

adaptations in order to run.

Best Regards,

Adalberto

tba10596
Associate II
Posted on August 07, 2015 at 14:44

Thank you for your reply. In the end, we went with SPI, and I am able to connect my STM32F4 Discovery Board to the STEVAL-MKI142V1 board, and initially read the WhoAmI register. Also, I went through the AN4450 appnote and was able to issue the register commands to be able to do a one-shot read of pressure. I received a valid pressure reading in doing this. I then went to a small board with a single TPS25H mounted, and I was able to repeat the procedure on the small board (built by our company).

I have tried using the Xcube plug-in for the Atollic IDE, and it would hopefully allow me to create code that would use I2C, but so far the learning curve has been pretty steep, and I will probably not continue to pursue the I2C path on this part.

Regards,

Todd Anderson

randya
Associate
Posted on March 16, 2016 at 16:42

Would you mind shearing you basic SPI code?  The Data sheet leaves out a lot.