GebraBit

BME280 Sensor Project With STM32F303 Microcontroller

متن سربرگ خود را وارد کنید

BME280 gebrabit project

BME280 Sensor Project With STM32F303 Microcontroller

BME280 gebrabit project
  1. Home
  2. »
  3. Projects
  4. »
  5. BME280 Sensor Project With STM32F303 Microcontroller

What's the purpose of this project?

In this section, we are going to launch the BME280 sensor using ARM microcontroller, STM32F series. In order to use more conveniently and optimally in this project, we use two ready modules GB635N and GebraBit STM32F303. These two modules contain the minimum necessary elements of the BME280 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 BME280 sensor, you will get to know all the BME280 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 GB635EN 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 BME280 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 BME280 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 BME280 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 BME280 library and driver (provided by GebraBit).

You can download the “STM32Cube MX”, “library”, “driver” and KEIL project at the end of this tutorial.   

BME280 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 BME280.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 theBME280 sensor and the configurations related to each of the BME280 sensor internal blocks are defined in the form of a “STRUCT” with the name GebraBit_ BME280. Finally, in the Debug Session environment, all the configurations related to each block can be seen in real time.    

BME280_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. }BME280_Ability;

				
			

BME280_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. } BME280_Power_Mode; 

				
			

BME280_Sensor_Oversampling Enum

The values of this enum are used to select the sensor oversampling:

				
					1. typedef enum Pressure_Oversampling
2. {									
3. 	 X1_OVERSAMPLING    = 1 , 					
4. 	 X2_OVERSAMPLING    = 2 ,				  
5. 	 X4_OVERSAMPLING    = 3 ,                    
6. 	 X8_OVERSAMPLING    = 4 ,					
7. 	 X16_OVERSAMPLING   = 5		                  
8. } BME280_Sensor_Oversampling;  

				
			

BME280_Inactive_Duration Enum

The values of this enum are used to select the sensor stand-by time:

				
					1. typedef enum Inactive_Duration
 2. {
 3. 	 INACTIVE_DURATION_5_mS           = 0 ,                  
 4. 	 INACTIVE_DURATION_62P5_mS        = 1 ,				
 5. 	 INACTIVE_DURATION_125_mS         = 2 ,				
 6. 	 INACTIVE_DURATION_250_mS         = 3 ,
 7. 	 INACTIVE_DURATION_500_mS         = 4 ,                  
 8. 	 INACTIVE_DURATION_1000_mS        = 5 ,				
 9. 	 INACTIVE_DURATION_10_mS          = 6 ,			
10. 	 INACTIVE_DURATION_20_mS          = 7 
11. } BME280_Inactive_Duration;

				
			

BME280_IIR_Filter_Coefficient Enum

The values of this enum are used to select the appropriate values of sensor calibration coefficients:

				
					1. typedef enum IIR_Filter_Coefficient
2. {
3. 	 FILTER_OFF               = 0 ,                  
4. 	 FILTER_COEFFICIENT_2     = 1 ,					
5. 	 FILTER_COEFFICIENT_4     = 2 ,					
6. 	 FILTER_COEFFICIENT_8     = 3 ,
7. 	 FILTER_COEFFICIENT_16    = 4 
8. } BME280_IIR_Filter_Coefficient;

				
			

BME280_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. }BME280_Preparation;

				
			

BME280_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. }BME280_Reset_Status; 

				
			

BME280 struct

All sensor properties, calibration coefficients and sensor data are defined in this “struct” and All the information and configuration implemented on the sensor are stored in this “structure” and you can see the changes in each part of the sensor in the “Debug Session” environment.

				
					 1. typedef struct BME280
 2. {
 3.     uint8_t                       	   REGISTER_CACHE;
 4.     BME280_Reset_Status                RESET;
 5.     uint8_t                       	   DEVICE_ID;
 6.     BME280_Preparation		           CONVERSION_RESULT;
 7.     BME280_Preparation		           NVM_DATA;
 8.     BME280_Power_Mode                  POWER_MODE;
 9.     BME280_Ability                     TEMPERATURE;
10.     BME280_Ability                     PRESSURE;
11.     BME280_Ability                     HUMIDITY;
12.     BME280_Sensor_Oversampling         TEMPERATURE_OVERSAMPLING;
13.     BME280_Sensor_Oversampling         PRESSURE_OVERSAMPLING;
14.     BME280_Sensor_Oversampling         HUMIDITY_OVERSAMPLING;
15.     BME280_IIR_Filter_Coefficient      IIR_FILTER_TIME_CONATANT;
16.     BME280_Inactive_Duration           INACTIVE_DURATION;
17.     uint8_t 						   PRESS_TEMP_CALIBRATION_DATA[PRESS_TEMP_CALIBRATION_DATA_BUFFER_SIZE];
18.     uint8_t 						   HUMIDITY_CALIBRATION_DATA[HUMIDITY_CALIBRATION_DATA_BUFFER_SIZE];
19.     int32_t 						   dig_t1;
20.     int32_t 						   dig_t2;
21.     int32_t 						   dig_t3;
22.     uint16_t 						   dig_p1;
23.     int16_t 						   dig_p2;
24.     int16_t 						   dig_p3;
25.     int16_t 						   dig_p4;
26.     int16_t							   dig_p5;
27.     int16_t 						   dig_p6;
28.     int16_t 						   dig_p7;
29.     int16_t 						   dig_p8;
30.     int16_t 						   dig_p9;
31.     int32_t 						   dig_h1;
32.     int32_t 						   dig_h2;
33.     int32_t 						   dig_h3;
34.     int32_t 						   dig_h4;
35.     int32_t 						   dig_h5;
36.     int32_t 						   dig_h6;
37.     int32_t 						   FINE_TEMP_RESOLUTIN;
38.     uint8_t 						   REGISTER_RAW_DATA_BUFFER[REGISTER_RAW_DATA_BYTE_QTY];
39.     uint32_t 						   REGISTER_RAW_PRESSURE;
40.     uint32_t 						   REGISTER_RAW_TEMPERATURE;
41.     uint32_t 						   REGISTER_RAW_HUMIDITY;
42.     double 							   COMPENSATED_TEMPERATURE;
43.     double 							   COMPENSATED_PRESSURE;
44.     double 							   ALTITUDE;
45.     double 					           COMPENSATED_HUMIDITY;
46. }GebraBit_BME280;
47.  

				
			

Declaration of functions

At the end of this file, all the functions for reading and writing in BME280 registers, sensor configuration and receiving data from the sensor are declared:

				
					 1. /********************************************************
 2.  *Declare Read&Write BME280 Register Values Functions *
 3.  ********************************************************/
 4. extern	uint8_t	GB_BME280_Read_Reg_Data ( uint8_t regAddr,uint8_t* data);
 5. extern	uint8_t GB_BME280_Read_Reg_Bits (uint8_t regAddr,uint8_t start_bit, uint8_t len, uint8_t* data);
 6. extern	uint8_t GB_BME280_Burst_Read(uint8_t regAddr,uint8_t *data, uint16_t byteQuantity);
 7. extern	uint8_t GB_BME280_Write_Reg_Data(uint8_t regAddr, uint8_t data);
 8. extern	uint8_t	GB_BME280_Write_Reg_Bits(uint8_t regAddr, uint8_t start_bit, uint8_t len, uint8_t data);
 9. extern	uint8_t GB_BME280_Burst_Write		( uint8_t regAddr,uint8_t *data, 	uint16_t byteQuantity);
10. /********************************************************
11.  *       Declare BME280 Configuration Functions       *
12.  ********************************************************/
13. extern void GB_BME280_Soft_Reset ( GebraBit_BME280 * BME280 );
14. extern void	GB_BME280_Get_Device_ID(GebraBit_BME280 * BME280);
15. extern void GB_BME280_Check_NVM_Data(GebraBit_BME280 * BME280 ) ;
16. extern void GB_BME280_Check_Conversion_Transferred_Register(GebraBit_BME280 * BME280 );
17. extern void GB_BME280_Turn_Humidity_OFF(GebraBit_BME280* BME280);
18. extern void GB_BME280_Humidity_OverSampling(GebraBit_BME280* BME280 ,BME280_Sensor_Oversampling hum_over);
19. extern void GB_BME280_Turn_Temperature_OFF(GebraBit_BME280* BME280);
20. extern void GB_BME280_Temperature_OverSampling(GebraBit_BME280* BME280 ,BME280_Sensor_Oversampling temp_over);
21. extern void GB_BME280_Turn_Pressure_OFF(GebraBit_BME280* BME280);
22. extern void GB_BME280_Pressure_OverSampling(GebraBit_BME280* BME280 ,BME280_Sensor_Oversampling press_over);
23. extern void GB_BME280_Power_Mode(GebraBit_BME280* BME280 ,BME280_Power_Mode pmode);
24. extern void GB_BME280_Inactive_Duration(GebraBit_BME280 * BME280 , BME280_Inactive_Duration dur ) ;
25. extern void GB_BME280_IIR_Filter_Coefficient (GebraBit_BME280 * BME280 , BME280_IIR_Filter_Coefficient filter);
26. extern void GB_BME280_Power_Mode(GebraBit_BME280* BME280 ,BME280_Power_Mode pmode);
27. extern void GB_BME280_Calculate_Calibration_Coefficients(GebraBit_BME280 * BME280) ;
28. extern void GB_BME280_Twos_Complement_Converter(int32_t *value, uint8_t length) ;
29. extern void GB_BME280_Compensate_Temperature(GebraBit_BME280 * BME280) ;
30. extern void GB_BME280_Compensate_Pressure(GebraBit_BME280 * BME280) ;
31. extern void GB_BME280_Compensate_Humidity(GebraBit_BME280 * BME280);
32.  
33. /********************************************************
34.  *          Declare BME280 DATA Functions               *
35.  ********************************************************/
36. extern void GB_BME280_Get_Register_Raw_Pressure_Temperature_Humidity(GebraBit_BME280 * BME280 );
37. extern void GB_BME280_Altitude(GebraBit_BME280 * BME280);
38. extern void GB_BME280_Get_Data(GebraBit_BME280 * BME280 );
39. /********************************************************
40.  *          Declare BME280 HIGH LEVEL Functions       *
41.  ********************************************************/
42. extern void GB_BME280_initialize( GebraBit_BME280 * BME280 );
43. extern void GB_BME280_Configuration(GebraBit_BME280 * BME280);
44.  

				
			

GebraBit_ BME280.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_BME280.c” library provided by GebraBit, we will examine the “main .c” file of the sample tutorial and view the output of the GebraBit_BME280 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_BME280.h” header has been added to access the GebraBit BME280 module required structures, Enums and functions. In the next part, a variable named BME280_Module of the GebraBit_BME280 structure type (this structure is in the GebraBit_BME280 header and is explained in the GebraBit_BME280 library description section) is defined for the configuration of the GebraBit BME280 module:  

				
					/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
GebraBit_BME280 BME280_ MODULE;
/* USER CODE END PTD */

				
			

In the next section of the written code, we set and configure the GebraBit BME280 module using the GB_BME280_initialize (&BME280_Module) and GB_BME280_Configuration(&BME280_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_BME280_initialize(&BME280_MODULE);
7.   GB_BME280_Configuration(&BME280_MODULE);
8.   /* USER CODE END 2 */

				
			

And finally, we read the data from the sensor and continuously receive the values of pressure, temperature, humidity, and altitude in the “while” part of the program:

				
					1.   /* Infinite loop */
 2.   /* USER CODE BEGIN WHILE */
 3.   while (1)
 4.   {
 5.     /* USER CODE END WHILE */
 6.  
 7.     /* USER CODE BEGIN 3 */
 8.     GB_BME280_Get_Data(&BME280_MODULE);
 9.   } 
10.   /* USER CODE END 3 */
11. } 

				
			

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_BME280.h"
 49. /* USER CODE END Includes */
 50.  
 51. /* Private typedef -----------------------------------------------------------*/
 52. /* USER CODE BEGIN PTD */
 53. GebraBit_BME280 BME280_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_BME280_initialize(&BME280_MODULE);
114. 	GB_BME280_Configuration(&BME280_MODULE);
115.   /* USER CODE END 2 */
116.  
117.   /* Infinite loop */
118.   /* USER CODE BEGIN WHILE */
119.   while (1)
120.   {
121.     /* USER CODE END WHILE */
122.  
123.     /* USER CODE BEGIN 3 */
124.     GB_BME280_Get_Data(&BME280_MODULE);
125.   } 
126.   /* USER CODE END 3 */
127. }
128.  
129. /**
130.   * @brief System Clock Configuration
131.   * @retval None
132.   */
133. void SystemClock_Config(void)
134. {
135.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
136.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
137.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
138.  
139.   /** Initializes the RCC Oscillators according to the specified parameters
140.   * in the RCC_OscInitTypeDef structure.
141.   */
142.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
143.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
144.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
145.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
146.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
147.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
148.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
149.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
150.   {
151.     Error_Handler();
152.   }
153.  
154.   /** Initializes the CPU, AHB and APB buses clocks
155.   */
156.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
157.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
158.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
159.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
160.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
161.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
162.  
163.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
164.   {
165.     Error_Handler();
166.   }
167.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
168.   PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
169.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
170.   {
171.     Error_Handler();
172.   }
173. }
174.  
175. /* USER CODE BEGIN 4 */
176.  
177. /* USER CODE END 4 */
178.  
179. /**
180.   * @brief  This function is executed in case of error occurrence.
181.   * @retval None
182.   */
183. void Error_Handler(void)
184. {
185.   /* USER CODE BEGIN Error_Handler_Debug */
186.   /* User can add his own implementation to report the HAL error return state */
187.   __disable_irq();
188.   while (1)
189.   {
190.   }
191.   /* USER CODE END Error_Handler_Debug */
192. }
193.  
194. #ifdef  USE_FULL_ASSERT
195. /**
196.   * @brief  Reports the name of the source file and the source line number
197.   *         where the assert_param error has occurred.
198.   * @param  file: pointer to the source file name
199.   * @param  line: assert_param error line source number
200.   * @retval None
201.   */
202. void assert_failed(uint8_t *file, uint32_t line)
203. {
204.   /* USER CODE BEGIN 6 */
205.   /* User can add his own implementation to report the file name and line number,
206.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
207.   /* USER CODE END 6 */
208. }
209. #endif /* USE_FULL_ASSERT */
210.  

				
			

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 BME280 modules, because they receive their supply voltage directly from the STLINK V2 programmer.

Finally, enter the “Debug” mode and by adding the “BME280_Module” to the “watch” window and running the program, we can see the changes in pressure, temperature, and height of the GebraBit BME280 module:

In the following, you can download the “GebraBit BME280 module setup project” using the GebraBit STM32F303 module in the Keil environment, the “STM32CubeMX file”, the schematic of the modules and the “BME280 datasheet”.

Program output video

این مقاله را با دوستانتان به اشتراک بگذارید!

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart
Start typing to see posts you are looking for.

Sign in

No account yet?