You are here

Newb: Reading values from MPU-6050 (Accelerometer + Gyro) using I2C | Cypress Semiconductor

Newb: Reading values from MPU-6050 (Accelerometer + Gyro) using I2C

Summary: 5 Replies, Latest post by Bob Marlowe on 28 May 2014 04:45 AM PDT
Verified Answers: 0
Last post
Log in to post new comments.
VTW's picture
2 posts


I am really fresh when it comes to PSoC programming, I only have a little experience with arduino from some projects in the past.

My project now is to read out the RAW-values from the MPU-6050, which requires the use of I2C. I have never used this before, and I am struggeling with all the new commands, and how/when to use them.

All I want to do so far is to read the RAW-data and save them in different arrays.


I have attached a schematic of what I've made this far, but I am kind of stumbling in the dark at the moment.


VTW's picture
2 posts

 Code (far from done):


#include <device.h>


void main()


    /* Place your initialization/startup code here */

uint8 wrData;

uint8 rdData;

uint8 status;

uint8 readFlag;

uint8 breakp;

uint8 masterStatus;

uint8 temp;




I2C_1_EnableInt(); //Enables interrupt, which is required for most I2C operations.

wrData = 117; //Reg number

uint8 slaveAddress = 0x68;

#define WR_BUFFER_SIZE       (2u)

uint8 sample_segment[WR_BUFFER_SIZE];


    /* CyGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */



        status = I2C_1_MasterSendStart(slaveAddress, I2C_1_WRITE_XFER_MODE);

while (stats != I2C_1_MSTR_NO_ERROR);

if(status == I2C_1_MSTR_NO_ERROR) // Check if transfer is completed without errors



(uint8 *)sample_segment,



LCD_Char_PrintString("NO ERROR");






/* [] END OF FILE */

user_1377889's picture
9284 posts

Welcome in the fascinating world of PSoCs!

At very first sight:

The I2C is interrupt-driven, so you MUST enable global interrupts.


It is always advisable to upload the complete project here, so that we all can have a look at. To do so, in Creator "File -> Create Workspace Bundle (minimal)" and then upload the resulting archive here.


For newbees usually C-language and programming turns out to be a problem, too. When the project grows it becomes more and more complex, so when you start early to divide it into smaller pieces it will help you. so your main() may look something like










Remember: a(ny) project gets complicated. And: A function "ReadMPU6050()" can easily be re-used in your next project.


Happy coding


user_14586677's picture
7646 posts

Assumption made you connected SCL to SDA on accel, not the AUX connections

which do not  have pullups ?


Also in Creator there is a working example project using I2C you can modify or

look at.


I see on schematic different verison in notes section switched SDA, SCL, check your

version. Lastly I see you writing to I2C, but not reading the accel ? Was that config

commands for the accel in the write buffer ?


Regards, Dana.

hsanchez's picture
1 post


Maybe a little late, but I'm attaching an example that I did to test MPU-6050 using Cypress PSoC 4 Pionner Kit.


Hernán Sánchez

user_1377889's picture
9284 posts

Thank you very much for sharing your project with us!

Are you building any real project with that MPU6050?



Log in to post new comments.