Coder Social home page Coder Social logo

yankeehotelbravo / stm32_gy86_i2c_hal Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 1.0 63 KB

For use of MPU6050 and HMC5883L together in GY-86 Module. The code was written for STM32 operation using the HAL driver in I2C communication

C 100.00%
mpu6050 stm32 hal ahrs complementary-filter hmc5883l ms5611

stm32_gy86_i2c_hal's Introduction

About this Library

The following guide is written in order to assist the use of GY-86 sensor module which combines MPU6050, HMC5883L, and MS5611 on a single PCB board. The library is intended to be used on STM32 microcontroller using HAL drivers utilizing I2C communication protocol. The overall structure of the project is inspired by leech001's library for the MPU6050. Here is the link to the repository, I hope you also check it out.
https://github.com/leech001/MPU6050

Table of Contents

  1. MPU6050 & HMC5883L (Understanding Auxiliary I2C)
  2. MS5611

1. MPU6050 & HMC5883L

MPU6050 Sensor is fairly simple to use, however it is quite difficult to use it together with HMC5883L. Without understanding the auxiliary I2C, you will not be able to use HMC5883L at all.

The HMC5883L sensor is not directly connected to SDA and SCL lines going through external pins. HMC5883L sensor is connected to the MPU6050 through auxiliary lines, which is physically inaccessible through external pins on the board. In order to properly set up the HMC5883L, the MPU6050 must be in bypass mode so that the micro controller can simply bypass MPU6050 and directly access to the HMC5883L. Only then the microcontroller can write registers to HMC5883L sensor. Once initialization of HMC5883L is complete, the MPU6050 should be brought back to the master mode and it should read the data from HMC5883L. The data sent by the HMC5883L will be read by the MPU6050, then it will be saved to the MPU6050's internal register address. When the user requires to read the data, the user can retrieve 9 axis values through reading the registers from MPU6050.

Summary of HMC5883L

  1. Set MPU6050 to bypass mode (it is set to master mode by default, therefore needs to be changed)
  2. Directly access HMC5883L for initial setup
  3. Set MPU6050 to back to master mode
  4. Let MPU6050 to read HMC5883L through auxiliary I2C connection
  5. Read 9 axis values from MPU6050

Functions Explained

MPU6050_Init(I2C_HandleTypeDef *I2Cx, uint8_t Gyro_FS, uint8_t Acc_FS, uint8_t DLPF_CFG)

This function is to set the full scale of the sensor. The range of output value is always consist of 16bit, however changing the full scale will change what the value means in real physical units.

MPU6050_Bypass(I2C_HandleTypeDef *I2Cx)

This function will put the MPU6050 sensor into a bypass mode. It will basically bypass all I2C communication sent to the main I2C line towards the HMC5883L so that the MCU can directly communication with HMC5883L. The reason why you have to understand the bypass mode or master mode will be explained later in this document withing the HMC5883L section.

MPU6050_Master(I2C_HandleTypeDef *I2Cx)

This function will put the sensor back to master mode. It means that the MCU can communicate with MPU6050, but not the HMC5883L.

HMC5883L_Setup(I2C_HandleTypeDef *I2Cx)

Once the MPU6050 is set to bypass mode, use this function to complete the basic settings for the HMC5883L.

MPU6050_Slave_Read(I2C_HandleTypeDef *I2Cx)

This function will allow MPU6050 to automatically read values from HMC5883L by itself and save the data into it's own register.

MPU6050_Read_All(I2C_HandleTypeDef *I2Cx, MPU6050_t *DataStruct)

This function will let the MCU read all the outputs of MPU6050 including the values that the MPU6050 has retrieved from the HMC5883L.

MPU6050_Parsing_NoOffest(MPU6050_t *DataStruct)

This function will do bit shifting so that the retrieved values from sensors would fit to the proper form, and it will also convert some values into different unit.

2. MS5611

On the other hand, MS5611 sensor is directly connected to SDA and SCL lines so it could be accessed from the master device without any issue.

stm32_gy86_i2c_hal's People

Contributors

yankeehotelbravo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

shaman7036

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.