Author Topic: L3GD20H Gyroscope Help (SPI)  (Read 3190 times)

0 Members and 1 Guest are viewing this topic.

Offline yash101Topic starter

  • Contributor
  • Posts: 48
  • Country: us
  • Sup there!
    • My Land
L3GD20H Gyroscope Help (SPI)
« on: May 14, 2015, 04:43:24 am »
I need help in getting my gyroscope to work. The datasheet is here:
http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00060659.pdf
My microcontroller is a Parallax Propeller. I am programming it in C (SimpleIDE) because I am a C/C++ programmer and it is first knowledge for me.

I am trying to figure out how to read the X, Y and Z data from this device. I have CS mapped to Pin 0, MISO mapped to Pin 1, MOSI to 2 and CLK to 3.

What would help my the most is if someone could help me understand how to read the data sheet and understand it.
I do not know if the communication is MSB first or LSB first. I do not know how to initialize this device. Nothing. I am unable to follow the datasheet and understand how to use it.

Thank You!
 

Offline agehall

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: se
Re: L3GD20H Gyroscope Help (SPI)
« Reply #1 on: May 14, 2015, 05:09:06 pm »
Looking at figure 3, I'd say it operates MSB.
 

Offline yash101Topic starter

  • Contributor
  • Posts: 48
  • Country: us
  • Sup there!
    • My Land
Re: L3GD20H Gyroscope Help (SPI)
« Reply #2 on: May 14, 2015, 05:26:24 pm »
Thanks. Also, how do I initialize the device and begin retrieving values?
I am initializing the CS and CLK pins. After that, what should I send it? 0b00000000 is what I am currently sending it because I do t know how to use it.
 

Offline agehall

  • Frequent Contributor
  • **
  • Posts: 383
  • Country: se
Re: L3GD20H Gyroscope Help (SPI)
« Reply #3 on: May 14, 2015, 07:56:17 pm »
Are you trying to use SPI or I2C? All you need to know is in chapter 5 and 6 of the data sheet, so you probably need to read up on those sections. They show exactly how you are supposed to transmit data to and from the device.

Everything seems to be register based (I have just skimmed the data sheet, so there could be more "advanced" options too) so basically you send a read read command to the device and then you read back the data in the following clock cycles.
 

Offline yash101Topic starter

  • Contributor
  • Posts: 48
  • Country: us
  • Sup there!
    • My Land
Re: L3GD20H Gyroscope Help (SPI)
« Reply #4 on: May 14, 2015, 10:12:12 pm »
I know, but I'm not able to understand the data sheet. Do you have any resource which will explain it step by step?
 

Offline FreddyVictor

  • Regular Contributor
  • *
  • Posts: 164
  • Country: gb
Re: L3GD20H Gyroscope Help (SPI)
« Reply #5 on: May 14, 2015, 10:30:17 pm »
Thanks. Also, how do I initialize the device and begin retrieving values?
I am initializing the CS and CLK pins. After that, what should I send it? 0b00000000 is what I am currently sending it because I do t know how to use it.
1st of all, take a look at some code like this (for Arduino): https://www.nordevx.com/content/l3gd20h-gyro
since arduino has SPI built-in, you'll need to replace the SPI.transfer() function with your own bit-banging one
an example is the bitbang() function here: http://hifiengineering.blogspot.co.uk/2013/07/bit-banging-serial-data-with-arduino.html

you'll need to set MOSI,SCK and CS as output and MISO as input pins (is that what you mean by initialize ?)

I would start by writing some simple code to read the WHO_AM_I register which should return 0b11010100 ( 212 )

TBH, SPI isn't too easy via bit-bang method (Propeller chip seems very basic !), since your chip has i2c, maybe try that instead ?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf