L3G4200D SPI / I2C Drivers

Hello,

I am trying to develop a high-speed driver for the L3G4200D gyro. I have tried using multiple SPI example codes, but none of them work - it is possible my wiring is suspect. Does anyone know of any tried and true spin SPI drivers for this gyro? I2C works, but is too slow. I am also trying to translate the Parallax I2C example code for the driver into PASM, but I think that it will run so fast that the gyro won't be able to keep up.

For example:

This will take a few thousand clock cycles, whereas,
PRI stop ' 3 Stack Longs

  dira[SCLpin]         := false
  dira[SDApin]         := false


This will only take 8!
L3G4200D_stop
                        and     dira,           SCL_Inv_Mask
                        and     dira,           SDA_Inv_Mask
L3G4200D_stop_ret       ret

Will this work regardless, and if not how should I sync this code to handle normal I2C speeds?


I am attaching my current (in progress) I2C code as well.


Comments

  • 1 Comment sorted by Date Added Votes
  • You have to insert delays (using WAITCNT instructions) whenever you change SCL or SDA to keep to I2C's limits of 100KHz or 400KHz (depending on the device's specification).

    If you're interested, you could download FemtoBasic from the OBEX and look at sdspiFemto.spin. This is a driver for arbitrary (mostly EEPROM) I2C devices and SD cards (SPI memory devices). It can switch between 100KHz and 400KHz I2C devices. It may give you some ideas.

    Even though you show L3G4200D_stop as a PASM subroutine, you can't call that from Spin. sdspiFemto.spin launches a new cog containing the actual PASM I/O driver. The Spin interface code communicates with the new cog via a shared command/status area (2 longs in size). You'd have to do something similar.
Sign In or Register to comment.