What's the purpose of this project?
In this project, we are going to use the GB638EN module to set up the ICP20100 temperature and humidity sensor with the STM32F microcontroller through the SPI protocol. Since you probably don’t know the GB638EN module, it is appropriate to say that GB638EN is a module that includes the ICP20100 sensor and other necessary components, designed and produced by the GebraBit team in the form of an integrated kit for your convenience.
What are we going to learn in this tutorial?
In this tutorial, in addition to setting up and using the ICP20100 sensor, you will get to know all the ICP20100 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 GB638EN 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
|
Are you ready?? so let’s start !!
First of all, we must select the SPI communication protocol using the jumpers on the board and then place the GebraBit ICP20100 module Pin to Pin on the GebraBit STM32F303 module as shown below:
Note: The above picture is intended only to show how the GebraBit ICP20100 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 and acceleration in real time in the “Watch1” window of the Keil compiler in “Debug Session” mode.
Now, we need to prepare the STM32 microcontroller to set up the desired sensor module. How?? Let me tell you! come with me!
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 ICP20100 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 ICP20100 library and driver (provided by GebraBit).
You can download the “STM32Cube MX”, “ICP20100 library”, “driver” and KEIL project at the end of this tutorial.
ICP20100 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 ICP20100.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 ICP20100 sensor and the configurations related to each of the ICP20100 sensor internal blocks are defined in the form of a “STRUCT” with the name GebraBit_ ICP20100. Finally, in the Debug Session environment, all the configurations related to each block can be seen in real time.
ICP20100_Measurement_Configuration Enum
The sensor working modes are defined in this enum:
1. typedef enum measurement_configuration
2. {
3. ICP20100_OP_MODE0 = 0 ,
4. ICP20100_OP_MODE1 ,
5. ICP20100_OP_MODE2 ,
6. ICP20100_OP_MODE3 ,
7. ICP20100_OP_MODE4 ,
8. ICP20100_OP_MODE_RES
9. }ICP20100_Measurement_Configuration;
ICP20100_Forced_Measure_Trig Enum
This enum is used to select the “STAND BY” mode or “forced measurement” mode:
1. typedef enum forced_measure_trig {
2. ICP20100_FORCE_MEAS_STANDBY = 0,
3. ICP20100_FORCE_MEAS_TRIGGER = 1
4. }ICP20100_Forced_Measure_Trig;
ICP20100_Measure_Mode Enum
This enum is used to select “Continuous” or “Standby” working mode of the sensor:
1. typedef enum measure_mode
2. {
3. ICP20100_MEAS_MODE_FORCED_TRIGGER = 0,
4. ICP20100_MEAS_MODE_CONTINUOUS = 1
5. }ICP20100_Measure_Mode;
ICP20100_Power_Mode Enum
This enum is used to select the sensor “Power” mode:
1. typedef enum power_mode
2. {
3. ICP20100_POWER_NORMAL_MODE = 0,
4. ICP20100_POWER_ACTIVE_MODE = 1
5. }ICP20100_Power_Mode;
ICP20100_FIFO_Readout_Mode Enum
This enum is used to set how to read data from the FIFO of the sensor:
1. typedef enum FIFO_readout_mode
2. {
3. ICP20100_FIFO_READOUT_MODE_PRES_TEMP = 0,
4. ICP20100_FIFO_READOUT_MODE_TEMP_ONLY = 1,
5. ICP20100_FIFO_READOUT_MODE_TEMP_PRES = 2,
6. ICP20100_FIFO_READOUT_MODE_PRES_ONLY = 3
7. }ICP20100_FIFO_Readout_Mode;
ICP20100_Interrupt_Source Enum
Each of the values of this Enum indicates the interrupt source:
1. typedef enum interrupt_source
2. {
3. FIFO_OVERFLOW_INT = 1 ,
4. FIFO_UNDERFLOW_INT = 2 ,
5. FIFO_WMK_HIGH_INT = 4 ,
6. FIFO_WMK_LOW_INT = 8 ,
7. PRESS_ABS_INT = 32 ,
8. PRESS_DELTA_INT = 64 ,
9. ALL_INT_SOURCE = 111
10. }ICP20100_Interrupt_Source;
ICP20100_Interrupt_Mask Enum
We determine the interruption sources using the values of this enum:
1. typedef enum interrupt_mask
2. {
3. FIFO_OVERFLOW_NOT_MASK = 0xEE ,
4. FIFO_UNDERFLOW_NOT_MASK = 0xED ,
5. FIFO_WMK_HIGH_NOT_MASK = 0xEB ,
6. FIFO_WMK_LOW_NOT_MASK = 0xE7 ,
7. PRESS_ABS_NOT_MASK = 0xCF ,
8. PRESS_DELTA_NOT_MASK = 0xAF ,
9. ALL_INT_MASK = 0xEF ,
10. ALL_INT_NOT_MASK = 0
11. }ICP20100_Interrupt_Mask;
ICP20100_FIFO_Empty_Flag Enum
The values of this enum are used for FIFO empty indication:
1. typedef enum FIFO_empty_flag
2. {
3. NOT_EMPTY_FIFO = 0,
4. FIFO_IS_EMPTY = 1
5. }ICP20100_FIFO_Empty_Flag;
ICP20100_FIFO_Full_Flag Enum
The values of this enum are used for FIFO full indication:
1. typedef enum FIFO_full_flag
2. {
3. NOT_FULL_FIFO = 0,
4. FIFO_IS_FULL = 1
5. }ICP20100_FIFO_Full_Flag;
ICP20100_FIFO_Fill_Level Enum
Using the values of this enum, the FIFO Fill level is determined:
1. typedef enum FIFO_fill_level
2. {
3. ICP20100_FIFO_FILL_LEVEL_Empty = 0, /* 00000: Empty */
4. ICP20100_FIFO_FILL_LEVEL_1_16 = 1, /* 00001: 1/16 full */
5. ICP20100_FIFO_FILL_LEVEL_2_16 = 2, /* 00010: 2/16 full */
6. ICP20100_FIFO_FILL_LEVEL_3_16 = 3, /* 00011: 3/16 full */
7. ICP20100_FIFO_FILL_LEVEL_4_16 = 4, /* 00100: 4/16 full */
8. ICP20100_FIFO_FILL_LEVEL_5_16 = 5, /* 00101: 5/16 full */
9. ICP20100_FIFO_FILL_LEVEL_6_16 = 6, /* 00110: 6/16 full */
10. ICP20100_FIFO_FILL_LEVEL_7_16 = 7, /* 00111: 7/16 full */
11. ICP20100_FIFO_FILL_LEVEL_8_16 = 8, /* 01000: 8/16 full */
12. ICP20100_FIFO_FILL_LEVEL_9_16 = 9, /* 01001: 9/16 full */
13. ICP20100_FIFO_FILL_LEVEL_10_16 = 10, /* 01010: 10/16 full */
14. ICP20100_FIFO_FILL_LEVEL_11_16 = 11, /* 01011: 11/16 full */
15. ICP20100_FIFO_FILL_LEVEL_12_16 = 12, /* 01100: 12/16 full */
16. ICP20100_FIFO_FILL_LEVEL_13_16 = 13, /* 01101: 13/16 full */
17. ICP20100_FIFO_FILL_LEVEL_14_16 = 14, /* 01110: 14/16 full */
18. ICP20100_FIFO_FILL_LEVEL_15_16 = 15, /* 01111: 15/16 full */
19. ICP20100_FIFO_FILL_LEVEL_FULL = 16 /* 10000: 16/16 full */
20. }ICP20100_FIFO_Fill_Level;
21.
ICP20100_Mode_Sync_Status Enum
The sensor Synchronization with CLK is set using the values of this enum:
1. typedef enum mode_sync_status
2. {
3. NOT_SYNC_TO_CLK = 0,
4. SYNC_TO_CLK = 1
5. }ICP20100_Mode_Sync_Status;
ICP20100_Device_Version Enum
The values of this enum define the version of the sensor:
1. typedef enum device_version
2. {
3. VERSION_A = 0x00,
4. VERSION_B = 0xB2
5. }ICP20100_Device_Version;
ICP20100_OTP_Config Enum
The values of this enum show the sensor need for OTP settings:
1. typedef enum otp_config
2. {
3. NEED_OTP_CONFIG = 0,
4. NO_NEED_OTP_CONFIG = 1
5. }ICP20100_OTP_Config;
GebraBit_ ICP20100 structure
Declaration of functions
At the end of this file, all the functions for reading and writing in ICP20100 registers, sensor configuration, FIFO and receiving data from the sensor are declared:
1. /********************************************************
2. *Declare Read&Write ICP20100 Register Vlalues Functions*
3. ********************************************************/
4. extern uint8_t GB_ICP20100_Read_Reg_Data (uint8_t regAddr, uint8_t* data);
5. extern uint8_t GB_ICP20100_Burst_Read (uint8_t regAddr,uint8_t *data, uint8_t bytepcs);
6. extern uint8_t GB_ICP20100_Read_Reg_Bits (uint8_t regAddr, uint8_t start_bit, uint8_t len, uint8_t* data);
7. extern uint8_t GB_ICP20100_Write_Reg_Data (uint8_t regAddr, uint8_t data);
8. extern uint8_t GB_ICP20100_Write_Reg_Bits (uint8_t regAddr, uint8_t start_bit, uint8_t len, uint8_t data);
9. /********************************************************
10. * Declare ICP20100 Configuration Functions *
11. ********************************************************/
12. extern void GB_ICP20100_Get_Device_ID (GebraBit_ICP20100 * icp20100);
13. extern void GB_ICP20100_Get_Device_Version (GebraBit_ICP20100 * icp20100);
14. extern void GB_ICP20100_Read_Mode_Select (GebraBit_ICP20100 * icp20100);
15. extern void GB_ICP20100_Write_Mode_Select (GebraBit_ICP20100 * icp20100);
16. extern void GB_ICP20100_Read_Meas_Config (GebraBit_ICP20100 * icp20100);
17. extern void GB_ICP20100_Write_Meas_Config (GebraBit_ICP20100 * icp20100);
18. extern void GB_ICP20100_Read_Forced_Measure_Trig (GebraBit_ICP20100 * icp20100);
19. extern void GB_ICP20100_Write_Forced_Measure_Trig (GebraBit_ICP20100 * icp20100);
20. extern void GB_ICP20100_Read_Measure_Mode (GebraBit_ICP20100 * icp20100);
21. extern void GB_ICP20100_Write_Measure_Mode (GebraBit_ICP20100 * icp20100);
22. extern void GB_ICP20100_Read_Power_Mode (GebraBit_ICP20100 * icp20100);
23. extern void GB_ICP20100_Write_Power_Mode (GebraBit_ICP20100 * icp20100);
24. extern void GB_ICP20100_Read_PRESS_ABS (GebraBit_ICP20100 * icp20100);
25. extern void GB_ICP20100_Write_PRESS_ABS (GebraBit_ICP20100 * icp20100);
26. extern void GB_ICP20100_Read_PRESS_DELTA (GebraBit_ICP20100 * icp20100);
27. extern void GB_ICP20100_Write_PRESS_DELTA (GebraBit_ICP20100 * icp20100);
28. extern void GB_ICP20100_MODE_SYNC_STATUS_Check (GebraBit_ICP20100 * icp20100);
29. /********************************************************
30. * Declare ICP20100 Interrupt Functions *
31. ********************************************************/
32. extern void GB_ICP20100_Get_Interrupt_Triggered_Source (GebraBit_ICP20100 * icp20100);
33. extern void GB_ICP20100_Write_Interrupt_Status (GebraBit_ICP20100 * icp20100);
34. extern void GB_ICP20100_Clear_Interrupt_Source_Bit (GebraBit_ICP20100 * icp20100);
35. extern void GB_ICP20100_Read_Interrupt_Mask (GebraBit_ICP20100 * icp20100);
36. extern void GB_ICP20100_Write_Interrupt_Mask (GebraBit_ICP20100 * icp20100);
37. extern void GB_ICP20100_Mask_All_Interrupt (GebraBit_ICP20100 * icp20100);
38. extern void GB_ICP20100_NOT_Mask_Source_Interrupt (GebraBit_ICP20100 * icp20100);
39. /********************************************************
40. * Declare ICP20100 FIFO Functions *
41. ********************************************************/
42. extern void GB_ICP20100_Read_FIFO (GebraBit_ICP20100 * icp20100);
43. extern void GB_ICP20100_Read_FIFO_Readout_Mode (GebraBit_ICP20100 * icp20100);
44. extern void GB_ICP20100_Write_FIFO_Readout_Mode (GebraBit_ICP20100 * icp20100);
45. extern void GB_ICP20100_Read_FIFO_Congig (GebraBit_ICP20100 * icp20100);
46. extern void GB_ICP20100_Write_FIFO_Congig (GebraBit_ICP20100 * icp20100);
47. extern void GB_ICP20100_Read_FIFO_WM_HIGH (GebraBit_ICP20100 * icp20100);
48. extern void GB_ICP20100_Read_FIFO_WM_LOW (GebraBit_ICP20100 * icp20100);
49. extern void GB_ICP20100_Write_FIFO_WM_HIGH (GebraBit_ICP20100 * icp20100);
50. extern void GB_ICP20100_Write_FIFO_WM_LOW (GebraBit_ICP20100 * icp20100);
51. extern void GB_ICP20100_Read_FIFO_Fill (GebraBit_ICP20100 * icp20100);
52. extern void GB_ICP20100_Write_FIFO_Fill (GebraBit_ICP20100 * icp20100);
53. extern void GB_ICP20100_FIFO_Empty_Check (GebraBit_ICP20100 * icp20100);
54. extern void GB_ICP20100_FIFO_Full_Check (GebraBit_ICP20100 * icp20100);
55. extern void GB_ICP20100_FIFO_FILL_LEVEL (GebraBit_ICP20100 * icp20100);
56. extern void GB_ICP20100_FIFO_Flush (void);
57. /********************************************************
58. * Declare ICP20100 High Level Functions *
59. ********************************************************/
60. extern void GB_ICP20100_OTP_Bootup_Check (GebraBit_ICP20100 * icp20100);
61. extern void GB_ICP20100_Soft_Reset (GebraBit_ICP20100 * icp20100);
62. extern void GB_ICP20100_To_Standby (GebraBit_ICP20100 * icp20100);
63. extern void GB_ICP20100_Config (GebraBit_ICP20100 * icp20100);
64. extern void GB_ICP20100_Get_FIFO_Data (GebraBit_ICP20100 * icp20100);
65. extern void GB_ICP20100_Raw_Data_Partition (GebraBit_ICP20100 * icp20100);
66. extern void GB_ICP20100_Valid_Temp_Press_Data (GebraBit_ICP20100 * icp20100);
GebraBit_ ICP20100.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_ ICP20100.c” library provided by GebraBit, we will examine the “main .c” file of the sample tutorial and view the output of the GebraBit_ICP20100 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_ ICP20100.h” header has been added to access the structures and functions required by the GebraBit ICP20100 module. In the next part, a variable named ICP20100_Module of the GebraBit_ ICP20100 structure type (this structure is in the GebraBit_ ICP20100 header and is explained in the GebraBit_ ICP20100 library description section) is defined for the configuration of the GebraBit ICP20100 module:
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
GebraBit_ICP20100 ICP20100_Module;
/* USER CODE END PTD */
In the next part of the written code, after checking the OTP and RESET of the sensor software, the configuration and settings of the GebraBit ICP20100 module have been done using the ICP20100_Module structure. Finally, by referencing the ICP20100_Module structure to the argument of the GB_ICP20100_Config function, the GebraBit ICP20100 module will be configured:
1. /* USER CODE BEGIN 2 */
2. GB_ICP20100_OTP_Bootup_Check(&ICP20100_Module);
3. GB_ICP20100_Soft_Reset (&ICP20100_Module);
4. ICP20100_Module.MEAS_CONFIG = ICP20100_OP_MODE2 ;
5. ICP20100_Module.FORCED_MEAS_TRIGGER = ICP20100_FORCE_MEAS_STANDBY ;
6. ICP20100_Module.MEAS_MODE = ICP20100_MEAS_MODE_CONTINUOUS ;
7. ICP20100_Module.POWER_MODE = ICP20100_POWER_NORMAL_MODE ;
8. ICP20100_Module.FIFO_READOUT_MODE = ICP20100_FIFO_READOUT_MODE_PRES_TEMP ;
9. ICP20100_Module.INTERUPT_MASK = FIFO_WMK_HIGH_NOT_MASK ;
10. ICP20100_Module.PRESS_ABS = 24109;
11. ICP20100_Module.PRESS_DELTA = 31062 ;
12. ICP20100_Module.FIFO_WM_HIGH = 10 ;
13. ICP20100_Module.FIFO_WM_LOW = 4 ;
14. ICP20100_Module.FIFO_Packet_Qty = 10 ;
15.GB_ICP20100_Config(&ICP20100_Module);
16. /* USER CODE END 2 */
17. /* Infinite loop */
18. /* USER CODE BEGIN WHILE */
19. GB_ICP20100_Read_Mode_Select(&ICP20100_Module);
20. GB_ICP20100_Read_Interrupt_Mask(&ICP20100_Module);
21. GB_ICP20100_Read_FIFO_Congig(&ICP20100_Module);
22. GB_ICP20100_Read_FIFO_Fill(&ICP20100_Module);
23. GB_ICP20100_Read_PRESS_ABS(&ICP20100_Module);
24. GB_ICP20100_Read_PRESS_DELTA(&ICP20100_Module);
And finally, in the “while” part of the program, after reading the FIFO level and the interrupt source, the data is read from the FIFO and the pressure and temperature values are continuously received:
1. while (1)
2. {
3. GB_ICP20100_Read_Interrupt_Mask(&ICP20100_Module);
4. GB_ICP20100_FIFO_FILL_LEVEL(&ICP20100_Module);
5. GB_ICP20100_Get_Interrupt_Triggered_Source(&ICP20100_Module);
6. if (ICP20100_Module.INTERUPT_STATUS & FIFO_WMK_HIGH_INT )
7. {
8. GB_ICP20100_Get_FIFO_Data (&ICP20100_Module);
9. GB_ICP20100_Raw_Data_Partition(&ICP20100_Module);
10. GB_ICP20100_Valid_Temp_Press_Data(&ICP20100_Module );
11. GB_ICP20100_Clear_Interrupt_Source_Bit(&ICP20100_Module);
12. GB_ICP20100_FIFO_Flush();
13. }
14.
15. /* USER CODE END WHILE */
16.
17. /* USER CODE BEGIN 3 */
18. }
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) 2022 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. //#define FIFO_THRESOLD 12
45. /* Private includes ----------------------------------------------------------*/
46. /* USER CODE BEGIN Includes */
47. #include "GebraBit_ICP20100.h"
48.
49. /* USER CODE END Includes */
50.
51. /* Private typedef -----------------------------------------------------------*/
52. /* USER CODE BEGIN PTD */
53. GebraBit_ICP20100 ICP20100_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. //float valid_temp,valid_press;
69. //ICP20100_FIFO_Fill_Level level;
70. /* USER CODE END PV */
71.
72. /* Private function prototypes -----------------------------------------------*/
73. void SystemClock_Config(void);
74. /* USER CODE BEGIN PFP */
75.
76. /* USER CODE END PFP */
77.
78. /* Private user code ---------------------------------------------------------*/
79. /* USER CODE BEGIN 0 */
80.
81. /* USER CODE END 0 */
82.
83. /**
84. * @brief The application entry point.
85. * @retval int
86. */
87. int main(void)
88. {
89. /* USER CODE BEGIN 1 */
90.
91. /* USER CODE END 1 */
92.
93. /* MCU Configuration--------------------------------------------------------*/
94.
95. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
96. HAL_Init();
97.
98. /* USER CODE BEGIN Init */
99.
100. /* USER CODE END Init */
101.
102. /* Configure the system clock */
103. SystemClock_Config();
104.
105. /* USER CODE BEGIN SysInit */
106.
107. /* USER CODE END SysInit */
108.
109. /* Initialize all configured peripherals */
110. MX_GPIO_Init();
111. MX_I2C1_Init();
112. MX_SPI1_Init();
113. /* USER CODE BEGIN 2 */
114. GB_ICP20100_OTP_Bootup_Check(&ICP20100_Module);
115. GB_ICP20100_Soft_Reset (&ICP20100_Module);
116. ICP20100_Module.MEAS_CONFIG = ICP20100_OP_MODE2 ;
117. ICP20100_Module.FORCED_MEAS_TRIGGER = ICP20100_FORCE_MEAS_STANDBY ;
118. ICP20100_Module.MEAS_MODE = ICP20100_MEAS_MODE_CONTINUOUS ;
119. ICP20100_Module.POWER_MODE = ICP20100_POWER_NORMAL_MODE ;
120. ICP20100_Module.FIFO_READOUT_MODE = ICP20100_FIFO_READOUT_MODE_PRES_TEMP ;
121. ICP20100_Module.INTERUPT_MASK = FIFO_WMK_HIGH_NOT_MASK ;
122. ICP20100_Module.PRESS_ABS = 24109;
123. ICP20100_Module.PRESS_DELTA = 31062 ;
124. ICP20100_Module.FIFO_WM_HIGH = 10 ;
125. ICP20100_Module.FIFO_WM_LOW = 4 ;
126. ICP20100_Module.FIFO_Packet_Qty = 10 ;
127. GB_ICP20100_Config(&ICP20100_Module);
128. /* USER CODE END 2 */
129. /* Infinite loop */
130. /* USER CODE BEGIN WHILE */
131. GB_ICP20100_Read_Mode_Select(&ICP20100_Module);
132. GB_ICP20100_Read_Interrupt_Mask(&ICP20100_Module);
133. GB_ICP20100_Read_FIFO_Congig(&ICP20100_Module);
134. GB_ICP20100_Read_FIFO_Fill(&ICP20100_Module);
135. GB_ICP20100_Read_PRESS_ABS(&ICP20100_Module);
136. GB_ICP20100_Read_PRESS_DELTA(&ICP20100_Module);
137.
138. while (1)
139. {
140. GB_ICP20100_Read_Interrupt_Mask(&ICP20100_Module);
141. GB_ICP20100_FIFO_FILL_LEVEL(&ICP20100_Module);
142. GB_ICP20100_Get_Interrupt_Triggered_Source(&ICP20100_Module);
143. if (ICP20100_Module.INTERUPT_STATUS & FIFO_WMK_HIGH_INT )
144. {
145. GB_ICP20100_Get_FIFO_Data (&ICP20100_Module);
146. GB_ICP20100_Raw_Data_Partition(&ICP20100_Module);
147. GB_ICP20100_Valid_Temp_Press_Data(&ICP20100_Module );
148. GB_ICP20100_Clear_Interrupt_Source_Bit(&ICP20100_Module);
149. GB_ICP20100_FIFO_Flush();
150. }
151.
152. /* USER CODE END WHILE */
153.
154. /* USER CODE BEGIN 3 */
155. }
156. /* USER CODE END 3 */
157. }
158.
159. /**
160. * @brief System Clock Configuration
161. * @retval None
162. */
163. void SystemClock_Config(void)
164. {
165. RCC_OscInitTypeDef RCC_OscInitStruct = {0};
166. RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
167. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
168.
169. /** Initializes the RCC Oscillators according to the specified parameters
170. * in the RCC_OscInitTypeDef structure.
171. */
172. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
173. RCC_OscInitStruct.HSEState = RCC_HSE_ON;
174. RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
175. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
176. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
177. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
178. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
179. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
180. {
181. Error_Handler();
182. }
183.
184. /** Initializes the CPU, AHB and APB buses clocks
185. */
186. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
187. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
188. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
189. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
190. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
191. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
192.
193. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
194. {
195. Error_Handler();
196. }
197. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_I2C1;
198. PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
199. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
200. {
201. Error_Handler();
202. }
203. }
204.
205. /* USER CODE BEGIN 4 */
206.
207. /* USER CODE END 4 */
208.
209. /**
210. * @brief This function is executed in case of error occurrence.
211. * @retval None
212. */
213. void Error_Handler(void)
214. {
215. /* USER CODE BEGIN Error_Handler_Debug */
216. /* User can add his own implementation to report the HAL error return state */
217. __disable_irq();
218. while (1)
219. {
220. }
221. /* USER CODE END Error_Handler_Debug */
222. }
223.
224. #ifdef USE_FULL_ASSERT
225. /**
226. * @brief Reports the name of the source file and the source line number
227. * where the assert_param error has occurred.
228. * @param file: pointer to the source file name
229. * @param line: assert_param error line source number
230. * @retval None
231. */
232. void assert_failed(uint8_t *file, uint32_t line)
233. {
234. /* USER CODE BEGIN 6 */
235. /* User can add his own implementation to report the file name and line number,
236. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
237. /* USER CODE END 6 */
238. }
239. #endif /* USE_FULL_ASSERT */
240.
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 ICP20100 modules, because they receive their supply voltage directly from the STLINK V2 programmer.
Finally, enter the “Debug” mode and by adding the “ICP20100_Module” to the “watch” window and running the program, we can see the temperature and pressure values changes of the GebraBit ICP20100 module:
In the following, you can download the “GebraBit ICP20100 module setup project” using the GebraBit STM32F303 module in the Keil environment, the “STM32CubeMX file”, the schematic of the modules and the “ICP20100 datasheet”.