MMA7660FC Programming

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MMA7660FC Programming

Jump to solution
2,497 Views
torby
Contributor I

Must have something wrong here as any register I read from my MMA7660FC contains 255.

 

I'm using AVR processors, 'cause that's what I know, and Peter Fluery's vaunted I2c library. This is my first try at using I2C. It seems pretty nice, if I can make it work

 

If I try to start with the wrong slave address, I get no response. If I use the correct slave address, 0x4C << 1, I do get a response, so I suspect my test board is working.

 

So, in setting up my MMA7660FC, I first:

 

WriteMMA(MMA_SR,7); // 1 sample per second, no filter.

WriteMMA(MMA_INTSU,1); // Back/Front interrupt (which isn't hooked up)

 

My writeMMA method is:

void WriteMMA(uint8_t R, uint8_t V) // Write v into register R

{

i2c_start_wait(MMA+I2C_WRITE); // set device address and write mode

i2c_write(R); // Register to write

i2c_write(V); // Value to write

i2c_stop();

}

 

Then, I loop, reading the tilt register and displaying it whenever it changes.

 

while(1)

  {

uint8_t X = ReadMMA(MMA_TILT) ; // Read the x register

if (oX != X)

{

oX = X;

j += 1;

LCDclear();

ShowByte(j);

LCDxy(0,1);

ShowByte(X);

}

  }

 

(Do you have [CODE] tags here?)

 

And, the ReadMMA method always gets me 255.

 

I've attached the source of the actual program.

 

 

I know the program is lame, but I generally don't write a complicated program doing something I don't know anything about until I've made something simple that I don't know anything about work.

 

Have I missed something in the setup?

Perhaps I'm misusing ack and nak while reading?

Perhaps my program is correct and my little test board is wonky?

 

(This is the second time I've tried soldering one of these "QFN" type things without any pins. I don't want to talk about the first try )

Original Attachment has been moved to: Torby.zip

Tags (1)
0 Kudos
Reply
1 Solution
1,930 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Tom,

Looking at your source code, I do not think that your ReadMMA function is correct. You are sending 0x99 ((0x4C << 1) | 0x01) at first, while a read from the MMA7660FC actually starts off by writing to it.

As shown in Figure 3 of the MMA7660FC data sheet, the message format for reading from the accelerometer is as follows:

1. Send a start sequence

2. Send 0x4C with the R/W bit low (0x98)

3. Send internal address of the register you want to read from

4. Send a start sequence again (repeated start)

5. Send 0x4C with the R/W bit high (0x99)

6. Read a data byte from MMA7660FC

7. [Optionally, read any further data bytes]

8. Send NAK and a stop sequence


Regards,

Tomas


View solution in original post

0 Kudos
Reply
2 Replies
1,931 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Tom,

Looking at your source code, I do not think that your ReadMMA function is correct. You are sending 0x99 ((0x4C << 1) | 0x01) at first, while a read from the MMA7660FC actually starts off by writing to it.

As shown in Figure 3 of the MMA7660FC data sheet, the message format for reading from the accelerometer is as follows:

1. Send a start sequence

2. Send 0x4C with the R/W bit low (0x98)

3. Send internal address of the register you want to read from

4. Send a start sequence again (repeated start)

5. Send 0x4C with the R/W bit high (0x99)

6. Read a data byte from MMA7660FC

7. [Optionally, read any further data bytes]

8. Send NAK and a stop sequence


Regards,

Tomas


0 Kudos
Reply
1,930 Views
torby
Contributor I

Oh. Cool. I was hoping for a "No, Dummy, you do it this way," type reply. Somehow I had in mind you had to write the address you wanted to read. (Too many things to learn at one time before I get a response.)

0 Kudos
Reply