Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 10 months ago.
STM32F103x I2C issues with MPU6050..can't write any register.
Reading any particular register works fine..like if I try to read Who_Am_I it returns 0x68. When I write to any register, code executes fine without any hiccups..but then when I read that register to check if new value has been written or not it still shows the reset value of the register..here are few code snippets.
Code: https://github.com/spookymelonhead/Mini-STM32-v3.0/blob/master/STM32F103x-%20MPU6050.c
2 Answers
8 years, 10 months ago.
Thats a fun one that everyone who starts with the MPU6050 ends up with :D. The MPU6050 boots up in a sleep mode, during which it will ignore all writes and won't do anything. Somewhere you got a power mode register, and you need to disable sleep there. Then it works fine.
hey there again..with some hassle..I2C code which I was working on works without any hiccup..but problem now is..I can't get any raw data from MPU6050..I can read or write register..but fifo is all zero..I already disabled it from sleep mode..enable the fifo enable register..see here-http://uploadpie.com/dSHix and here's the code along with the libraries I coded..https://github.com/spookymelonhead/Tuna_Fish/tree/master/Tuna_Fish
posted by 08 Feb 20168 years, 10 months ago.
Why aren't you using the I2C class within mbed? You can simplify your code immensely. Here's a snip from the LM75A example:
// Read temperature register data_write[0] = LM75_REG_TEMP; i2c.write(LM75_ADDR, data_write, 1, 1); // no stop i2c.read(LM75_ADDR, data_read, 2, 0);