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.
Code (far from done):
/* Place your initialization/startup code here */
I2C_1_EnableInt(); //Enables interrupt, which is required for most I2C operations.
wrData = 117; //Reg number
uint8 slaveAddress = 0x68;
#define WR_BUFFER_SIZE (2u)
/* 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
/*  END OF FILE */
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.
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
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 ?
I am trying the same with PSoC 5 LP097 and MPU 6050. I do not understand as to why I observe no data on the COM port. There is no data displayed on the COM port.
I have attached the project bundle here for reference. Kindly help.
Your error is not in the UART, but in your I2C handling. The last parameter for I2C_MasterSendStart() and I2C_MasterSendRestart() is the indicator for following reads or writes. Use the defined const from I2C.h : I2C_READ_XFER_MODE, I2C_WRITE_XFER_MODE and when writing to slave I2C_ACK_DATA, I2C_NAK_DATA.
Keep in mind that most I2C APIs return a status which indicates an error. Better check that until program works.
I do not understand how reading out the register "MPU6050_RA_ACCEL_XOUT_H" gives all the 14 bytes including the temp. sensor values in the code provided by Hernán Sánchez. Isn't it supposed to be reached out to individual registers and try reading out the content?
And after making the changes suggested by you, I observe the following behaviour -
1. I am able to read the bytes from the MPU6050 registers, when I do not connect the PULLUP resistors for SDA and SCL. In case of PULL UP registers connected, the command - " I2C_MasterSendStart(MPU6050_DEVICE_ADDRESS, I2C_WRITE_XFER_MODE) " fails with a return error - I2C_MSTR_NOT_READY. Are pull up resistors not required in this case?
2. After reading some random bytes (approx. 14*16 or 14*19), the slave device stops responding. The command - " I2C_MasterWriteByte(reg)" fails with a return value - I2C_MSTR_ERR_LB_NAK.
3. How do I display the values read from the registers to the Hyperterminal. All I can see is some random characters being written on the terminal.
Could you please provide some tips on this?
Your conversion of hex values to ASCII is not correct. Consider that a uint8 keeps two hex digits, simply adding 0x30 will not convert them.
You might use sprintf() to convert and format into a buffer which you can send to UART. Do not forget to set the heap size to 0x0200 (System view of design wide resources).