Part Number: LAUNCHXL-F28069M
Other Parts Discussed in Thread: MOTORWARE
Hi,
I'm using gyro sensor MPU-6050 https://www.invensense.com/wp-content/uploads/2015/02/MPU-6000-Register-Map1.pdf
In my code I try to request data of gyro readings at 0x3B, and 0x3C registers, but program always stuck in line:
while(I2caRegs.I2CSTR.bit.RRDY == 0){}; //I2CDRR not ready to read?
It means data has not been copied from I2CRSR to I2CDRR, but I dont have idea why.
Could you check my code please?
#include "DSP28x_Project.h"
#include <stdio.h>
Uint16 PassCount;
Uint16 FailCount;
Uint16 Data[]={0x6B,0x3B};
Uint16 RxdData[10];
void main(void)
{
// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2806x_SysCtrl.c file.
//
InitSysCtrl();
//
// Setup only the GP I/O only for I2C functionality
//
InitI2CGpio();
//
// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
//
DINT;
//
// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the F2806x_PieCtrl.c file.
//
InitPieCtrl();
//
// Disable CPU interrupts and clear all CPU interrupt flags
//
IER = 0x0000;
IFR = 0x0000;
//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2806x_DefaultIsr.c.
// This function is found in F2806x_PieVect.c.
//
InitPieVectTable();
PassCount = 0;
FailCount = 0;
//
// Enable interrupts required for this example
//
//
// Enable I2C interrupt 1 in the PIE: Group 8 interrupt 1
//
PieCtrlRegs.PIEIER8.bit.INTx1 = 1;
//
// Enable CPU INT8 which is connected to PIE group 8
//
IER |= M_INT8;
EINT;
//////////////////////////
// Write data to EEPROM //
//////////////////////////
I2caRegs.I2CSAR = 0x68; //Set slave address
I2caRegs.I2CCNT = 2; //Set count to 5 characters plus 2 address bytes
I2caRegs.I2CDXR = 0x6B; //register where i will write 0x40 (reset)
I2caRegs.I2CMDR.bit.TRX = 1; //Set to Transmit mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 1; //Stop when internal counter becomes 0
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CDXR = 0x40;
for(i = 0; i < 3; i++){
RxdData[i] = 0x00;
}
for(;;)
{
//////////////////////////
// Read data from EEPROM//
//////////////////////////
//while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CSAR = 0x68; //Set slave address
I2caRegs.I2CCNT = 1; //Set count to 2 address bytes
I2caRegs.I2CDXR = 0x3B; //Send high address of register to read
I2caRegs.I2CMDR.bit.TRX = 1; //Set to Transmit mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 0; //Dont release the bus after Tx
I2caRegs.I2CMDR.bit.STT = 1; //Send the start bit, transmission will follow
while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
//I2caRegs.I2CDXR = 0x3B; //Send low address of register to read
//while(I2caRegs.I2CSTR.bit.XRDY == 0){}; //Do nothing till data is shifted out
I2caRegs.I2CCNT = 2; //read 5 bytes from eeprom
I2caRegs.I2CMDR.bit.TRX = 0; //Set to Recieve mode
I2caRegs.I2CMDR.bit.MST = 1; //Set to Master mode
I2caRegs.I2CMDR.bit.FREE = 1; //Run in FREE mode
I2caRegs.I2CMDR.bit.STP = 1; //Stop when internal counter becomes 0
I2caRegs.I2CMDR.bit.STT = 1; //Repeated start, Reception will follow
for(i = 0; i < 2; i++){
while(I2caRegs.I2CSTR.bit.RRDY == 0){}; //I2CDRR not ready to read? program stuck here in endless loop
RxdData[i] = I2caRegs.I2CDRR;
PassCount++;
}
}
}