I2C Interfacing
SRLM
Posts: 5,045
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:
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).
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).
Comments
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/
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?
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.
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.