Gyro L3G4200D Code Request


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default Re: Gyro L3G4200D Code Request

    Hi Louie,

    The 18F is jumpered in to the LABX1 and running fine. I set the OSC to run at 32Mhz. I am debugging with SEROUT2 command.

    It appears that I am getting ACK from the Gyro because I am getting a debug statement out just after the "WHILE SSPCON2.6 : WEND.

    I am freezing up though at "WHILE !SSPSTAT.0 : WEND". So I am not seeing any data out yet.

    Here is that code segment along with my SEROUT2 Debug Statements in that section.

    FOR e = 6 TO 11

    SEROUT2 PORTB.7,84,[" READ GYRO ",10,10]
    ' Receive the 8 bit data from gyroscope
    SSPCON2.3 = 1 ' Enable the Receiver to clock in data
    WHILE !SSPSTAT.0: WEND ' Wait until Buffer Full bit is set
    XYZ_RAM[e] = SSPBUF ' Load each XYZ_RAM byte in array

    SEROUT2 PORTB.7,84,[" XYZ_RAM ",DEC XYZ_RAM[E],10,10]
    ' Master sends ACK for first 5 data packets
    IF e != 11 THEN
    SSPCON2.4 = 1 ' Initiate Acknowledge sequence
    WHILE SSPCON2.4 = 1: WEND ' Wait until Acknowledge sequence Idle
    ENDIF
    NEXT e

    Again your help is very much appreciated.

    Fritz

  2. #2
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Gyro L3G4200D Code Request

    Hey Fritz,

    Cool project, close to the crash sensor I was working on.

    It sounds as though there's nothing in the buffer to give, causing it to stay there. Now what would keep the gyro from actually working? CTRL_REG1 bits 2:0 enable/disable the 3 axes.

    Busy looking at datasheet.....

    Do you get an interrupt output signal at DRDY or INIT indicating the device is updating?

    Edit:
    I looked at the code I provided and noticed that I stopped using the INT1 and DRDY outputs, bits 7 and 3. So you'll have to set these in order to verify data updates.
    Besides the typos, I see a few discrepancies within the comments and actual SSPBUF values so confirm what you need to use, sorry about that.
    Code:
    ' Load CTRL_REG3: 10000000, INT1_G enabled, no Boot Status, Active High,
    ' Push-pull output. INT2_G disabled
    GOSUB Start_Gyr        ' Adresss the device
    SSPBUF = $22           ' Transmit register address
    WHILE SSPSTAT.2: WEND  ' Wait until MSSP module finishes task
    SSPBUF = %00000000     ' Transmit the 8bit data to register
    WHILE SSPSTAT.2: WEND  ' Wait until MSSP module finishes task
    PIR1.3 = 0             ' Clear interrupt flag
    GOSUB Stop_I2C         ' Complete TX data
    Last edited by LinkMTech; - 6th March 2015 at 01:58. Reason: More info
    Louie

Similar Threads

  1. am I being rude to ask this. . .ASM code request
    By camcompco in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 11th March 2013, 11:54
  2. 16F877A and Gyro algorithm question
    By Macgman2000 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 22nd February 2012, 22:21
  3. A Defines Request
    By Kirk Fraser in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 31st March 2011, 22:23
  4. How to tell there is a serial request
    By cncmachineguy in forum Serial
    Replies: 4
    Last Post: - 21st November 2010, 21:14
  5. Code request....18f2550 usb/serial
    By f_lez in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st November 2009, 13:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts