I2C MMA8452 Accelerometer


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Aug 2013
    Posts
    6

    Default I2C MMA8452 Accelerometer

    I connected to the I2C bus 4 chips that work perfect ,I can read and write without any problem,
    (2 x PCA9532 - LED drivers,MAX17043 - Fuel Gauge, DS1307 - RTC).but the MMA8452 returns only zeros.
    I tried slow ans high speeds,I2C_HOLD but failed.
    I use the PIC18F2553 at 48MHz
    The compiler is PBP 2.6
    Help,Please....

  2. #2
    Join Date
    Aug 2013
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    I read the datasheet and it says:"Single Byte ReadThe MMA8453Q has an internal ADC that can sample, convert and return sensor data on request. The transmission of an
    8-bit command begins on the falling edge of SCL. After the eight clock cycles are used to send the command, note that the data
    returned is sent with the MSB first once the data is received. Figure 11 shows the timing diagram for the accelerometer 8-bit I2C
    read operation. The Master (or MCU) transmits a start condition (ST) to the MMA8453Q, slave address ($1D), with the R/W bit
    set to “0” for a write, and the MMA8453Q sends an acknowledgement. Then the Master (or MCU) transmits the address of the
    register to read and the MMA8453Q sends an acknowledgement. The Master (or MCU) transmits a repeated start condition (SR)
    and then addresses the MMA8453Q ($1D) with the R/W bit set to “1” for a read from the previously selected register. The Slave
    then acknowledges and transmits the data from the requested register. The Master does not acknowledge (NAK) the transmitted
    data, but transmits a stop condition to end the data transfer."
    How can I send a repeated start?

  3. #3
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    Quote Originally Posted by emf985 View Post
    but the MMA8452 returns only zeros.
    I assume that you are using a different address for every device. Isolate the MMA8452 and try to communicate with it first.
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  4. #4
    Join Date
    Aug 2013
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    Thanks
    Yes,of course ,the problem, as I see it , is that the pbp cannot produce a repeated start .
    I used a logic analizer -----> the accelerometer sends acknowlage signals.
    the data sheet demands an Sr (repeat start) in order to read the device.
    the device resets the address register to zero if the master sends a STOP.
    I can read only the top seven registers only.(there are a lot of registers).

  5. #5
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer


  6. #6
    Join Date
    Aug 2013
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    Thanks,I read it,( there is no part 2) .
    I used PBP I2CREAD and I2CWRITE instructions .
    Maby there is something to be done with the instructions we have,I hope I'll not be forced to write new I2C subrutines just for this device.(hopefully somone did write it)

  7. #7
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    This is I2C write:
    GOSUB INT_ROM
    SHIFTOUT DPIN,CPIN,1,[DATO\8,%1\1]
    GOSUB STOP_ROM

    I2CREAD:
    GOSUB INT_ROM
    GOSUB START_ROM
    SHIFTOUT DPIN,CPIN,1,[CONT1]
    SHIFTIN DPIN,CPIN,0,[ACK\1,DATI\8]
    SHIFTOUT DPIN,CPIN,1,[%1\1]
    GOSUB STOP_ROM

    This is start sequence:
    START_ROM:
    HIGH CPIN:HIGH DPIN:LOW DPIN:RETURN

    Every thing is already done...

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


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    I have a LSM330DLC accelerometer set up with a PIC18F14K50 but used the MSSP hardware module for the I2C. What a workout!
    This device also calls for the "Repeated Start Condition" when reading a register.

    Unfortunately, I am using PBPX 3.0. So can't say if this works the same as your version.

    After playing around with the I2CREAD a little bit, was surprised to find that the READ statement supplied everything to read the "WHO AM I" register of the Gyro with just the I2CREAD statement.

    Gyro info:
    Write address = $D6
    Read address = $D7
    Device ID register located at $0F should contain $D4

    This code provided the following as seen on the screen capture:
    • Start condition (1st Green dot)
    • Write to address $D6 to Read register $0F
    • Inserts the "Repeated Start Condition" (SR), (2nd Green dot)
    • Then the Read address $D7 followed with the clocked in Gyro register data value $D4
    Code:
    MAIN:
        I2CREAD SDA,SCL,$D7,$0F,[Mem_data]             
        PAUSEUS 100     ' A little pause to visually seperate on display
    GOTO MAIN
    Name:  I2C Read.jpg
Views: 1371
Size:  81.4 KB


    I learned something new today. Hope this helps.
    Louie

  9. #9
    Join Date
    Aug 2013
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    I have pbp 2.6 (by the way ,is it worth upgrading?)
    my code is like this:
    '
    'The WHO_AM_I register is factory set to $3A
    '
    I2CWRITE IICData,IICScl,$3A,[$0D],IICFail 'WHO_AM_I register address = $D
    I2CREAD IICData,IICScl,$3B,[STR a\7],IICFail 'Fails to read, it reads only the first 7 bytes .... after STOP the counter
    I'm going to try your way
    thanks

  10. #10
    Join Date
    Aug 2013
    Posts
    6


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    YES!!! IT WORKS!!!
    I didn't know that the register address to read can be set in I2CREAD. I used ,by mistake I2CWRITE to set the address of the register and then read it.
    This is also new to me

  11. #11
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    Quote Originally Posted by emf985 View Post
    I have pbp 2.6 (by the way ,is it worth upgrading?)
    That's another topic. It is discussed here

    PBP 3.0 really needed?
    http://www.picbasic.co.uk/forum/showthread.php?t=16234
    "No one is completely worthless. They can always serve as a bad example."

    Anonymous

  12. #12
    Join Date
    Sep 2007
    Location
    Waco, Texas
    Posts
    151


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    LinkMTech-
    I am just now workiing with a LSM330DLC myself on a PIC18F66J11 and also PBP3.
    Was wondering if I get stuck on how to set it up, read data, etc if you wouldn't mind giving me some pointers?
    I plan on using I2C interface (I think its easier) and I planned on using DT's interrupt (sure miss that Guy) and reading from it.
    I am working the schematic now and will have a test board made in a few days.
    You can PM if you like.

    Regards,
    Steve
    "If we knew what we were doing, it wouldn't be called research"
    - Albert Einstein

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


    Did you find this post helpful? Yes | No

    Default Re: I2C MMA8452 Accelerometer

    Hi Steve,

    Sure I'll help you out. My project works but on the shelf for now.
    Got your PM.

    Louie
    Louie

Similar Threads

  1. 3-Axis Accelerometer (LIS302DL)
    By Gusse in forum Code Examples
    Replies: 20
    Last Post: - 28th January 2013, 04:20
  2. Accelerometer reading
    By joseph Degorio in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th February 2011, 11:43
  3. accelerometer question
    By griffin in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th February 2009, 21:00
  4. Accelerometer Sensor
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 27th August 2008, 13:26
  5. Adxl213ae Accelerometer
    By DougB in forum mel PIC BASIC
    Replies: 0
    Last Post: - 25th July 2005, 21:32

Members who have read this thread : 0

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

Posting Permissions

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