MPU6050: FIFO read issue

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i am trying to get the values of accelerometer data from from mpu6050{I2C Communication},if i read the respective registers byte by byte i am able to get data{polling mode} ,but when i am using the burst feature i.e reading data from the fifo buffer of MPU6050 it is giving me all zero values.even the status flag showing buffer overflow is also set.i am interfacing it with Atmega 16.my questions are 1. how to read data from fifo of mpu6050 in interrupt mode? 2. where will the interrupt will come as TWI interrupt or at the INT pin of mpu6050? below is the code that i am using.here just to read values i was reading the buffer overflow flag when it is set i programmed it to start reading the buffer values.but i want to make it work with interrupt mode.

 

int main()
{

    I2C_Init();                                         /* Initialize I2C */
    Gyro_Init();                                        /* Initialize Gyro */
    USART_Init(9600);                                   /* Initialize USART with 9600 baud rate */
    //DDRB=0xff;
    //TWCR=0X00;
    //sei();
    //GICR|=(1<<INT0);
    //MCUCR|=((1<<ISC01)|(1<<ISC00));
    //TWCR|= ((1<<TWIE)|(1<<TWEN)|(1<<TWINT));
    // I2C_Start_Wait(0xD0);
    while(1)
    {

    I2C_Start_Wait(0xD0);
    I2C_Write(INT_STATUS);
    I2C_Repeated_Start(0xD1);
    //value2 = (I2C_Read_Ack()<<8);
    value1=I2C_Read_Ack();
    //value2=value2|value1;

    I2C_Stop();
    TWCR=0x00;

    if(value1==0x11)
    {
    I2C_Start_Wait(0xD0);
    I2C_Write(FIFO_R_W);
    I2C_Repeated_Start(0xD1);
     for (i=0;i<200;i++)
     {
         Acc_x=I2C_Read_Ack();
         raw_data[i]=Acc_x;
     }

     I2C_Stop;
     TWCR=0x00;

     }
     }

    }

void Gyro_Init()                                        /* Gyro initialization function */
{
                                        /* Power up time >100ms */
    I2C_Start_Wait(0xD0);                               /* Start with device write address */
    I2C_Write(SMPLRT_DIV);                  /* Write to sample rate register */
    I2C_Write(0x07);                                    /* 1KHz sample rate 07*/
    I2C_Stop();

    I2C_Start_Wait(0xD0);
    I2C_Write(PWR_MGMT_1);                              /* Write to power management register */
    I2C_Write(0x01);
    I2C_Stop();

    I2C_Start_Wait(0xD0);
    I2C_Write(CONFIG);                                  /* Write to Configuration register */
    I2C_Write(0x02);                                    /* Fs = 8KHz */
    I2C_Stop();

    I2C_Start_Wait(0xD0);
    I2C_Write(ACCEL_CONFIG);                    /* Write to Accelerometer Configuration register */
    I2C_Write(0x00);
    I2C_Stop();

    I2C_Start_Wait(0xD0);
    I2C_Write(FIFO_EN);                             /* Write to interrupt enable register Fifo interrupt*/
    I2C_Write(0x08);
    I2C_Stop();

    I2C_Start_Wait(0xD0);
    I2C_Write(INT_ENABLE);                              /*  Fifo  overflow interrupt enable */
    I2C_Write(0x10);
    I2C_Stop();

}

pranjal

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How to properly post source code: http://www.avrfreaks.net/comment...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

With I2c, when reading data from the slave you must read_nak() the last byte expected so the slave knows to release the bus so the master can stop() properly!

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OT:

How to properly post source code: http://www.avrfreaks.net/comment...

Actually, I rather like how the OP has posted code, although I'm not certain how he did it.  I notice that the code is wrapped in the following:

<pre style="margin-top: 0px; margin-bottom: 1em; padding: 5px;
border: 0px; font-variant-numeric: inherit; font-stretch: inherit;
font-size: 13px; line-height: inherit; font-family: Consolas,
Menlo, Monaco, &quot;Lucida Console&quot;, &quot;Liberation
Mono&quot;, &quot;DejaVu Sans Mono&quot;, &quot;Bitstream Vera
Sans Mono&quot;, &quot;Courier New&quot;, monospace, sans-serif;
vertical-align: baseline; width: auto; max-height: 600px; overflow:
auto; background-color: rgb(239, 240, 241); word-wrap: normal; color:
rgb(36, 39, 41);">
</pre>

If only the forum software had a good code editor, and a sensible colour scheme.

 

I might start using this myself.

 

 

/OT

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"Read a lot.  Write a lot."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

Last Edited: Thu. Sep 28, 2017 - 04:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:
Actually, I rather like how the OP has posted code, although I'm not certain how he did it.

Maybe it's copied from somewhere with its own formatting.

 

The indentation is a bit of a mess - but it's not clear if that's the OP's original mess, or a result of posting, or if following the instructions would have sabed it, or ...

 

If only this forum software had a good code editor, and a sensible colour scheme

Indeed!

 

angry