What's the purpose of this project?
In this section, we are going to launch the BMP390 sensor using ARM microcontroller, STM32F series. In order to use more conveniently and optimally in this project, we use two ready modules GB636EN and GebraBit STM32F303. These two modules contain the minimum necessary elements of the BMP390 sensor and the STM32F microcontroller, which are provided by the GebraBit team to facilitate the work.
What are we going to learn in this tutorial?
In this tutorial, in addition to setting up and using the BMP390 sensor, you will get to know all the BMP390 sensor registers, how to set the various parts of the STM32 microcontroller to set up this sensor using the SPI protocol, how to use the GB636EN module specific library and driver file. You will also learn how to declare functions and finally receive sensor data in the Keil compiler.
What do we need to start this project?
As you probably know, we need some hardware and software to do this project. The titles of these hardware and software are provided to you in the table below and you can prepare/download by clicking on each of them and get ready to start.
Required hardware
|
Required software
|
---|---|
Keil compiler
|
|
STM32CubeMX program
|
|
ST-LINK/V2 programmer
|
First select the SPI communication protocol using the on-board jumpers and then we place the GebraBit BMP390 module as Pin to Pin on the GebraBit STM32F303 module as shown in the below picture :
Note: The above picture is intended only to show how the GebraBit BMP390 module is placed as pin to pin on the GebraBit STM32F303 module. Therefore, to use the SPI communication protocol, the user must choose the correct state of the on-board selector jumpers.
Finally, we will see the values of temperature, pressure, and approximate height in real time in the “Watch1” window of the Keil compiler in “Debug Session” mode.
STM32CubeMX settings
In the following, we review the settings related to each of the “SPI”, “RCC”, “Debug”, and “Clock” sections in the STM32F303 microcontroller to develop the GebraBit BMP390 module.
RCC settings
Due to the presence of “8Mhz” crystal in the GebraBit STM32F303 module, we select the “external clock” in the “RCC” section:
Debug & Programming settings
Regarding the access to “SWCLK” and “SWDIO” pins in the GebraBit STM32F303 module, to reduce the number of pins during “Debug & Programming”, in the “SYS” block, we select the “Serial Wire” option in the “Debug” section:
SPI settings
To communicate with the GebraBit STM32F303 module via SPI, we select the “Full Duplex Master” mode and select the PB3, PB4, and PB5 pins as SCK, MISO and MOSI and define the PC13 pin as CS:
According to the sensor data sheet, the settings of the SPI parameters in the “Parameter Settings” section will be set as shown in the above image.
Clock settings
The “clock” settings for each part of the STM32F303 microcontroller in this code, are as follows:
Project Manager settings
“Project Manager” settings are as follows, here we have used “MDK-ARM” version “5.32” compiler:
After completing all the above settings, we can develop our code easily just by one click on “GENERATE CODE” and adding the BMP390 library and driver (provided by GebraBit).
You can download the “STM32Cube MX”, “library”, “driver” and KEIL project at the end of this tutorial.
BMP390 library and driver
In addition to the modular design of various sensors and ICs, GebraBit tries to provide variety of structured and hardware-independent libraries in C language for the ease of users in setting up and developing software.
For this purpose, after preparing each GebraBit module, the users can refer to the “tutorial” section of the desired module and download the dedicated library, which contains the “ .h” and “ .c” file (Header and Source) and a sample training program under “GebraBit STM32F303”, “GebraBit ATMEGA32A” or “Arduino” development boards.
All the defined functions and structures in the library are commented in full detail and all the received parameters in the arguments of the functions and their return values, are briefly explained. Since the libraries are hardware independed, the user can easily add the library in any of their favorite compilers and develop it by desired microcontroller and development board.
GebraBit BMP390.h header file
In this file, based on the datasheet of the sensor or IC, all address registers, the values of each register are defined in the form of “Enumeration”. Also, the casing of the BMP390 sensor and the configurations related to each of the BMP390 sensor internal blocks are defined in the form of a “STRUCT” with the name GebraBit_ BMP390. Finally, in the Debug Session environment, all the configurations related to each block can be seen in real time.
Error_Condition Enum
Sensor errors are defined in this enum:
1. typedef enum Error_Condition
2. {
3. FATAL_ERR = 1 ,
4. CMD_ERR = 2 ,
5. CONF_ERR = 4
6. }BMP390_Error_Condition;
Sensor_Status Enum
The sensor performance status is defined in this enum:
1. typedef enum Sensor_Status
2. {
3. CMD_RDY = 0x10 ,
4. DRDY_PRESS = 0x20 ,
5. DRDY_TEMP = 0x40
6. }BMP390_Sensor_Status;
Interrupt_Status Enum
The occurred interrupt type is defined in this enum:
1. typedef enum Interrupt_Status
2. {
3. FIFO_WATERMARK_INTERRUPT = 0x01 ,
4. FIFO_FULL_INTERRUPT = 0x02 ,
5. DATA_READY_INTERRUPT = 0x08
6. }BMP390_Interrupt_Status
Data_Select Enum
Using this Enum, it is determined whether the output data is filtered or not:
1. typedef enum Data_Select
2. {
3. UNFILTERED_DATA = 0 ,
4. FILTERED_DATA
5. }BMP390_Data_Select;
FIFO_Mode Enum
Using this Enum, the type of data in FIFO is specified:
1. typedef enum FIFO_Mode
2. {
3. STREAM_TO_FIFO = 0 ,
4. STOP_ON_FULL_FIFO_SNAPSHOT = 1
5. }BMP390_FIFO_Mode
BMP390_Ability Enum
The ability to activate or deactivate different parts of the sensor is defined in this enum:
1. typedef enum Ability
2. {
3. Disable = 0 ,
4. Enable
5. }BMP390_Ability;
BMP390_Power_Mode Enum
The values of this enum are used to select the sensor Power mode:
1. typedef enum Power_Mode
2. {
3. SLEEP_MODE = 0,
4. FORCED_MODE = 1,
5. NORMAL_MODE = 3
6. } BMP390_Power_Mode;
BMP390_Sensor_Oversampling Enum
The values of this enum are used to select oversampling of the sensor:
1. typedef enum Pressure_Oversampling
2. {
3. X1_NO_OVERSAMPLING = 0 ,
4. X2_OVERSAMPLING = 1 ,
5. X4_OVERSAMPLING = 2 ,
6. X8_OVERSAMPLING = 3 ,
7. X16_OVERSAMPLING = 4 ,
8. X32_OVERSAMPLING = 5
9. } BMP390_Sensor_Oversampling;
BMP390_Output_Data_Rate Enum
The values of this enum are used to select the sensor output data rate:
1. typedef enum Output_Data_Rate
2. {
3. ODR_200_HZ_5_mS = 0 ,
4. ODR_100_HZ_10_mS = 1 ,
5. ODR_50_HZ_20_mS = 2 ,
6. ODR_25_HZ_40_mS = 3 ,
7. ODR_12P5_HZ_80_mS = 4 ,
8. ODR_6P25_HZ_160_mS = 5 ,
9. ODR_3P1_HZ_320_mS = 6 ,
10. ODR_1P5_HZ_640_mS = 7 ,
11. ODR_0P78_HZ_1280_mS = 8 ,
12. ODR_0P39_HZ_2560_mS = 9 ,
13. ODR_0P2_HZ_5120_mS = 10 ,
14. ODR_0P1_HZ_10240_mS = 11 ,
15. ODR_0P05_HZ_20480_mS = 12 ,
16. ODR_0P02_HZ_40960_mS = 13 ,
17. ODR_0P01_HZ_81920_mS = 14 ,
18. ODR_0P006_HZ_163840_mS = 15 ,
19. ODR_0P003_HZ_327680_mS = 16 ,
20. ODR_0P0015_HZ_655360_mS = 17
21. } BMP390_Output_Data_Rate;
BMP390_IIR_Filter_Coefficient Enum
The values of this enum are used to select the appropriate sensor calibration coefficients values:
1. typedef enum IIR_Filter_Coefficient
2. {
3. FILTER_BYPASS_MODE = 0 ,
4. FILTER_COEFFICIENT_1 = 1 ,
5. FILTER_COEFFICIENT_3 = 2 ,
6. FILTER_COEFFICIENT_7 = 3 ,
7. FILTER_COEFFICIENT_15 = 4 ,
8. FILTER_COEFFICIENT_31 = 5 ,
9. FILTER_COEFFICIENT_63 = 6 ,
10. FILTER_COEFFICIENT_127 = 7
11. } BMP390_IIR_Filter_Coefficient;
BMP390_ FIFO_Header Enum
The values of this enum are used to select the data frame type in the FIFO header:
1. typedef enum FIFO_Header
2. {
3. FIFO_EMPTY_FRAME = 0x80 ,
4. FIFO_CONFIG_CHANGE = 0x48 ,
5. FIFO_ERROR_FRAME = 0x44 ,
6. FIFO_TIME_FRAME = 0xA0 ,
7. FIFO_PRESS_FRAME = 0x84 ,
8. FIFO_TEMP_FRAME = 0x90 ,
9. FIFO_TEMP_PRESS_FRAME = 0x94
10. } BMP390_FIFO_Header;
BMP390_Preparation Enum
The values of this enum determine whether the data is ready or not:
1. typedef enum Preparation
2. {
3. IS_Ready = 0 ,
4. IS_NOT_Ready
5. }BMP390_Preparation;
BMP390_ Get_DATA Enum
The values of this enum are used to determine how to receive sensor data:
1. typedef enum Get_DATA
2. {
3. FROM_REGISTER = 0 ,
4. FROM_FIFO
5. } BMP390_Get_DATA;
BMP390_Reset_Status Enum
The values of this enum determine whether the sensor is reset or not:
1. typedef enum
2. {
3. DONE = 0 ,
4. FAILED = 1
5. }BMP390_Reset_Status;
BMP390_ INT_Level Enum
The values of this enum are used to determine the basic logic level of Interrupt:
typedef enum int_level
{
ACTIVE_LOW = 0 ,
ACTIVE_ HIGH
} BMP390_INT_Level;
BMP390_ Latch_Type Enum
The values of this enum are used to determine the Interrupt output latch type:
typedef enum latch_type
{
NOT_LATCH = 0 ,
LATCH
} BMP390_Latch_Type;
BMP390_ INT_Type Enum
The values of this enum are used to determine the Interrupt output type:
typedef enum int_type
{
PUSH_PULL = 0 ,
OPEN_DRAIN
}BMP390_INT_Type;
BMP390 struct
Declaration of functions
At the end of this file, all the functions for reading and writing in BMP390 registers, sensor configuration and receiving data from the sensor are declared:
1. /********************************************************
2. *Declare Read&Write BMP390 Register Values Functions *
3. ********************************************************/
4. extern uint8_t GB_BMP390_Read_Reg_Data ( uint8_t regAddr,uint8_t* data);
5. extern uint8_t GB_BMP390_Read_Reg_Bits (uint8_t regAddr,uint8_t start_bit, uint8_t len, uint8_t* data);
6. extern uint8_t GB_BMP390_Burst_Read(uint8_t regAddr,uint8_t *data, uint16_t byteQuantity);
7. extern uint8_t GB_BMP390_Write_Reg_Data(uint8_t regAddr, uint8_t data);
8. extern uint8_t GB_BMP390_Write_Reg_Bits(uint8_t regAddr, uint8_t start_bit, uint8_t len, uint8_t data);
9. extern uint8_t GB_BMP390_Burst_Write ( uint8_t regAddr,uint8_t *data, uint16_t byteQuantity);
10. /********************************************************
11. * Declare BMP390 Configuration Functions *
12. ********************************************************/
13. extern void GB_BMP390_Soft_Reset ( GebraBit_BMP390 * BMP390 );
14. extern void GB_BMP390_Get_Device_ID(GebraBit_BMP390 * BMP390);
15. extern void GB_BMP390_Get_Revision_ID(GebraBit_BMP390 * BMP390);
16. extern void GB_BMP390_Temperature(GebraBit_BMP390* BMP390 ,BMP390_Ability temp);
17. extern void GB_BMP390_Pressure(GebraBit_BMP390 * BMP390 , BMP390_Ability press);
18. extern void GB_BMP390_Output_Sample_Rate (GebraBit_BMP390 * BMP390 , BMP390_Output_Data_Rate rate);
19. extern void GB_BMP390_IIR_Filter_Coefficient (GebraBit_BMP390 * BMP390 , BMP390_IIR_Filter_Coefficient filter) ;
20. extern void GB_BMP390_Check_Sensor_Status(GebraBit_BMP390 * BMP390 );
21. extern void GB_BMP390_Check_Error_Codition(GebraBit_BMP390 * BMP390 );
22. extern void GB_BMP390_Check_FIFO_Full_Interrupt_(GebraBit_BMP390 * BMP390 );
23. extern void GB_BMP390_Check_Data_Ready_Interrupt(GebraBit_BMP390 * BMP390 );
24. extern void GB_BMP390_Temperature_OverSampling(GebraBit_BMP390* BMP390 ,BMP390_Sensor_Oversampling temp_over) ;
25. extern void GB_BMP390_Pressure_OverSampling(GebraBit_BMP390* BMP390 ,BMP390_Sensor_Oversampling press_over);
26. extern void GB_BMP390_Power_Mode(GebraBit_BMP390* BMP390 ,BMP390_Power_Mode pmode);
27. extern void GB_BMP390_Set_INT_Pin(GebraBit_BMP390 * BMP390 , BMP390_INT_Level level ,BMP390_INT_Type type , BMP390_Latch_Type latch ) ;
28. extern void GB_BMP390_Data_Output_Select(GebraBit_BMP390 * BMP390 , BMP390_Data_Select data_sel) ;
29. extern void GB_BMP390_Data_Ready_Interrupt(GebraBit_BMP390 * BMP390 , BMP390_Ability data_ready_int);
30. extern void GB_BMP390_FIFO(GebraBit_BMP390 * BMP390 , BMP390_Ability fifo) ;
31. extern void GB_BMP390_FIFO_Full_Interrupt(GebraBit_BMP390 * BMP390 , BMP390_Ability fifo_full_int) ;
32. extern void GB_BMP390_Write_SensorTime_FIFO(GebraBit_BMP390 * BMP390 , BMP390_Ability time_fifo );
33. extern void GB_BMP390_Write_Pressure_FIFO(GebraBit_BMP390 * BMP390 , BMP390_Ability press_fifo );
34. extern void GB_BMP390_Write_Temperature_FIFO(GebraBit_BMP390 * BMP390 , BMP390_Ability temp_fifo );
35. extern void GB_BMP390_FIFO_Mode(GebraBit_BMP390 * BMP390 , BMP390_FIFO_Mode fifo_mode );
36. extern void GB_BMP390_FIFO_DownSampling(GebraBit_BMP390 * BMP390,uint8_t dwnsmple);
37. extern void GB_BMP390_FIFO_WATERMARK (GebraBit_BMP390 * BMP390,BMP390_Ability watermark , uint16_t wm);
38. extern void GB_BMP390_GET_FIFO_Length (GebraBit_BMP390 * BMP390 ) ;
39. extern void GB_BMP390_FIFO_Flush(GebraBit_BMP390 * BMP390 );
40. extern void GB_BMP390_Read_FIFO(GebraBit_BMP390 * BMP390 , uint16_t qty);
41. extern void GB_BMP390_FIFO_Configuration ( GebraBit_BMP390 * BMP390 , BMP390_FIFO_Ability fifo );
42. /********************************************************
43. * Declare BMP390 DATA Functions *
44. ********************************************************/
45. extern void GB_BMP390_Get_Register_Raw_Pressure_Temperature(GebraBit_BMP390 * BMP390 ) ;
46. extern void GB_BMP390_Calculate_Compensated_Temperature(GebraBit_BMP390 * BMP390 , int32_t raw_temp , double * valid_temp ) ;
47. extern void GB_BMP390_Calculate_Compensated_Pressure(GebraBit_BMP390 * BMP390 , int32_t raw_press , double valid_temp ,double * valid_press );
48. extern void GB_BMP390_FIFO_Data_Partition_Pressure_Temperature(GebraBit_BMP390 * BMP390);
49. extern void GB_BMP390_Altitude(GebraBit_BMP390 * BMP390);
50. extern void GB_BMP390_Get_Data(GebraBit_BMP390 * BMP390 , BMP390_Get_DATA get_data);
51. /********************************************************
52. * Declare BMP390 HIGH LEVEL Functions *
53. ********************************************************/
54. extern void GB_BMP390_Set_Power_Management(GebraBit_BMP390 * BMP390 , BMP390_Power_Mode pmode) ;
55. extern void GB_BMP390_initialize( GebraBit_BMP390 * BMP390 );
56. extern void GB_BMP390_Configuration(GebraBit_BMP390 * BMP390, BMP390_FIFO_Ability fifo);
GebraBit_ BMP390.c source file
In this file, which is written in C language, all the functions are commented in full detail, and all the parameters received in the arguments of the functions and their return values are clearly explained so we confine to these explanations and invite users to check this file directly for more information.
Sample program in Keil
After making the Keil project by STM32CubeMX and adding the “GebraBit_BMP390.c” library provided by GebraBit, we will examine the “main .c” file of the sample tutorial and view the output of the GebraBit_BMP390 module in the “watch” part in the Keil compiler “Debugging” environment.
Description of “main.c” file
If you look carefully at the beginning part of the “main.c” file, you will notice that the “GebraBit_BMP390.h” header has been added to access the GebraBit BMP390 module required structures, Enums and functions. In the next part, a variable named BMP390_Module of the GebraBit_BMP390 structure type (this structure is in the GebraBit_BMP390 header and is explained in the GebraBit_BMP390 library description section) is defined for the configuration of the GebraBit BMP390 module:
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
GebraBit_BMP390 BMP390_ MODULE;
/* USER CODE END PTD */
In the next section of the written code, we set and configure the GebraBit BMP390 module using the GB_BMP390_initialize (&BMP390_Module) and GB_BME280_Configuration (&BMP390_MODULE) functions:
1. /* Initialize all configured peripherals */
2. MX_GPIO_Init();
3. MX_I2C1_Init();
4. MX_SPI1_Init();
5. /* USER CODE BEGIN 2 */
6. GB_BMP390_initialize( &BMP390_Module );
7. //GB_BMP390_Configuration(&BMP390_Module, FIFO_DISABLE) ;
8. GB_BMP390_Configuration(&BMP390_Module, FIFO_ENABLE) ;
9. /* USER CODE END 2 */
And finally, we read the data from the sensor and continuously receive the values of pressure, temperature and altitude in the “while” part of the program:
1. /* USER CODE BEGIN WHILE */
2. while (1)
3. {
4.
5. GB_BMP390_Get_Data(&BMP390_Module, FROM_FIFO);
6. //GB_BMP390_Get_Data(&BMP390_Module, FROM_REGISTER);
7. /* USER CODE END WHILE */
8.
9. /* USER CODE BEGIN 3 */
10. }
11. /* USER CODE END 3 */
The “main.c” file code text:
1. /* USER CODE BEGIN Header */
2. /*
3. * ________________________________________________________________________________________________________
4. * Copyright (c) 2020 GebraBit Inc. All rights reserved.
5. *
6. * This software, related documentation and any modifications thereto (collectively “Software”) is subject
7. * to GebraBit and its licensors' intellectual property rights under U.S. and international copyright
8. * and other intellectual property rights laws.
9. *
10. * GebraBit and its licensors retain all intellectual property and proprietary rights in and to the Software
11. * and any use, reproduction, disclosure or distribution of the Software without an express license agreement
12. * from GebraBit is strictly prohibited.
13.
14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15. * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT IN
16. * NO EVENT SHALL GebraBit BE LIABLE FOR ANY DIRECT, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
17. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
18. * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
19. * OF THE SOFTWARE.
20. * ________________________________________________________________________________________________________
21. */
22. /**
23. ******************************************************************************
24. * @file : main.c
25. * @brief : Main program body
26. * @Author : Mehrdad Zeinali
27. ******************************************************************************
28. * @attention
29. *
30. * Copyright (c) 2022 STMicroelectronics.
31. * All rights reserved.
32. *
33. * This software is licensed under terms that can be found in the LICENSE file
34. * in the root directory of this software component.
35. * If no LICENSE file comes with this software, it is provided AS-IS.
36. *
37. ******************************************************************************
38. */
39. /* USER CODE END Header */
40. /* Includes ------------------------------------------------------------------*/
41. #include "main.h"
42. #include "i2c.h"
43. #include "spi.h"
44. #include "gpio.h"
45.
46. /* Private includes ----------------------------------------------------------*/
47. /* USER CODE BEGIN Includes */
48. #include "GebraBit_BMP390.h"
49. /* USER CODE END Includes */
50.
51. /* Private typedef -----------------------------------------------------------*/
52. /* USER CODE BEGIN PTD */
53. GebraBit_BMP390 BMP390_Module;
54. /* USER CODE END PTD */
55.
56. /* Private define ------------------------------------------------------------*/
57. /* USER CODE BEGIN PD */
58. /* USER CODE END PD */
59.
60. /* Private macro -------------------------------------------------------------*/
61. /* USER CODE BEGIN PM */
62.
63. /* USER CODE END PM */
64.
65. /* Private variables ---------------------------------------------------------*/
66.
67. /* USER CODE BEGIN PV */
68.
69. /* USER CODE END PV */
70.
71. /* Private function prototypes -----------------------------------------------*/
72. void SystemClock_Config(void);
73. /* USER CODE BEGIN PFP */
74.
75. /* USER CODE END PFP */
76.
77. /* Private user code ---------------------------------------------------------*/
78. /* USER CODE BEGIN 0 */
79.
80. /* USER CODE END 0 */
81.
82. /**
83. * @brief The application entry point.
84. * @retval int
85. */
86. int main(void)
87. {
88. /* USER CODE BEGIN 1 */
89.
90. /* USER CODE END 1 */
91.
92. /* MCU Configuration--------------------------------------------------------*/
93.
94. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
95. HAL_Init();
96.
97. /* USER CODE BEGIN Init */
98.
99. /* USER CODE END Init */
100.
101. /* Configure the system clock */
102. SystemClock_Config();
103.
104. /* USER CODE BEGIN SysInit */
105.
106. /* USER CODE END SysInit */
107.
108. /* Initialize all configured peripherals */
109. MX_GPIO_Init();
110. MX_I2C1_Init();
111. MX_SPI1_Init();
112. /* USER CODE BEGIN 2 */
113. GB_BMP390_initialize( &BMP390_Module );
114. //GB_BMP390_Configuration(&BMP390_Module, FIFO_DISABLE) ;
115. GB_BMP390_Configuration(&BMP390_Module, FIFO_ENABLE) ;
116. /* USER CODE END 2 */
117. /* Infinite loop */
118. /* USER CODE BEGIN WHILE */
119. while (1)
120. {
121.
122. GB_BMP390_Get_Data(&BMP390_Module, FROM_FIFO);
123. //GB_BMP390_Get_Data(&BMP390_Module, FROM_REGISTER);
124. /* USER CODE END WHILE */
125.
126. /* USER CODE BEGIN 3 */
127. }
128. /* USER CODE END 3 */
129. }
130.
131. /**
132. * @brief System Clock Configuration
133. * @retval None
134. */
135. void SystemClock_Config(void)
136. {
137. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
138. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
139. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
140.
141. /** Initializes the RCC Oscillators according to the specified parameters
142. * in the RCC_OscInitTypeDef structure.
143. */
144. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
145. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
146. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
147. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
148. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
149. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
150. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
151. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
152. {
153. Error_Handler();
154. }
155.
156. /** Initializes the CPU, AHB and APB buses clocks
157. */
158. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
159. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
160. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
161. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
162. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
163. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
164.
165. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
166. {
167. Error_Handler();
168. }
169. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
170. PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
171. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
172. {
173. Error_Handler();
174. }
175. }
176.
177. /* USER CODE BEGIN 4 */
178.
179. /* USER CODE END 4 */
180.
181. /**
182. * @brief This function is executed in case of error occurrence.
183. * @retval None
184. */
185. void Error_Handler(void)
186. {
187. /* USER CODE BEGIN Error_Handler_Debug */
188. /* User can add his own implementation to report the HAL error return state */
189. __disable_irq();
190. while (1)
191. {
192. }
193. /* USER CODE END Error_Handler_Debug */
194. }
195.
196. #ifdef USE_FULL_ASSERT
197. /**
198. * @brief Reports the name of the source file and the source line number
199. * where the assert_param error has occurred.
200. * @param file: pointer to the source file name
201. * @param line: assert_param error line source number
202. * @retval None
203. */
204. void assert_failed(uint8_t *file, uint32_t line)
205. {
206. /* USER CODE BEGIN 6 */
207. /* User can add his own implementation to report the file name and line number,
208. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
209. /* USER CODE END 6 */
210. }
211. #endif /* USE_FULL_ASSERT */
212.
Program output
After generating the Keil project using STM32CubeMX and adding the library, we connect the STLINK V2 programmer to the GebraBit STM32F303 using the STLINKV2 adapter:
STLINKV2 adapter:
By connecting the STLINK V2 programmer to the GebraBit STM32F303, there is no need to apply power to the GebraBit STM32F303 and GebraBit BMP390 modules, because they receive their supply voltage directly from the STLINK V2 programmer.
Finally, enter the “Debug” mode and by adding the “BMP390_Module” to the “watch” window and running the program, we can see the changes in pressure, temperature and altitude of the GebraBit BMP390 module.
Receiving sensor data directly from data registers:
Receiving sensor data from FIFO:
In the following, you can download the “GebraBit BMP390 module setup project” using the GebraBit STM32F303 module in the Keil environment, the “STM32CubeMX file”, the schematic of the modules and the “BMP390 datasheet”.