ME 507 Romi++
Cylindrical Differential Drive Robot created for ME 507 at Cal Poly in Spring 2025
Loading...
Searching...
No Matches
BNO055_STM32.h
1/*
2 * BNO055_STM32.h
3 *
4 * Created on: Jun 5, 2025
5 * Author: jacka
6 *
7 * \copyright Copyright (c) 2024 Afebia
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32
33#ifndef INC_BNO055_STM32_H_
34#define INC_BNO055_STM32_H_
35
36#include <stdint.h>
37#include <stdio.h>
38#include "stm32f4xx_hal.h"
39#include <stdbool.h>
40
41extern I2C_HandleTypeDef hi2c1;
42#define bno_i2c (hi2c1)
43
44
45#define P_BNO055 (0x29<<1)
46#define BNO055_ID 0xA0
47
48/*===========================================================================================================================*/
49/* *[Page 0 Register Addresses Macro Definition]* */
50/*===========================================================================================================================*/
51
52/*
53 * Radius registers
54 */
55#define MAG_RADIUS_MSB_ADDR 0x6A
56#define MAG_RADIUS_LSB_ADDR 0x69
57#define ACC_RADIUS_MSB_ADDR 0x68
58#define ACC_RADIUS_LSB_ADDR 0x67
59
60/*
61 * Gyroscope offset register address macros
62 */
63#define GYRO_OFFSET_Z_MSB_ADDR 0x66
64#define GYRO_OFFSET_Z_LSB_ADDR 0x65
65#define GYRO_OFFSET_Y_MSB_ADDR 0x64
66#define GYRO_OFFSET_Y_LSB_ADDR 0x63
67#define GYRO_OFFSET_X_MSB_ADDR 0x62
68#define GYRO_OFFSET_X_LSB_ADDR 0x61
69
70/*
71 * Magnetometer offset register address macros
72 */
73#define MAG_OFFSET_Z_MSB_ADDR 0x60
74#define MAG_OFFSET_Z_LSB_ADDR 0x5F
75#define MAG_OFFSET_Y_MSB_ADDR 0x5E
76#define MAG_OFFSET_Y_LSB_ADDR 0x5D
77#define MAG_OFFSET_X_MSB_ADDR 0x5C
78#define MAG_OFFSET_X_LSB_ADDR 0x5B
79
80/*
81 * Accelerometer offset register address macros
82 */
83#define ACC_OFFSET_Z_MSB_ADDR 0x5A
84#define ACC_OFFSET_Z_LSB_ADDR 0x59
85#define ACC_OFFSET_Y_MSB_ADDR 0x58
86#define ACC_OFFSET_Y_LSB_ADDR 0x57
87#define ACC_OFFSET_X_MSB_ADDR 0x56
88#define ACC_OFFSET_X_LSB_ADDR 0x55
89
90#define AXIS_MAP_SIGN_ADDR 0x42
91#define AXIS_MAP_CONFIG_ADDR 0x41
92#define TEMP_SOURCE_ADDR 0x40
93#define SYS_TRIGGER_ADDR 0x3F
94#define PWR_MODE_ADDR 0x3E
95#define OPR_MODE_ADDR 0x3D
96
97#define UNIT_SEL_ADDR 0x3B
99
100#define SYS_ERR_ADDR 0x3A
101#define SYS_STATUS_ADDR 0x39
102#define SYS_CLK_STATUS_ADDR 0x38
103#define INT_STA_ADDR 0x37
104#define ST_RESULT_ADDR 0x36
105#define CALIB_STAT_ADDR 0x35
106#define TEMP_ADDR 0x34
107
108/*
109 * Address macros of gravity vector data output registers
110 * Note: Read-only register access
111 */
112#define GRV_DATA_Z_MSB_ADDR 0x33
113#define GRV_DATA_Z_LSB_ADDR 0x32
114#define GRV_DATA_Y_MSB_ADDR 0x31
115#define GRV_DATA_Y_LSB_ADDR 0x30
116#define GRV_DATA_X_MSB_ADDR 0x2F
117#define GRV_DATA_X_LSB_ADDR 0x2E
118#define GRV_DATA_BASEADDR GRV_DATA_X_LSB_ADDR
119
120/*
121 * Address macros of linear acceleration data output registers
122 * Note: Read-only register access
123 */
124#define LIA_DATA_Z_MSB_ADDR 0x2D
125#define LIA_DATA_Z_LSB_ADDR 0x2C
126#define LIA_DATA_Y_MSB_ADDR 0x2B
127#define LIA_DATA_Y_LSB_ADDR 0x2A
128#define LIA_DATA_X_MSB_ADDR 0x29
129#define LIA_DATA_X_LSB_ADDR 0x28
130#define LIA_DATA_BASEADDR LIA_DATA_X_LSB_ADDR
131
132/*
133 * Address macros of quaternion data output registers
134 * Note: Read-only register access
135 */
136#define QUA_DATA_Z_MSB_ADDR 0x27
137#define QUA_DATA_Z_LSB_ADDR 0x26
138#define QUA_DATA_Y_MSB_ADDR 0x25
139#define QUA_DATA_Y_LSB_ADDR 0x24
140#define QUA_DATA_X_MSB_ADDR 0x23
141#define QUA_DATA_X_LSB_ADDR 0x22
142#define QUA_DATA_W_MSB_ADDR 0x21
143#define QUA_DATA_W_LSB_ADDR 0x20
144#define QUA_DATA_BASEADDR QUA_DATA_W_LSB_ADDR
145
146/*
147 * Address macros of euler data output registers
148 * Note: Read-only register access
149 */
150#define EUL_PITCH_MSB_ADDR 0x1F
151#define EUL_PITCH_LSB_ADDR 0x1E
152#define EUL_ROLL_MSB_ADDR 0x1D
153#define EUL_ROLL_LSB_ADDR 0x1C
154#define EUL_HEADING_MSB_ADDR 0x1B
155#define EUL_HEADING_LSB_ADDR 0x1A
156#define EUL_DATA_BASEADDR EUL_HEADING_LSB_ADDR
157
158/*
159 * Address macros of gyroscope data output registers
160 * Note: Read-only register access
161 */
162#define GYRO_DATA_Z_MSB_ADDR 0x19
163#define GYRO_DATA_Z_LSB_ADDR 0x18
164#define GYRO_DATA_Y_MSB_ADDR 0x17
165#define GYRO_DATA_Y_LSB_ADDR 0x16
166#define GYRO_DATA_X_MSB_ADDR 0x15
167#define GYRO_DATA_X_LSB_ADDR 0x14
168#define GYRO_DATA_BASEADDR GYRO_DATA_X_LSB_ADDR
169
170/*
171 * Address macros of magnetometer data output registers
172 * Note: Read-only register access
173 */
174#define MAG_DATA_Z_MSB_ADDR 0x13
175#define MAG_DATA_Z_LSB_ADDR 0x12
176#define MAG_DATA_Y_MSB_ADDR 0x11
177#define MAG_DATA_Y_LSB_ADDR 0x10
178#define MAG_DATA_X_MSB_ADDR 0x0F
179#define MAG_DATA_X_LSB_ADDR 0x0E
180#define MAG_DATA_BASEADDR MAG_DATA_X_LSB_ADDR
181
182/*
183 * Address macros of accelerometer data output registers
184 * Note: Read-only register access
185 */
186#define ACCEL_DATA_Z_MSB_ADDR 0x0D
187#define ACCEL_DATA_Z_LSB_ADDR 0x0C
188#define ACCEL_DATA_Y_MSB_ADDR 0x0B
189#define ACCEL_DATA_Y_LSB_ADDR 0x0A
190#define ACCEL_DATA_X_MSB_ADDR 0x09
191#define ACCEL_DATA_X_LSB_ADDR 0x08
192#define ACCEL_DATA_BASEADDR ACCEL_DATA_X_LSB_ADDR
193
194/*
195 * Address macros of register which contains various ID parameters
196 * Note: Read-only register access
197 */
198#define PAGE_ID_ADDR 0x07
199#define BL_REV_ID_ADDR 0x06
200#define SW_REV_ID_MSB_ADDR 0x05
201#define SW_REV_ID_LSB_ADDR 0x04
202#define GYR_ID_ADDR 0x03
203#define MAG_ID_ADDR 0x02
204#define ACC_ID_ADDR 0x01
205#define CHIP_ID_ADDR 0x00
206
207/*===========================================================================================================================*/
208/* *[ Page 1 Register Addresses Macro Definition]* */
209/*===========================================================================================================================*/
210
211/*
212 * NOTE: All page 1 registers have read-only access
213 */
214#define UNIQUE_ID_BASEADDR 0x50
215#define GYR_AM_SET_ADDR 0x1F
216#define GYR_AM_THRES_ADDR 0x1E
217#define GYR_DUR_Z_ADDR 0x1D
218#define GYR_HR_Z_SET_ADDR 0x1C
219#define GYR_DUR_Y_ADDR 0x1B
220#define GYR_HR_Y_SET_ADDR 0x1A
221#define GYR_DUR_X_ADDR 0x19
222#define GYR_HR_X_SET_ADDR 0x18
223#define GYR_INT_SETING_ADDR 0x17
224#define ACC_NM_SET_ADDR 0x16
225#define ACC_NM_THRES_ADDR 0x15
226#define ACC_HG_THRES_ADDR 0x14
227#define ACC_HG_DURATION_ADDR 0x13
228#define ACC_INT_Setting_ADDR 0x12
229#define ACC_AM_THRES_ADDR 0x11
230#define INT_EN_ADDR 0x10
231#define INT_MSK_ADDR 0x0F
232#define GYR_Sleep_Config_ADDR 0x0D
233#define ACC_Sleep_Config_ADDR 0x0C
234#define GYRO_CONFIG_1_ADDR 0x0B
235#define GYRO_CONFIG_0_ADDR 0x0A
236#define MAG_CONFIG_ADDR 0x09
237#define ACC_CONFIG_ADDR 0x08
238
239/*
240 * Page macros
241 */
242#define PAGE_0 0x00
243#define PAGE_1 0x01
244
248 */
249typedef struct{
250 uint8_t STresult; //First 4 bit[0:3] indicates self test resulst 3:ST_MCU, 2:ST_GYRO, 1:ST_MAG, 0:ST_ACCEL
251 uint8_t SYSError; //Contains system error type If SYSStatus is System_Error(0x01)
252 uint8_t SYSStatus;
255typedef struct{
256 uint8_t System;
257 uint8_t Gyro;
258 uint8_t Acc;
259 uint8_t MAG;
261
265 */
266typedef struct{ //SENSOR DATA AXIS X, Y and Z
267 float X;
268 float Y;
269 float Z;
272typedef struct{ //SENSOR DATA AXIS W, X, Y and Z (Only for quaternion data)
273 float W;
274 float X;
275 float Y;
276 float Z;
279typedef struct{ //SENSOR DATAS
280 BNO055_Data_XYZ_t Accel;
282 BNO055_Data_XYZ_t Magneto;
283 BNO055_Data_XYZ_t Euler;
284 BNO055_Data_XYZ_t LineerAcc;
285 BNO055_Data_XYZ_t Gravity;
286 BNO055_QuaData_WXYZ_t Quaternion;
288
289typedef enum {
290 SENSOR_GRAVITY = 0x01,
291 SENSOR_QUATERNION = 0x02,
292 SENSOR_LINACC = 0x04,
293 SENSOR_GYRO = 0x08,
294 SENSOR_ACCEL = 0x10,
295 SENSOR_MAG = 0x20,
296 SENSOR_EULER = 0x40,
297} BNO055_Sensor_Type;
298
299//Base Addresses of output data register
300#define BNO_ACCEL ACCEL_DATA_BASEADDR
301#define BNO_GYRO GYRO_DATA_BASEADDR
302#define BNO_MAG MAG_DATA_BASEADDR
303#define BNO_EULER EUL_DATA_BASEADDR
304#define BNO_LINACC LIA_DATA_BASEADDR
305#define BNO_GRAVITY GRV_DATA_BASEADDR
306#define BNO_QUATERNION QUA_DATA_BASEADDR
307
311 */
312typedef struct
313{
314 uint8_t Unit_Sel;
315 uint8_t Axis;
316 uint8_t Axis_sign;
317 uint8_t Mode;
318 uint8_t OP_Modes;
319 uint8_t Clock_Source;
320 uint8_t ACC_Range;
322
323typedef enum{// OPERATION MODES
324 CONFIG_MODE =0x00, //This is the only mode in which all the writable register map entries can be changed (Except INT , INT_MASK, OPR_MODE)
325 ACC_ONLY =0x01,
326 MAG_ONLY =0x02,
327 GYRO_ONLY =0x03,
328 ACC_MAG =0x04,
329 ACC_GYRO =0x05,
330 MAG_GYRO =0x06,
331 AMG= 0x07,
332 IMU= 0x08,
333 COMPASS =0x09,
334 M4G= 0x0A,
335 NDOF_FMC_OFF =0x0B,
336 NDOF= 0x0C
337}Op_Modes_t;
338
339#define BNO055_NORMAL_MODE 0
340#define BNO055_LOWPOWER_MODE 1
341#define BNO055_SUSPEND_MODE 2
342
343#define DEFAULT_AXIS_REMAP 0x24
344#define DEFAULT_AXIS_SIGN 0x00
345
346#define CLOCK_EXTERNAL (1 << 7)
347#define CLOCK_INTERNAL (0 << 7)
348
349/*
350 * UNIT_SELECT register macros definition
351 */
352#define UNIT_ORI_ANDROID (1 << 7)
353#define UNIT_ORI_WINDOWS (0 << 7)
354#define UNIT_TEMP_CELCIUS (0 << 4)
355#define UNIT_TEMP_FAHRENHEIT (1 << 4)
356#define UNIT_EUL_DEG (0 << 2)
357#define UNIT_EUL_RAD (1 << 2)
358#define UNIT_GYRO_DPS (0 << 1)
359#define UNIT_GYRO_RPS (1 << 1)
360#define UNIT_ACC_MS2 (0 << 0)
361#define UNIT_ACC_MG (1 << 0)
362
363/*
364 * ACCEL range macros definition for ACC_CONFIG register
365 */
366#define Range_2G 0x00
367#define Range_4G 0x01
368#define Range_8G 0x02
369#define Range_16G 0x03
370
371/*
372 * BNO055 library function declaration
373 */
374void getCalibration(Calib_status_t *calib);
375Op_Modes_t getCurrentMode(void);
376bool isFullyCalibrated(void);
377void setSensorOffsets(const uint8_t *calibData) ;
378void getSensorOffsets(uint8_t *calibData);
379bool Calibrate_BNO055(void);
380
381void Set_Operation_Mode(Op_Modes_t Mode);
382void Clock_Source(uint8_t source);
383void SetPowerMODE(uint8_t BNO055_);
384void BNO055_Axis(uint8_t remap, uint8_t sign);
385void SelectPage(uint8_t page);
386void SET_Accel_Range(uint8_t range);
387void BNO055_Init(BNO055_Init_t Init);
388void ReadData(BNO055_Sensors_t *sensorData,BNO055_Sensor_Type sensors);
389void Check_Status(BNO_Status_t *result);
390void ResetBNO055(void);
391
392#endif /* INC_BNO055_STM32_H_ */
393
394
395#ifdef __cplusplus
396}
397#endif
Definition BNO055_STM32.h:265
Definition BNO055_STM32.h:312
Definition BNO055_STM32.h:271
Definition BNO055_STM32.h:278
Definition BNO055_STM32.h:248
Definition BNO055_STM32.h:254