Tool/software: Code Composer Studio
Hello,
This Problem is related to the GY80 sensor i.e L3GH200D Gyrometer . My problem is that , in output all the register values are same . Please check my program.
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
/* Driver Header files */
#include <ti/drivers/GPIO.h>
#include <ti/drivers/I2C.h>
#include <ti/display/Display.h>
#include <xdc/runtime/system.h>
/* Example/Board Header files */
#include "Board.h"
#define TASKSTACKSIZE 640
#define DATAX0 0x28 /*X-Axis Data 0 */
#define DATAX1 0x29 /*X-Axis Data 1 */
#define DATAY0 0x2A /*Y-Axis Data 0 */
#define DATAY1 0x2B /*Y-Axis Data 1 */
#define DATAZ0 0x2C /*Z-Axis Data 0 */
#define DATAZ1 0x2D /*Z-Axis Data 1 */
#define DEVID 0x0F /* Device address */
#define PCR 0x20 /* power controlled register*/
#define SNS 0x23 /* Sensitivity and scale selection*/
static Display_Handle display;
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
//int x,y,z,i;
//float x_out,y_out,z_out;
uint8_t txBuffer[10];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();
/* Open the HOST display for output */
display = Display_open(Display_Type_UART, NULL);
if (display == NULL) {
while (1);
}
/* Turn on user LED */
GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);
Display_printf(display, 0, 0, "Starting the i2ctmp007 example\n");
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
if (i2c == NULL) {
Display_printf(display, 0, 0, "Error Initializing I2C\n");
while (1);
}
else {
Display_printf(display, 0, 0, "I2C Initialized!\n");
}
{
txBuffer[0]=0x20;/* CTRL_REG1 - Power Mode */
txBuffer[1]=0x8F; /* Normal mode: 400Hz ,00 bw, - 01001111b */
i2cTransaction.slaveAddress = (0x69); /* I2C address*/
//two byes are going to be sent when doing a single byte write (Register + Value)
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
//No reply from the slave when doing a write, no need for a buffer
i2cTransaction.readBuf = NULL;
i2cTransaction.readCount = 0;
}
{
txBuffer[0]=0x23; /* CTRL_REG4 - Sensitivity, Scale Selection */
txBuffer[1]=0x30; /* 2000dps: 48d - 00110000b */
i2cTransaction.slaveAddress = (0x69);
//two byes are going to be sent when doing a single byte write (Register + Value)
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
//No reply from the slave when doing a write, no need for a buffer
i2cTransaction.readBuf = NULL;
i2cTransaction.readCount = 0;
}
if (I2C_transfer(i2c, &i2cTransaction))
{
i2cTransaction.slaveAddress = (0x69);
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 2;
i2cTransaction.readBuf = txBuffer;
i2cTransaction.readCount = 10;
txBuffer[0]=0x0f; /* Device address*/
txBuffer[1]=0x28; /* x_l axis */
txBuffer[2]=0x29;/* x_h axis */
txBuffer[3]=0x2A;/* y_l axis */
txBuffer[4]=0x2B;/* y_h axis */
txBuffer[5]=0x2C;/* z_l axis */
txBuffer[6]=0x2D;/* z_h axis */
if (I2C_transfer(i2c, &i2cTransaction))
{
Display_printf(display,0,0,"%x : %x",txBuffer[0],txBuffer[1]);
Display_printf(display,0,0,"%x : %x",txBuffer[2],txBuffer[3]);
Display_printf(display,0,0,"%x : %x",txBuffer[4],txBuffer[5]);
Display_printf(display,0,0,"%x : %x",txBuffer[6],txBuffer[7]);
Display_printf(display,0,0,"%x : %x",txBuffer[8],txBuffer[9]);
}
else
{
Display_printf(display, 0, 0, "I2C Bus fault\n");
}
}
else
{
Display_printf(display, 0, 0, "I2C Bus fault\n");
}
/* Sleep for 1 second */
sleep(1);
/* Deinitialized I2C */
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!\n");
return (NULL);
}
the ouput of my program is