GebraBit

DPS310 Sensor Project With STM32F303 Microcontroller

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

DPS310 gebrabit project

DPS310 Sensor Project With STM32F303 Microcontroller

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

What's the purpose of this project?

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

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

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

DPS310_FIFO_Status Enum

The status of the sensor FIFO being full or empty is defined in this enum:

				
					1. typedef enum FIFO_Status
2. {  
3.  FIFO_EMPTY    = 0x01 ,
4.  FIFO_FULL     = 0x02    						
5. }DPS310_FIFO_Status;

				
			

DPS310_Interrupt Enum

The sensor interruption source is defined in this enum:

				
					1. typedef enum Interrupt
 2. {
 3.  PRESS_INTERRUPT     	        = 1 ,                  
 4.  TEMP_INTERRUPT                 = 2 ,	
 5.  PRESS_TEMP_INTERRUPT           = 3 ,	
 6.  FIFO_FULL_INTERRUPT            = 4 ,						
 7.  PRESS_FIFO_FULL_INTERRUPT      = 5 ,                  
 8.  TEMP_FIFO_FULL_INTERRUPT       = 6 ,
 9.  PRESS_TEMP_FIFO_FULL_INTERRUPT = 7
10. } DPS310_Interrupt; 

				
			

DPS310_Interrupt_Status Enum

The occurred interrupt type is defined in this enum:

				
					1. typedef enum Interrupt_Status
2. {  
3.  PRESSURE_MESUREMENT_INTERRUPT      = 0x01 ,                   
4.  TEMPERATURE_MESUREMENT_INTERRUPT   = 0x02 ,                
5.  FIFO_IS_FULL_INTERRUPT             = 0x04                      
6. }DPS310_Interrupt_Status;

				
			

DPS310_Measurement_Mode Enum

By using this Enum, the sensor measurement modes are determined:

				
					1. typedef enum Measurement_Mode
 2. {
 3. STANDBY	                                  = 0 ,			
 4. COMMAND_PRESSURE	                          = 1 , 
 5. COMMAND_TEMPERATURE 	                      = 2 ,	
 6. CONTINUOUS_BACKGROUND_PRESSURE             = 5 ,
 7. CONTINUOUS_BACKGROUND_TEMPERATURE          = 6 ,
 8. CONTINUOUS_BACKGROUND_PRESSURE_TEMPERATURE = 7
 9. } DPS310_Measurement_Mode;

				
			

DPS310_Oversampling Enum

By using this Enum, the number of the sensor oversampling is determined:

				
					1. typedef enum Oversampling
 2. {
 3. 	  SINGLE     = 0 ,							
 4. 	 _2_TIMES    = 1 , 							
 5. 	 _4_TIMES    = 2 ,							 
 6. 	 _8_TIMES    = 3 ,                   
 7. 	 _16_TIMES   = 4 ,							
 8. 	 _32_TIMES   = 5 ,		                    
 9. 	 _64_TIMES   = 6 ,
10. 	 _128_TIMES  = 7 ,
11. } DPS310_Oversampling;
12.  

				
			

DPS310_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. }DPS310_Ability;

				
			

DPS310_Measurement_Rate Enum

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

				
					1. typedef enum Measurement_Rate
 2. {
 3. 	 _1_PER_SECOND         = 0 ,                  
 4. 	 _2_PER_SECOND         = 1 ,									
 5. 	 _4_PER_SECOND         = 2 ,									
 6. 	 _8_PER_SECOND         = 3 ,
 7. 	 _16_PER_SECOND        = 4 ,                  
 8. 	 _32_PER_SECOND        = 5 ,									
 9. 	 _64_PER_SECOND        = 6 ,									
10. 	 _128_PER_SECOND       = 7 
11. } DPS310_Measurement_Rate;

				
			

DPS310_Scale_Factor Enum

The values of this enum show the sensor SCALE FACTOR:

				
					1. typedef enum Scale_Factor
 2. {
 3. 	 SF_524288_KP_KT       = 0 ,                  
 4. 	 SF_1572864_KP_KT      = 1 ,					
 5. 	 SF_3670016_KP_KT      = 2 ,					
 6. 	 SF_7864320_KP_KT      = 3 ,
 7. 	 SF_253952_KP_KT       = 4 ,                  
 8. 	 SF_516096_KP_KT       = 5 ,					
 9. 	 SF_1040384_KP_KT      = 6 ,					
10. 	 SF_2088960_KP_KT      = 7 
11. } DPS310_Scale_Factor;

				
			

DPS310_Bit_Shift Enum

The values of this enum are used to change the values in the data registers:

				
					1. typedef enum Bit_Shift
2. { 
3.   NO_SHIFT = 0 ,	                                 
4.   SHIFT_BIT                     						
5. }DPS310_Bit_Shift;

				
			

DPS310_Preparation Enum

The values of this enum show whether the sensor data is ready or not:

				
					1. typedef enum Preparation
2. {  
3. IS_NOT_Ready = 0 ,                      
4. IS_Ready     = 1 ,
5. TEMPERATURE_PRESSURE_IS_READY = 3
6. }DPS310_Preparation;

				
			

DPS310_Coefficient_Status Enum

The values of this enum show whether the calibration coefficient data is ready or not:

				
					1. typedef enum Coefficient_Status
2. {  
3. COEFFICIENT_ARE_NOT_AVAILABLE = 0 ,                      
4. COEFFICIENT_ARE_AVAILABLE     
5. }DPS310_Coefficient_Status; 

				
			

DPS310_Sensor_Initialization Enum

The values of this enum indicate whether the sensor is initialized or not:

				
					1. typedef enum Sensor_Initialization 
2. {  
3. INITIALIZATION_NOT_COMPLETE = 0,                      
4. INITIALIZATION_COMPLETE     
5. }DPS310_Sensor_Initialization;

				
			

DPS310_ 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. } DPS310_Get_DATA;

				
			

DPS310_Reset_Status Enum

The values of this enum specify whether the sensor is reset or not:

				
					1. typedef enum 
2. {  
3. DONE     = 0 ,                      
4. FAILED   = 1    
5. }DPS310_Reset_Status;             

				
			

DPS310_FIFO_Ability Enum

To enable or disable FIFO, the values of this enum are used:

				
					1. typedef enum FIFO_Ability
2. {  
3. 	FIFO_DISABLE = 0 ,                      
4. 	FIFO_ENABLE     
5. } DPS310_FIFO_Ability;

				
			

DPS310_Temperature_Sensor Enum

The values of this enum are used to choose whether to use the internal or external temperature sensor:

				
					1. typedef enum Temperature_Sensor
2. {  
3. 	INTERNAL_SENSOR = 0 ,                      
4. 	EXTERNAL_SENSOR     
5. } DPS310_Temperature_Sensor;

				
			

DPS310 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.

Declaration of functions

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

				
					/********************************************************
 *Declare Read&Write DPS310 Register Values Functions *
 ********************************************************/
 1. extern	uint8_t	GB_DPS310_Read_Reg_Data ( uint8_t regAddr,uint8_t* data);
 2. extern	uint8_t GB_DPS310_Read_Reg_Bits (uint8_t regAddr,uint8_t start_bit, uint8_t len, uint8_t* data);
 3. extern	uint8_t GB_DPS310_Burst_Read(uint8_t regAddr,uint8_t *data, uint16_t byteQuantity);
 4. extern	uint8_t GB_DPS310_Write_Reg_Data(uint8_t regAddr, uint8_t data);
 5. extern	uint8_t	GB_DPS310_Write_Reg_Bits(uint8_t regAddr, uint8_t start_bit, uint8_t len, uint8_t data);
 6. extern	uint8_t GB_DPS310_Burst_Write		( uint8_t regAddr,uint8_t *data, 	uint16_t byteQuantity);
 7. /********************************************************
 8.  *       Declare DPS310 Configuration Functions       *
 9.  ********************************************************/
10. extern void GB_DPS310_Pressure_Measurement_Rate(GebraBit_DPS310 * DPS310 , DPS310_Measurement_Rate rate );
11. extern void GB_DPS310_Pressure_OverSampling(GebraBit_DPS310 * DPS310 , DPS310_Oversampling oversmp );
12. extern void GB_DPS310_Temperature_Measurement_Rate(GebraBit_DPS310 * DPS310 , DPS310_Measurement_Rate rate );
13. extern void GB_DPS310_Temperature_OverSampling(GebraBit_DPS310 * DPS310 , DPS310_Oversampling oversmp );
14. extern void GB_DPS310_Temperature(GebraBit_DPS310 * DPS310 , DPS310_Temperature_Sensor tmp );
15. extern void GB_DPS310_Check_Coefficient(GebraBit_DPS310 * DPS310);
16. extern void GB_DPS310_Sensor_Initialization(GebraBit_DPS310 * DPS310);
17. extern void GB_DPS310_Check_Temperature_Data(GebraBit_DPS310 * DPS310);
18. extern void GB_DPS310_Check_Pressure_Data(GebraBit_DPS310 * DPS310);
19. extern void GB_DPS310_Check_Temperature_Pressure_Data(GebraBit_DPS310 * DPS310);
20. extern void GB_DPS310_Measurement_Mode(GebraBit_DPS310 * DPS310 , DPS310_Measurement_Mode meas);
21. extern void GB_DPS310_Temperature_Result_BitShift(GebraBit_DPS310 * DPS310 , DPS310_Bit_Shift shift);
22. extern void GB_DPS310_Pressure_Result_BitShift(GebraBit_DPS310 * DPS310 , DPS310_Bit_Shift shift);
23. extern void GB_DPS310_Interrupt(GebraBit_DPS310 * DPS310 , DPS310_Interrupt intrupt);
24. extern void GB_DPS310_Check_Interrupt_Status(GebraBit_DPS310 * DPS310 );
25. extern void GB_DPS310_Soft_Reset(GebraBit_DPS310 * DPS310 );
26. extern void GB_DPS310_Product_ID(GebraBit_DPS310 * DPS310 );
27. extern void GB_DPS310_Revision_ID(GebraBit_DPS310 * DPS310 );
28. extern void GB_DPS310_Check_Temperature_Coefficient_Source(GebraBit_DPS310 * DPS310 );
29. /********************************************************
30.  *          Declare DPS310 FIFO Functions             *
31.  ********************************************************/
32. extern void GB_DPS310_FIFO(GebraBit_DPS310 * DPS310 , DPS310_Ability fifo);
33. extern void GB_DPS310_FIFO_Configuration ( GebraBit_DPS310 * DPS310 , DPS310_FIFO_Ability fifo  );
34. extern void GB_DPS310_Check_FIFO_Status(GebraBit_DPS310 * DPS310 );
35. extern void GB_DPS310_FIFO_Flush(GebraBit_DPS310 * DPS310 );
36. extern void GB_DPS310_Read_FIFO(GebraBit_DPS310 * DPS310);
37. extern void GB_DPS310_FIFO_Data_Partition_Pressure_Temperature(GebraBit_DPS310 * DPS310);
38. /********************************************************
39.  *          Declare DPS310 DATA Functions             *
40.  ********************************************************/
41. extern void GB_DPS310_Twos_Complement_Converter(int32_t *value, uint8_t length);
42. extern void GB_DPS310_Calculate_Calibration_Coefficients(GebraBit_DPS310 * DPS310);
43. extern void GB_DPS310_Get_Register_Raw_Pressure_Temperature(GebraBit_DPS310 * DPS310 );
44. extern void GB_DPS310_Calculate_Compensated_Pressure(GebraBit_DPS310 * DPS310);
45. extern void GB_DPS310_Calculate_Compensated_Temperature(GebraBit_DPS310 * DPS310)	;
46. extern void GB_DPS310_Get_Data(GebraBit_DPS310 * DPS310 , DPS310_Get_DATA get_data) ;
47. extern void GB_DPS310_Temperature_Correction(GebraBit_DPS310 * DPS310);
48. extern void GB_DPS310_Altitude(GebraBit_DPS310 * DPS310);
49. ///********************************************************
50. // *          Declare DPS310 HIGH LEVEL Functions       *
51. // ********************************************************/
52. extern void GB_DPS310_Initialize( GebraBit_DPS310 * DPS310 );
53. extern void GB_DPS310_Configuration(GebraBit_DPS310 * DPS310, DPS310_FIFO_Ability fifo);
54.  

				
			

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

				
					/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
GebraBit_DPS310 DPS310_ MODULE;
/* USER CODE END PTD */

				
			

In the next section of the written code, we set and configure the GebraBit DPS310 module using the GB_ DPS310_initialize (&DPS310_Module) and GB_ DPS310_Configuration (&DPS310_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_DPS310_Initialize( &DPS310_Module );
 7.   //GB_DPS310_Configuration(&DPS310_Module, FIFO_DISABLE) ;
 8.   GB_DPS310_Configuration(&DPS310_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_DPS310_Get_Data(&DPS310_Module, FROM_FIFO);
 6. 		//GB_DPS310_Get_Data(&DPS310_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.   ******************************************************************************
 27.   * @attention
 28.   *
 29.   * Copyright (c) 2023 STMicroelectronics.
 30.   * All rights reserved.
 31.   *
 32.   * This software is licensed under terms that can be found in the LICENSE file
 33.   * in the root directory of this software component.
 34.   * If no LICENSE file comes with this software, it is provided AS-IS.
 35.   *
 36.   ******************************************************************************
 37.   */
 38. /* USER CODE END Header */
 39. /* Includes ------------------------------------------------------------------*/
 40. #include "main.h"
 41. #include "i2c.h"
 42. #include "spi.h"
 43. #include "gpio.h"
 44.  
 45. /* Private includes ----------------------------------------------------------*/
 46. /* USER CODE BEGIN Includes */
 47. #include "GebraBit_DPS310.h"
 48. /* USER CODE END Includes */
 49.  
 50. /* Private typedef -----------------------------------------------------------*/
 51. /* USER CODE BEGIN PTD */
 52. GebraBit_DPS310  DPS310_MODULE;
 53. /* USER CODE END PTD */
 54.  
 55. /* Private define ------------------------------------------------------------*/
 56. /* USER CODE BEGIN PD */
 57. /* USER CODE END PD */
 58.  
 59. /* Private macro -------------------------------------------------------------*/
 60. /* USER CODE BEGIN PM */
 61.  
 62. /* USER CODE END PM */
 63.  
 64. /* Private variables ---------------------------------------------------------*/
 65.  
 66. /* USER CODE BEGIN PV */
 67.  
 68. /* USER CODE END PV */
 69.  
 70. /* Private function prototypes -----------------------------------------------*/
 71. void SystemClock_Config(void);
 72. /* USER CODE BEGIN PFP */
 73.  
 74. /* USER CODE END PFP */
 75.  
 76. /* Private user code ---------------------------------------------------------*/
 77. /* USER CODE BEGIN 0 */
 78.  
 79. /* USER CODE END 0 */
 80.  
 81. /**
 82.   * @brief  The application entry point.
 83.   * @retval int
 84.   */
 85. int main(void)
 86. {
 87.   /* USER CODE BEGIN 1 */
 88.  
 89.   /* USER CODE END 1 */
 90.  
 91.   /* MCU Configuration--------------------------------------------------------*/
 92.  
 93.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 94.   HAL_Init();
 95.  
 96.   /* USER CODE BEGIN Init */
 97.  
 98.   /* USER CODE END Init */
 99.  
100.   /* Configure the system clock */
101.   SystemClock_Config();
102.  
103.   /* USER CODE BEGIN SysInit */
104.  
105.   /* USER CODE END SysInit */
106.  
107.   /* Initialize all configured peripherals */
108.   MX_GPIO_Init();
109.   MX_I2C1_Init();
110.   MX_SPI1_Init();
111.   /* USER CODE BEGIN 2 */
112.  
113.   /* USER CODE END 2 */
114.  
115.   /* Infinite loop */
116.   /* USER CODE BEGIN WHILE */
117.   GB_DPS310_Initialize( &DPS310_MODULE);
118.   GB_DPS310_Configuration( &DPS310_MODULE , FIFO_DISABLE);
119.   //GB_DPS310_Configuration( &DPS310_MODULE , FIFO_ENABLE);
120.   while (1)
121.   {
122. 		//GB_DPS310_Get_Data(&DPS310_MODULE, FROM_FIFO);
123. 		GB_DPS310_Get_Data(&DPS310_MODULE, FROM_REGISTER);
124.     /* USER CODE END WHILE */
125.  
126.     /* USER CODE BEGIN 3 */
127.  
128.  }
129.   /* USER CODE END 3 */
130. }
131.  
132. /**
133.   * @brief System Clock Configuration
134.   * @retval None
135.   */
136. void SystemClock_Config(void)
137. {
138.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
139.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
140.   RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
141.  
142.   /** Initializes the RCC Oscillators according to the specified parameters
143.   * in the RCC_OscInitTypeDef structure.
144.   */
145.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
146.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
147.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
148.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
149.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
150.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
151.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
152.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
153.   {
154.     Error_Handler();
155.   }
156.  
157.   /** Initializes the CPU, AHB and APB buses clocks
158.   */
159.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
160.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
161.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
162.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
163.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
164.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
165.  
166.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
167.   {
168.     Error_Handler();
169.   }
170.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
171.   PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
172.   if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
173.   {
174.     Error_Handler();
175.   }
176. }
177.  
178. /* USER CODE BEGIN 4 */
179.  
180. /* USER CODE END 4 */
181.  
182. /**
183.   * @brief  This function is executed in case of error occurrence.
184.   * @retval None
185.   */
186. void Error_Handler(void)
187. {
188.   /* USER CODE BEGIN Error_Handler_Debug */
189.   /* User can add his own implementation to report the HAL error return state */
190.   __disable_irq();
191.   while (1)
192.   {
193.   }
194.   /* USER CODE END Error_Handler_Debug */
195. }
196.  
197. #ifdef  USE_FULL_ASSERT
198. /**
199.   * @brief  Reports the name of the source file and the source line number
200.   *         where the assert_param error has occurred.
201.   * @param  file: pointer to the source file name
202.   * @param  line: assert_param error line source number
203.   * @retval None
204.   */
205. void assert_failed(uint8_t *file, uint32_t line)
206. {
207.   /* USER CODE BEGIN 6 */
208.   /* User can add his own implementation to report the file name and line number,
209.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
210.   /* USER CODE END 6 */
211. }
212. #endif /* USE_FULL_ASSERT */
213.  

				
			

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

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

Receiving sensor data directly from data registers:

Receiving sensor data from FIFO:

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?