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.
MPU9520 I2C comms
Moderator: Benj
-
- Flowcode v5 User
- Posts: 104
- Joined: Fri Oct 10, 2014 11:15 am
- Has thanked: 27 times
- Been thanked: 22 times
- Contact:
- 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
Hi Dave,
Please can you try this and hopefully it will work as expected.
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.
Please can you try this and hopefully it will work as expected.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Flowcode v5 User
- Posts: 104
- Joined: Fri Oct 10, 2014 11:15 am
- Has thanked: 27 times
- Been thanked: 22 times
- Contact:
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- 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
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.
set trisb1 and trisb4 (I2C pins) as inputs. All now working. Thanks for your help Benj.
-
- 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
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?
Thanks, Dave.
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?
Thanks, Dave.