MPU9520 I2C comms

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

Moderator: Benj

Dave Squibb
Flowcode v5 User
Posts: 73
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 14 times
Been thanked: 17 times
Contact:

MPU9520 I2C comms

Postby Dave Squibb » Fri May 04, 2018 3:55 pm

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 12 times

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

Re: MPU9520 I2C comms

Postby Benj » Fri May 04, 2018 5:38 pm

Hi Dave,

Please can you try this and hopefully it will work as expected.

MPU9250.fcfx
(11.33 KiB) Downloaded 26 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.
These users thanked the author Benj for the post:
Dave Squibb (Tue May 08, 2018 9:32 am)
Rating: 5.88%
 

Dave Squibb
Flowcode v5 User
Posts: 73
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 14 times
Been thanked: 17 times
Contact:

Re: MPU9520 I2C comms

Postby Dave Squibb » Fri May 04, 2018 5:52 pm

Hi Benj,
Still reading 255!
Dave.

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

Re: MPU9520 I2C comms

Postby Benj » Fri May 04, 2018 6:03 pm

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: 73
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 14 times
Been thanked: 17 times
Contact:

Re: MPU9520 I2C comms

Postby Dave Squibb » Fri May 04, 2018 6:24 pm

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.
These users thanked the author Dave Squibb for the post:
Benj (Tue May 08, 2018 4:48 pm)
Rating: 5.88%
 

Dave Squibb
Flowcode v5 User
Posts: 73
Joined: Fri Oct 10, 2014 11:15 am
Has thanked: 14 times
Been thanked: 17 times
Contact:

Re: MPU9520 I2C comms

Postby Dave Squibb » Tue Jun 12, 2018 5:29 pm

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) Not downloaded yet


Thanks, Dave.