7512 views|8 replies

9721

Posts

24

Resources
The OP
 

LPS22HB Quick Start (I) Verify that a sensor is communicating properly [Copy link]

 LPS22HB is an ultra-small pressure sensor from ST. It uses the I2C interface for communication. This post will introduce some preparations before using LPS22HB and solutions to some common problems. These methods are also applicable to other sensors from ST.
When you buy a new sensor, you need to determine the following three things:
1. Is the sensor chip normal?
This situation often occurs when we manually solder the board. Some sensors are relatively small, and the process of manual soldering is very painful. For various reasons, it is impossible to determine whether the soldered board can work normally. These may include incorrect PCB design, static electricity damage to the device during soldering, excessive soldering temperature damage to the device, reversed pin order during soldering, poor contact between the chip pins and PCB pads after soldering, etc. 2. Are the connections between the sensor and the MCU normal? When connecting the sensor and the MCU, check whether the communication pins of the sensor are correctly connected to the corresponding pins of the MCU, whether the SCL and SDA of I2C are connected reversely, whether the upper resistors of SCL and SCA are connected, etc.
3. Is the MCU driver normal?
For frequently used MCUs, there is usually a set of verified drivers. For example, the I2C of this MCU has driven an EEPROM before, and I can be sure that it is normal. Otherwise, when there is no verified driver library for the specified MCU, a new design or modification is often required, and the question is whether the driver you just wrote is easy to use. If the above three points cannot be confirmed, that is, it is not sure whether the sensor board is working properly and whether the MCU driver is normal, and the wiring may be wrong, the first thing we have to do after soldering the board, connecting the wires, and writing the driver is to verify whether the communication is normal. ST's sensors have a register called WHO AM I. Different devices correspond to different values. The register address of WHO_AM_I of LPS22HB is 0x0F, and the corresponding value is 0xB1. Therefore, as long as 0x0F is read and 0xB1 is obtained, the above three uncertainties can be basically ruled out, proving that the communication is normal, or at least that the read operation is normal.
It is a pleasant thing to debug LPS22HB using STM32, because STM32 provides STM32CubeMX software, which can save a lot of time in writing and verifying code.
Let's talk about how to use STM32 to drive LPS22HB:
1. Open STM32CubeMX, click New Project to create a new project, enter the microcontroller model to be found and then double-click the corresponding model found
2. Enable the corresponding digital peripherals. The board I use is BlueCoin. LPS22HB is connected to the PB8 and PB9 pins under I2C1, so enable I2C1 first
3. Click PB8 and PB9 and select the pin function as I2C1_SCL and I2C1_SDA
4. After selecting, you do not need to do more configuration for I2C1, you can directly generate code
5. Open the project with the specified IDE. I use IAR. Add two lines of code to read who am I in the main function.
Among them, 0xBA is the device address of LPS22HB, because the development board connects SA0 of LPS22HB to VDD, and 0x0F is the register address of WHO_AM_I.
6. After running, we can see that the who am i read is 0xB1, which proves that the communication is successful.
[font=Calibri, It can be seen that it is very easy to debug LPS22HB with STM32. You only need to write 2 lines of code. It is also a very lucky thing to complete the communication function at one time. Because I use the official evaluation board and verify the function of the sensor with the official code, all hardware problems can be ruled out. Even if the first debugging is not successful, I can only suspect that there is a problem with the code I wrote without considering the hardware.
In actual testing, the PCB may be designed by yourself. If there is a problem, it will be troublesome to solve it. In order to save debugging time, it is best to use the official development board for verification in the early stage to ensure that at least one of the sensor hardware or the microcontroller driver is normal. You can also use the verified hardware to verify the newly written driver or use the verified driver to verify the newly designed sensor hardware. For example, use another development board with normal I2C to read the newly drawn sensor development board to determine whether there is a problem with the sensor hardware, or use a peripheral with normal I2C communication to verify whether the newly written I2C driver on the microcontroller is normal. Otherwise, you can only use an oscilloscope or logic analyzer to painfully capture the waveform to see whether the data sent by the microcontroller and the data returned by the sensor are normal and then analyze them step by step.
This post is from MEMS sensors

Latest reply

Thanks for sharing! I recently used LPS25HB, which also uses IIC communication. I drew the board myself, but I couldn't read the ID. LPS25HB is very similar to LPS22HB. I followed this method to read the ID of LPS25HB and found that I couldn't read it. So I concluded that it was a hardware problem. I bought a development board from the Internet and was able to read the ID using this method. It seems that my PCB Layout is wrong.  Details Published on 2024-4-6 21:15
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 

3

Posts

0

Resources
2
 
Does anyone have a routine to drive LPS22HB with spi?
This post is from MEMS sensors

Comments

The boards I have are all I2C interfaces, so I can't use SPI to test. Using SPI should be easier than I2C, at least you don't have to consider the device address. Below is the official LPS22HB driver. You can implement Sensor_IO_Read and Sensor_IO_Write using SPI. If you have any questions, please post them.  Details Published on 2018-1-22 17:56
 
 
 

9721

Posts

24

Resources
3
 
Da Da Bing posted on 2018-1-22 17:05 Does anyone have a routine for SPI driving LPS22HB?
The boards I have are all I2C interfaces, so I can't use SPI for testing. Using SPI should be easier than I2C, at least I don't have to consider the device address. Below is the official LPS22HB driver. Try implementing Sensor_IO_Read and Sensor_IO_Write using SPI. If you have any questions, please post a question. en.stsw-mems039.zip (17.32 KB, downloads: 71)
This post is from MEMS sensors
Personal signature虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 
 

3

Posts

0

Resources
4
 
littleshrimp posted on 2018-1-22 17:56 The boards I have are all I2C interfaces, and I can't use SPI to test. Using SPI should be easier than I2C, at least I don't have to consider the device address. Below is the official...
Well, thank you, I'll take a look at this official example first, and ask you if I have any questions
This post is from MEMS sensors
 
 
 

3

Posts

0

Resources
5
 
Which version of IAR did you use to debug lps22? I tried it and it gave me an error. The version is wrong.
This post is from MEMS sensors

Comments

Try 7.7  Details Published on 2018-4-20 16:14
 
 
 

9721

Posts

24

Resources
6
 
permanent809 posted on 2018-4-20 16:07 Which version of IAR did you use to debug lps22? I tried it and got an error. The version is wrong.
Try 7.7
This post is from MEMS sensors
 
 
 

3

Posts

0

Resources
7
 
I searched for 7.7 for a long time but couldn’t find it, so I downloaded 7.8 and tried it.
This post is from MEMS sensors

Comments

Try backward compatibility  Details Published on 2018-4-20 21:06
 
 
 

9721

Posts

24

Resources
8
 
permanent809 posted on 2018-4-20 20:18 I have been looking for 7.7 but I can't find it. I will download 7.8 to try.
Let's try it. Backward compatibility
This post is from MEMS sensors
 
 
 

4

Posts

1

Resources
9
 
Thanks for sharing! I recently used LPS25HB, which also uses IIC communication. I drew the board myself, but I couldn't read the ID. LPS25HB is very similar to LPS22HB. I followed this method to read the ID of LPS25HB and found that I couldn't read it. So I concluded that it was a hardware problem. I bought a development board from the Internet and was able to read the ID using this method. It seems that my PCB Layout is wrong.
This post is from MEMS sensors
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list