Название: STM32 IoT Projects for Beginners: A Hands-On Guide to Connecting Sensors, Programming Embedded Systems, Build IoT Devices with STM32 Автор: Aharen san Издательство: Independently published Год: 2023 Страниц: 214 Язык: английский Формат: pdf Размер: 15.1 MB
We will see how to interface BM e 280 sensor with STM 32. This sensor can measure the temperature, pressure and relative humidity. I have written a library for it, which I will upload on the GitHub and you can get it from there. As we progress along the project, I will also explain the code and how you can write one yourself using the datasheet. The library covers a lot of things, but there are still few things which you need to manually implement.
So watch the project carefully as you might need to make changes in the library based on what requirements you have from the sensor. This is the datasheet for the device. Here I have highlighted few important things that I will cover in today's project. I will leave the link to this data sheet in the description.
Let's start with cube ID and create a new project I am using STM 32 F 103 controller give some name to the project and click finish first of all I am enabling the external crystal for the clock. The blue pill have eight megahertz crystal on board and I want the system to run at maximum 72 megahertz clock. Enable the serial wire debug. The sensor can use both the eye to C and SPI for communication. You can use either of those but I am going to go with the eye to see enable the eye to see interface and leave everything to default.
We have the two pins for data and clock. Before going any further in the project. Let's see the sensor and the connection with blue pill. Here is the BM e 280. And as you can see it has the pinout for both SPI and eye to see. Here I am connecting it with the blue pill.
It's powered with 3.3 volts and there are two pull up resistors each 4700 ohms connected between the clock and data pins and the 3.3 volts. Poor resistors must be used while using the eye to see communication. Also one very important thing I have grounded the SDO pin. Keep this in mind as it will be used in the addressing of the device. Now connect the PV six to the clock pin and PV seven to the SDI pin that is data pin.
That completes the connection. Let's generate the project now. First thing we will do is copy the library files into our project. So copy the C file into the source directory and header file into the include directory. Let's take a look at the source file. Here first we have to define the eye to see we are using as I set up the i two c one so I am leaving it unchanged.
The next thing is the 64 bit support. If your configuration supports 64 bit integers, then leave this as one or else to use the 32 bit integers uncomment the 32 bit support and comment out 64 bit the next is the address of the device. As mentioned in the datasheet the seven bits of the address are these. Here x depends on the SDO pin.
And if you remember I grounded the pin and therefore the X is zero in my case the slave address will consist of these seven address bits along with the read or write bit. So the address will be 11101100 which makes up zero Crossy see. These variables will store the corresponding values and they are externally defined here. So you should define them in the main file. The rest of the code should be unchanged for default configuration Let me explain how this works.
Скачать STM32 IoT Projects for Beginners: A Hands-On Guide to Connecting Sensors, Programming Embedded Systems