GebraBit

BU2700MUCZ sensor project with STM32F303 microcontroller series

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

BU27006 gebrabit project

BU2700MUCZ sensor project with STM32F303 microcontroller series

BU27006 gebrabit project
  1. Home
  2. »
  3. Projects
  4. »
  5. BU2700MUCZ sensor project with STM32F303 microcontroller series

What's the purpose of this project?

In this section, we are going to launch the BU27006MUCZ sensor using ARM microcontroller, STM32F series. In order to use more conveniently and optimally in this project, we use two ready modules GB615EN and GebraBit STM32F303. These two modules contain the minimum necessary elements of the BU27006MUCZ 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 BU27006MUCZ sensor, you will get to know all the BU27006MUCZ sensor registers, how to set the various parts of the STM32 microcontroller to set up this sensor using the I2C protocol, how to use the GB615EN 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 as shown in the image below, we connect the GebraBit BU27006MUCZ module to the GebraBit STM32F303 module as follows:

Note: Considering that the PA14 pin of the GebraBit STM32F303 microcontroller module is used to program the microcontroller, the I2C setting on the PA14 and PA15 pins is not possible in this version, so the GebraBit BU27006MUCZ module cannot be placed as a pin to pin on the GebraBit STM32F303 microcontroller module.

Finally, we will see the values of RED, Blue, Green, IR and Flicker in Real Time in the “Watch1” window of the Keil compiler in the “Debug Session” mode.

STM32CubeMX settings

In the following, we review the settings related to each of the “I2C”, “RCC”, “Debug”, and “Clock” sections in the STM32F303 microcontroller to develop the GebraBit BU27006MUCZ 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:

I2C settings

To communicate with the GebraBit STM32F303 module through I2C, select the Standard Mode with a speed of 100khz and select PB8 and PB9 pins as SCL and SDA:

According to the sensor data sheet, the settings of the I2C 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 BU27006MUCZ library and driver (provided by GebraBit).

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

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

USER REGISTER MAP

The registry map or sensor commands are defined in this section:

				
					1. #define BU27006MUCZMUCZ_SYSTEM_CONTROL  		0x40
 2. #define BU27006MUCZMUCZ_MODE_CONTROL1  			0x41
 3. #define BU27006MUCZMUCZ_MODE_CONTROL2 			0x42
 4. #define BU27006MUCZMUCZ_MODE_CONTROL3 			0x43
 5. #define BU27006MUCZMUCZ_RED_DATA 				0x50  //2 byte
 6. #define BU27006MUCZMUCZ_GREEN_DATA 				0x52  //2 byte
 7. #define BU27006MUCZMUCZ_BLUE_DATA 				0x54  //2 byte
 8. #define BU27006MUCZMUCZ_IR_DATA 				0x56  //2 byte
 9. #define BU27006MUCZMUCZ_FLICKER_DATA 			0x58  //2 byte
10. #define BU27006MUCZMUCZ_FLICKER_COUNTER 		0x5A
11. #define BU27006MUCZMUCZ_FIFO_LEVEL 				0x5B
12. #define BU27006MUCZMUCZ_FIFO_DATA 				0x5C  //2 byte
13. #define BU27006MUCZMUCZ_MANUFACTURER_ID 		0x92
14. #define BU27006MUCZMUCZ_I2C		                &hi2c1	
15. #define BU27006MUCZMUCZ_ADDRESS 	            0x38
16. #define BU27006MUCZMUCZ_WRITE_ADDRESS 			((BU27006MUCZMUCZ_ADDRESS<<1)|0)
17. #define BU27006MUCZMUCZ_READ_ADDRESS 			((BU27006MUCZMUCZ_ADDRESS<<1)|1)
18.  

				
			

BU27006MUCZ _Ability Enum

This enum is used to activate and deactivate different parts of the sensor:

				
					1. typedef enum Ability
2. {  
3. 	Disable = 0 ,                      
4. 	Enable     
5. }BU27006MUCZ_Ability;   
6.  

				
			

BU27006MUCZ _Reset_Status Enum

By using this enum, the sensor reset status is determined:

				
					typedef enum 
{  
	FAILED = 0 ,                      
	DONE     
}BU27006MUCZ_Reset_Status;

				
			

BU27006MUCZ_ RGB_Gain Enum

The values of this enum are used to set the RGB gain of the sensor:

				
					1. typedef enum RGB_Gain 
2. {
3.   RGB_GAIN_1X   = 0,
4.   RGB_GAIN_4X   = 1,
5.   RGB_GAIN_32X  = 2,
6.   RGB_GAIN_128X = 3,
7. } BU27006MUCZ_RGB_Gain;
8.  

				
			

BU27006MUCZ_FLC_Gain Enum

The values of this enum are used to set the sensor FLC gain:

				
					1. typedef enum FLC_Gain 
 2. {
 3.   FLC_GAIN_1X   = 0,
 4.   FLC_GAIN_2X   = 1,
 5.   FLC_GAIN_4X   = 2,
 6.   FLC_GAIN_8X   = 3,
 7.   FLC_GAIN_16X  = 4,
 8.   FLC_GAIN_32X  = 5
 9. } BU27006MUCZ_FLC_Gain;
10.  

				
			

BU27006MUCZ_Interrupt_Channel Enum

To set the source of interruption in the sensor, the values of this enum are used:

				
					1. typedef enum Interrupt_Channel 
2. {  
3. 	CLEAR_CHANNEL = 0 ,                      
4. 	ALS_CHANNEL     
5. }BU27006MUCZ_Interrupt_Channel;

				
			

BU27006MUCZ_Interrupt_Mode Enum

Using this enum, the sensor interrupt type is selected:

				
					1. typedef enum Interrupt_Mode
2. {
3. 	 INTERRUPT_DISABLE  ,
4.   RGB_IR_COMPELETION ,
5.   FLICKER_COMPELETION,
6.   FIFO_64_DATA_READY
7. } BU27006MUCZ_Interrupt_Mode;
8.  

				
			

BU27006MUCZ_RGB_Measurement_Mode Enum

To specify the RGB measurement mode of the sensor, the values of this enum are used:

				
					1. typedef enum RGB_Measurement_Mode
2. {
3. 	_55_mS_MODE  = 1,
4.  _100_mS_MODE = 2
5. } BU27006MUCZ_RGB_Measurement_Mode;
6.  

				
			

BU27006MUCZ_FLC_Measurement_Mode Enum

The values of this enum are used to specify the FLC measurement mode of the sensor:

				
					1. typedef enum FLC_Measurement_Mode
2. {
3.   _1_KHZ_MODE,
4.   _2_KHZ_MODE
5. } BU27006MUCZ_FLC_Measurement_Mode;
6.  

				
			

BU27006MUCZ_Data_Status Enum

The values of this enum determine whether the read data is updated or not:

				
					1. typedef enum Data_Status 
2. {  
3. 	NOT_UPDATED = 0 ,                      
4. 	UPDATED     
5. }BU27006MUCZ_Data_Status;
6.  

				
			

BU27006MUCZ_Interrupt_Status Enum

The values of this Enum are used to know whether the interrupt in the sensor is fulfilled or not.

				
					1. typedef enum Interrupt_Status 
2. {  
3. 	INTERRUPT_NOT_FULFILLED = 0 ,                      
4. 	INTERRUPT_FULFILLED     
5. }BU27006MUCZ_Interrupt_Status;
6.  

				
			

BU27006MUCZ 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 BU27006MUCZ
 2. {
 3. 	  uint8_t                       	 Register_Cache;
 4. 	  uint8_t				             PART_ID;
 5. 	  uint8_t							 MANUFACTURER_ID;
 6. 	  BU27006MUCZ_Reset_Status			 RESET;
 7. 	  BU27006MUCZ_Ability                RGB_IR;
 8. 	  BU27006MUCZ_Ability                FLC;
 9. 	  BU27006MUCZ_RGB_Gain               RGB_GAIN;
10. 	  BU27006MUCZ_RGB_Measurement_Mode   RGB_MEASUREMENT_MODE;
11. 	  BU27006MUCZ_FLC_Gain               FLC_GAIN;
12. 	  BU27006MUCZ_FLC_Measurement_Mode   FLC_MEASUREMENT_MODE;
13. 	  float								 ALS_RESOLUTION_TIME;
14. 	  BU27006MUCZ_Data_Status            RGB_DATA;
15. 	  BU27006MUCZ_Data_Status            FLC_DATA;	  
16. 	  BU27006MUCZ_Interrupt_Mode         INTERRUPT_MODE;
17.       BU27006MUCZ_Interrupt_Channel      INTERRUPT_CHANNEL;
18. 	  uint8_t         					 FLICKER_COUNTER;
19. 	  uint8_t                            FIFO_LEVEL;
20. 	  BU27006MUCZ_Interrupt_Status		 INTERRRUPT_STATUS;
21. 	  uint32_t                        	 INTERRUPT_UPPER_THRESHOLD;
22. 	  uint32_t                           INTERRUPT_LOWER_THRESHOLD;
23. 	  uint8_t 							 REGISTER_DATA[REGISTER_DATA_BUFFER_SIZE];
24. 	  uint16_t                           RED_DATA;
25. 	  uint16_t                           GREEN_DATA;
26. 	  uint16_t               			 BLUE_DATA;
27. 	  uint16_t               			 IR_DATA;
28. 	  uint16_t               			 FLICKER_DATA;
29. 	  uint16_t 							 FIFO_DATA[FIFO_DATA_BUFFER_SIZE];
30.         float 							 RED_LUX;
31. 		float 							 GREEN_LUX;
32. 		float 							 BLUE_LUX;
33. }GebraBit_BU27006MUCZ;
34.  

				
			

Declaration of functions

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

				
					1. extern void GB_BU27006MUCZ_Read_Reg_Data(uint8_t regAddr,  uint8_t *data)	;
 2. extern void GB_BU27006MUCZ_Burst_Read(uint8_t regAddr,  uint8_t *data, uint16_t byteQuantity);
 3. extern void GB_BU27006MUCZ_Read_Reg_Bits (uint8_t regAddr, uint8_t start_bit, uint8_t len, uint8_t* data);	
 4. extern void GB_BU27006MUCZ_Write_Command( uint8_t cmd);
 5. extern void GB_BU27006MUCZ_Write_Reg_Data(uint8_t regAddr,  uint8_t data)	;
 6. extern void GB_BU27006MUCZ_Burst_Write(uint8_t regAddr,  uint8_t *data, uint16_t byteQuantity)								;
 7. extern void GB_BU27006MUCZ_Write_Reg_Bits(uint8_t regAddr, uint8_t start_bit, uint8_t len, uint8_t data);
 8. /********************************************************
 9.  *       Declare MS5611 Configuration Functions         *
10.  ********************************************************/
11. extern void GB_BU27006MUCZ_Soft_Reset ( GebraBit_BU27006MUCZ * BU27006MUCZ )  ;
12. extern void GB_BU27006MUCZ_RGB_Gain ( GebraBit_BU27006MUCZ * BU27006MUCZ , BU27006MUCZ_RGB_Gain gain ) ;
13. extern void GB_BU27006MUCZ_RGB_Measurement_Mode ( GebraBit_BU27006MUCZ * BU27006MUCZ , BU27006MUCZ_RGB_Measurement_Mode mode )   ;
14. extern void GB_BU27006MUCZ_FLC_Measurement_Mode ( GebraBit_BU27006MUCZ * BU27006MUCZ , BU27006MUCZ_FLC_Measurement_Mode mode )   ;
15. extern void GB_BU27006MUCZ_FLC_Gain ( GebraBit_BU27006MUCZ * BU27006MUCZ , BU27006MUCZ_FLC_Gain gain ) ;
16. extern void GB_BU27006MUCZ_RGB_IR ( GebraBit_BU27006MUCZ * BU27006MUCZ , BU27006MUCZ_Ability rgb )   ;
17. extern void GB_BU27006MUCZ_FLC ( GebraBit_BU27006MUCZ * BU27006MUCZ , BU27006MUCZ_Ability flc );
18. extern void GB_BU27006MUCZ_Interrupt(GebraBit_BU27006MUCZ * BU27006MUCZ , BU27006MUCZ_Interrupt_Mode mode)  ;
19. extern void GB_BU27006MUCZ_Check_Data_Updated ( GebraBit_BU27006MUCZ * BU27006MUCZ )  ;
20. extern void GB_BU27006MUCZ_Part_ID ( GebraBit_BU27006MUCZ * BU27006MUCZ  )  ;
21. extern void GB_BU27006MUCZ_Manufacture_ID ( GebraBit_BU27006MUCZ * BU27006MUCZ  )  ;
22. extern void GB_BU27006MUCZ_Flicker_Counter ( GebraBit_BU27006MUCZ * BU27006MUCZ ) ;
23. extern void GB_BU27006MUCZ_FIFO_Level ( GebraBit_BU27006MUCZ * BU27006MUCZ ) ;
24. extern void GB_BU27006MUCZ_Read_FIFO_Flicker_Data ( GebraBit_BU27006MUCZ * BU27006MUCZ );
25. extern void GB_BU27006MUCZ_initialize( GebraBit_BU27006MUCZ * BU27006MUCZ )  ;
26. extern void GB_BU27006MUCZ_Configuration(GebraBit_BU27006MUCZ * BU27006MUCZ)  ;
27. extern void GB_BU27006MUCZ_Read_RGB_IR_FLICKER(GebraBit_BU27006MUCZ * BU27006MUCZ);
28. extern void GB_BU27006MUCZ_Color_Luminosity(GebraBit_BU27006MUCZ * BU27006MUCZ);
29. extern void GB_BU27006MUCZ_Get_Data(GebraBit_BU27006MUCZ * BU27006MUCZ);
30.  

				
			

GebraBit_BU27006MUCZ.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_BU27006MUCZ.c” library provided by GebraBit, we will examine the “main .c” file of the sample tutorial and view the output of the GebraBit_BU27006MUCZ module in the “watch” part in the Keil compiler “Debugging” environment.

Description of “main.c” file

Enums and functions required by GebraBit BU27006MUCZ module have been added to the structures. In the next part, a variable named BU27006MUCZ_Module of the GebraBit_BU27006MUCZ structure type (this structure is in the GebraBit_BU27006MUCZ header and is explained in the GebraBit_BU27006MUCZ library description section) is defined for the configuration of the GebraBit BU27006MUCZ module:  

				
					/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
GebraBit_BU27006MUCZ BU27006MUCZ_Module;
/* USER CODE END PTD */

				
			

In the next part of the written code, using the GB_BU27006MUCZ_initialize (&BU27006MUCZ_Module) and GB_BU27006MUCZ_Configuration (&BU27006MUCZ_Module) functions, we set the GebraBit BU27006MUCZ module and finally, in the while part of the program, the data is read from the sensor and the RED, BLUE, GREEN, IR and Flicker values are continuously received:   

				
					1. /* USER CODE BEGIN 2 */
 2. 	GB_BU27006MUCZ_initialize(&BU27006MUCZ_Module);
 3. 	GB_BU27006MUCZ_Configuration(&BU27006MUCZ_Module);
 4.   /* USER CODE END 2 */
 5.  
 6.   /* Infinite loop */
 7.   /* USER CODE BEGIN WHILE */
 8.   while (1)
 9.   {
10.     /* USER CODE END WHILE */
11.  
12.     /* USER CODE BEGIN 3 */
		//GB_BU27006MUCZ_Get_Data(&BU27006MUCZ_Module);
		GB_BU27006MUCZ_Read_FIFO_Flicker_Data(&BU27006MUCZ_Module);14.   }
15.   /* USER CODE END 3 */
16. }
17.  

				
			

Description of “main.c” file

				
					  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 "gpio.h"
 44.  
 45. /* Private includes ----------------------------------------------------------*/
 46. /* USER CODE BEGIN Includes */
 47. #include "GebraBit_BU27006MUCZ.h"
 48. /* USER CODE END Includes */
 49.  
 50. /* Private typedef -----------------------------------------------------------*/
 51. /* USER CODE BEGIN PTD */
 52. GebraBit_BU27006MUCZ BU27006MUCZ_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.   /* USER CODE BEGIN 2 */
111.   GB_BU27006MUCZ_initialize(&BU27006MUCZ_Module);
112. 	GB_BU27006MUCZ_Configuration(&BU27006MUCZ_Module);
113.   /* USER CODE END 2 */
114.  
115.   /* Infinite loop */
116.   /* USER CODE BEGIN WHILE */
117.  
118. 	while (1)
119.   {
120.     /* USER CODE END WHILE */
121.  
122.     /* USER CODE BEGIN 3 */
123. 		//GB_BU27006MUCZ_Get_Data(&BU27006MUCZ_Module);
124. 		GB_BU27006MUCZ_Read_FIFO_Flicker_Data(&BU27006MUCZ_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 BU2700MUCZ modules, because they receive their supply voltage directly from the STLINK V2 programmer.

Finally, enter the “Debug” mode and by adding the “BU2700MUCZ_Module” to the “watch” window and running the program, we can see the changes in the RED, BLUE, GREEN, IR and Flicker values of the GebraBit BU2700MUCZ module:

Receive data from FIFO:

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

Program output video

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

Be the first to write a review

Please help the Gebra team to improve the quality by sending comments and ratings

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?