Shop OBEX P1 Docs P2 Docs Learn Events
I2C Interfacing — Parallax Forums

I2C Interfacing

SRLMSRLM Posts: 5,045
edited 2012-09-18 20:00 in Propeller 1
I am trying to interface to L3GD20 gyro over the Pololu MinIMU-9v2.

I want to get the Propeller to communicate with the gyro over the I2C lines.

My connections to the module are fairly simple. I have SCL in pin 23, SDA on pin 24, VIN to 3.3v, and GND to ground. I've tried it with and without additional 10K pullups on the SCL/SDA lines, and 3.3v connected to VDD. No changes in functionality were observed.

The problem: My requests for the WHO_AM_I register are not always successful when I expect the same answer every time I call it.

Here is the console output:
MESSAGE: 0,'Starting...'
MESSAGE: 3,'No gyro acknowledge (sending SAD+W).'
MESSAGE: 7,'No gyro acknowledge (sending SUB).'
MESSAGE: 10,'No gyro acknowledge (sending SAD+R).'
MESSAGE: 14,'Gyro WHO_AM_I: %11111111, %11010100 (read, default)'
MESSAGE: 1279,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
MESSAGE: 2545,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
MESSAGE: 3810,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
MESSAGE: 5037,'No gyro acknowledge (sending SAD+W).'
MESSAGE: 5050,'No gyro acknowledge (sending SUB).'
MESSAGE: 5073,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
MESSAGE: 6339,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
MESSAGE: 7570,'No gyro acknowledge (sending SAD+W).'
MESSAGE: 7583,'No gyro acknowledge (sending SUB).'
MESSAGE: 7588,'No gyro acknowledge (sending SAD+R).'
MESSAGE: 7593,'Gyro WHO_AM_I: %11111111, %11010100 (read, default)'
MESSAGE: 8828,'Gyro WHO_AM_I: %00000000, %11010100 (read, default)'
MESSAGE: 10074,'Gyro WHO_AM_I: %00000000, %11010100 (read, default)'
MESSAGE: 11320,'Gyro WHO_AM_I: %00000000, %11010100 (read, default)'
MESSAGE: 12547,'Done with I2C tests.'

I pulled out my Logic16 analyzer, and I got the attached traces. It's a bit large for one screen shot, so I took several.
Overview - This shows all the signals over the test. On the SCL line on the left is a small dip: this is when the Propeller reset. 1 second later the i2c.Initialize routine was called (no change in output), and .3 seconds after that the first i2c communications attempt was made.
Attempt 1 - The first attempt to get the WHO_AM_I register, and a failure. This shows the first transaction (sending the 1101011+0 address)
Attempt 1b - Shows the entire 1 transaction sequence (and the Logic16 interpretation of what's happening on the I2C bus)
Attempt 2 - Shows a successful transaction

It appears that the SCL line is incorrectly being toggled at a fairly slow rate (1.3kHz), when it should be held high during non-transaction times.

My question: what am I missing here, and what needs to be fixed? Thank you.

Edit: added .zip with the images in it (forum software automatically downsized the screenshots).
1024 x 161 - 24K
1024 x 161 - 27K
1024 x 161 - 27K
1024 x 161 - 25K

Comments

  • D.PD.P Posts: 790
    edited 2012-09-13 18:57
    SRLM wrote: »
    I am trying to interface to L3GD20 gyro over the Pololu MinIMU-9v2.

    I want to get the Propeller to communicate with the gyro over the I2C lines.

    My connections to the module are fairly simple. I have SCL in pin 23, SDA on pin 24, VIN to 3.3v, and GND to ground. I've tried it with and without additional 10K pullups on the SCL/SDA lines, and 3.3v connected to VDD. No changes in functionality were observed.

    The problem: My requests for the WHO_AM_I register are not always successful when I expect the same answer every time I call it.

    Here is the console output:
    MESSAGE: 0,'Starting...'
    MESSAGE: 3,'No gyro acknowledge (sending SAD+W).'
    MESSAGE: 7,'No gyro acknowledge (sending SUB).'
    MESSAGE: 10,'No gyro acknowledge (sending SAD+R).'
    MESSAGE: 14,'Gyro WHO_AM_I: %11111111, %11010100 (read, default)'
    MESSAGE: 1279,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
    MESSAGE: 2545,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
    MESSAGE: 3810,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
    MESSAGE: 5037,'No gyro acknowledge (sending SAD+W).'
    MESSAGE: 5050,'No gyro acknowledge (sending SUB).'
    MESSAGE: 5073,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
    MESSAGE: 6339,'Gyro WHO_AM_I: %11010100, %11010100 (read, default)'
    MESSAGE: 7570,'No gyro acknowledge (sending SAD+W).'
    MESSAGE: 7583,'No gyro acknowledge (sending SUB).'
    MESSAGE: 7588,'No gyro acknowledge (sending SAD+R).'
    MESSAGE: 7593,'Gyro WHO_AM_I: %11111111, %11010100 (read, default)'
    MESSAGE: 8828,'Gyro WHO_AM_I: %00000000, %11010100 (read, default)'
    MESSAGE: 10074,'Gyro WHO_AM_I: %00000000, %11010100 (read, default)'
    MESSAGE: 11320,'Gyro WHO_AM_I: %00000000, %11010100 (read, default)'
    MESSAGE: 12547,'Done with I2C tests.'
    

    I pulled out my Logic16 analyzer, and I got the attached traces. It's a bit large for one screen shot, so I took several.
    Overview - This shows all the signals over the test. On the SCL line on the left is a small dip: this is when the Propeller reset. 1 second later the i2c.Initialize routine was called (no change in output), and .3 seconds after that the first i2c communications attempt was made.
    Attempt 1 - The first attempt to get the WHO_AM_I register, and a failure. This shows the first transaction (sending the 1101011+0 address)
    Attempt 1b - Shows the entire 1 transaction sequence (and the Logic16 interpretation of what's happening on the I2C bus)
    Attempt 2 - Shows a successful transaction

    It appears that the SCL line is incorrectly being toggled at a fairly slow rate (1.3kHz), when it should be held high during non-transaction times.

    My question: what am I missing here, and what needs to be fixed? Thank you.

    Edit: added .zip with the images in it (forum software automatically downsized the screenshots).

    Please try rewriting your object using this driver. I have had great luck getting recalcitrant chips talking to the prop with this. Hat tip to JonnyMac!
    http://obex.parallax.com/objects/528/
  • ChrisGaddChrisGadd Posts: 310
    edited 2012-09-13 19:11
    That L3GD20 appears functionally identical to the L3G4200D gyroscope used in the Parallax gyroscope module. There's a program in the object exchange, which I used to develop this Gyroscope demo.zip.

    The only screwy thing about reading the gyro is that bit-7 needs to be set in the address in order to perform a page read, other than that I didn't have any problems. I used pins 28 and 29 shared with the EEPROM, with 4.7Kohm pull ups.

    Edited to add: I just noticed that the D20 has a different address than the 4200D, and the SDO pin can change the address still further. Is your SDO pin tied to Vdd?
  • D.PD.P Posts: 790
    edited 2012-09-17 12:54
    Hey SLRM

    Were you ever able to get your module to talk I2C correctly? I banged my head _allot against this sensor: http://www.co2meter.com/collections/co2-sensors/products/k-30-co2-sensor-module trying to get it to talk to the prop correctly. I used my logic analyzer and had the timing the same as the Ardrunio example, it turned out to be a couple of randomly placed "NOPs" that did the magic in the driver I sent a link to. The vendor can't explain it either. Curious mind and all since I've been down that road with I2C and the prop as well. Noticed that you sent the link to JM's driver to another I2C question so I posted this.
  • SRLMSRLM Posts: 5,045
    edited 2012-09-18 20:00
    Hi Dp, I did manage to get my issue solved. Turns out that it was an interaction with the counters, unrelated to the I2C code. In the end, I've decided to go with the I2C driver that Chris linked to, for two reasons: it's written in PASM, and it's very modular so that I can modify my own routines. The downside is that it's poorly documented, so I didn't recommend it for a beginner.

    For your CO2 sensor it looks like the maximum rate is 100kbit/sec. Most I2C devices support up to 400kbit/second (fast mode) or faster, so I suspect that the drivers were meant to go as fast as possible.
Sign In or Register to comment.