Shop OBEX P1 Docs P2 Docs Learn Events
get data from l3g4200d with spi protocol — Parallax Forums

get data from l3g4200d with spi protocol

mohammadesmailimohammadesmaili Posts: 8
edited 2012-05-24 06:20 in Accessories
hello
i want to get data from l3g4200d with use spi protocol and i dont know what data i shoud send to sensor to get data.SDO port of sensor is always set.please tell me
what data i shoud send to sensor

Comments

  • ratronicratronic Posts: 1,451
    edited 2012-05-22 19:02
    mohmmadesmaili if you are talking about the Parallax module I have some Propeller code I came up with a time back that shows the approximate rate for each axis on the serial terminal. Also the raw axis data is available in the gx, gy, and gz variables. Welcome to the forum's can I call you mo?

    Edit: You will need to substitute your Propeller port#'s were they are commented in the main method - dio = sda, clk = scl, cs = cs on the module. Also you need to give it up to about 7 seconds before you see a display
  • mohammadesmailimohammadesmaili Posts: 8
    edited 2012-05-23 02:35
    thanks
    i use ARM micro and my code is in keil program. i cant read spin file.
    for example when i send 0xA1 to SDA port of sensor ,according to l3g4200d datasheet i shoud get data from XL register but i didnt get anythings.
  • ratronicratronic Posts: 1,451
    edited 2012-05-23 07:36
    Sorry mo I wont be able to help you with the Arm program. Just to let anybody know that might look at this program it is setup for 3 wire SPI. DIO (data in/out) = SDA on the module, CLK (clock) = SCL on the module, and CS (chip select) = CS on the module.

    In this program mo I send $81 to $23, $08 to $22, $0f to $20 to set it up then monitor $27 for bit 4 to go high (data is ready) then read $28 thru $2d to get axis data. I hope this helps mo.
  • mohammadesmailimohammadesmaili Posts: 8
    edited 2012-05-23 09:01
    hi ratronic
    i use spi with four wire
    according to datasheet if i want to get data from XL register i shoud send 0xA1(0X10100001).
    1-Bit 0: READ bit. The value is 1.
    2-Bit 1: MS bit. When 0, do not increment address; when 1, increment address in multiple
    reading.
    3-Bit 2-7: address AD(5:0). This is the address field of the indexed register.
    4-Bit 8-15: data DO(7:0) (read mode). This is the data that is read from the device (MSb first).
    i get this four note from datasheet. in note 3 said that we have six bit for address but the address of registers is 7 bit .do you underestand what mean that?
    another question is that if i want to use Multiple byte reading whate shoud i do?
  • ratronicratronic Posts: 1,451
    edited 2012-05-23 10:09
    mo with SPI you have to specify a register address to send data to. I get the part about setting things up for read/write or multiple read/writes as that is in my Propeller code. But I have no idea how to tell you to go about this with an ARM other than what values I send to the particular registers to set it up and what register I monitor for the data to be ready to read and the regisers I read the data from in post#4. The usable register addreses in the L3G4200D are $0f and $20 thru $38.

    Edit: This module can be used with four wire SPI. Also it is the register address that needs to be modified with the proper bits cleared/set for write/read and non increment/ increment address. Also the byte needs to have the bits in it be reversed as the chip normally expects the most significant bit first.
  • mohammadesmailimohammadesmaili Posts: 8
    edited 2012-05-23 13:48
    hi
    ratronic, in spi with 4 wire if i want to get data from OUT_XL register with 0x28 address, what data i shoud send to sensor?
  • ratronicratronic Posts: 1,451
    edited 2012-05-23 14:59
    Sorry mo I can't help you, you will need to refer back to the datasheet you quoted earlier, it describes SPI operation. If you were using a Propeller I could describe exactly how my program works. In case you do not know how SPI operates I would look here.
  • ratronicratronic Posts: 1,451
    edited 2012-05-23 17:43
    mo I can tell you that to calculate the exact address # to send when reading the chip I take the real address in Propeller assembly and OR it with $80 or $C0 depending on whether I want to read a byte or multiple bytes, then reverse the bits in that byte before I start clocking it out to the chip. For writing a single byte you can take the real address # and only reverse the bits in that byte before clocking it out. Also remember that the chip normaly outputs the most significant bit first when reading. If you look carefully at your post#5 you will see that using this method all the bits will end up properly aligned for clocking out to the chip.
  • mohammadesmailimohammadesmaili Posts: 8
    edited 2012-05-24 06:20
    hi ratronic
    thanks alot for your information.
Sign In or Register to comment.