MPU9520 I2C comms

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 6.

Moderator: Benj

Post Reply
Dave Squibb
Flowcode v5 User
Posts: 104
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 27 times
Been thanked: 22 times
Contact:

MPU9520 I2C comms

Post by Dave Squibb »

Hello,
I am trying to communicate with an MPU9250 via I2C. I am using a PIC16F1827 as the I2C master and have an LCD display also connected. The MPU9250 address is 0x68 and the WHO_AM_I register is ox75 and should return 0x71 if communication is established. I can only read 255 (0xFF).
The SCL is connected to PORTB,4 and SDA to PORTB,1. I have 5K6 pullups on both.
I have not used I2C before. Would someone have a look at the code please?
Thanks, Dave.
MPU9250.fcfx
(7.34 KiB) Downloaded 252 times

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: MPU9520 I2C comms

Post by Benj »

Hi Dave,

Please can you try this and hopefully it will work as expected.
MPU9250.fcfx
(11.33 KiB) Downloaded 263 times
Your I2C addresses were not taking into account the Read Not Write bit that is added to the 7-bit address to make an 8-bit byte.

Dave Squibb
Flowcode v5 User
Posts: 104
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 27 times
Been thanked: 22 times
Contact:

Re: MPU9520 I2C comms

Post by Dave Squibb »

Hi Benj,
Still reading 255!
Dave.

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: MPU9520 I2C comms

Post by Benj »

Hi Dave,

Are you pulling the address pin low? If this pin is floating then it may be internally pulled up in which case the Write mode becomes 0xD2 and the Read mode becomes 0xD3.

Dave Squibb
Flowcode v5 User
Posts: 104
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 27 times
Been thanked: 22 times
Contact:

Re: MPU9520 I2C comms

Post by Dave Squibb »

Ok, found the problem. I put a scope on the clock and data lines and nothing was happening. I hadn't
set trisb1 and trisb4 (I2C pins) as inputs. All now working. Thanks for your help Benj.

Dave Squibb
Flowcode v5 User
Posts: 104
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 27 times
Been thanked: 22 times
Contact:

Re: MPU9520 I2C comms

Post by Dave Squibb »

Further to the above I am now trying to read the WHO_AM_I register for the magnetometer section.
The Magnetometer address is 0x0C and the WHO_AM_I register is 0x49 (should return 0x48).
As before I get 0xff. I have tried left shifting 0x0c one bit giving 0x18 write/ 0x19 read but that doesn't work either.
I have also initialised the MPU9250 to bypass mode.
I have included the modified code. Would someone have a look please?
MPU9250_Mag.fcfx
(8.7 KiB) Downloaded 229 times
Thanks, Dave.

Post Reply