4 years, 5 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. /media/uploads/spookymelonhead/i2c_init.jpg /media/uploads/spookymelonhead/i2c_write.jpg /media/uploads/spookymelonhead/main.jpg /media/uploads/spookymelonhead/output.jpg

Code: https://github.com/spookymelonhead/Mini-STM32-v3.0/blob/master/STM32F103x-%20MPU6050.c

2 Answers

4 years, 5 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.

Accepted Answer

thanks dude..I guess I already knew that, foolish brains.

posted by Brian B 05 Feb 2016

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 Brian B 08 Feb 2016
4 years, 5 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);

I like things transparent and doing it own my own..Thanks anyway.

posted by Brian B 05 Feb 2016