Other Parts Discussed in Thread: CC1310
Tool/software: Code Composer Studio
Hi ,
I'm interfacing GY521 with the CC1310LP using I2C(DIO 4&5).
I have imported i2ctmp116 and modified.
Accelerometer and Gyro Sens values are reading zero all the time.
Trying to read Accelerometer(x,y,z) Temperature, Gyro Values(x,y,z) from GY521 but returning values- zero.[I'm able to run the example code i2ctmp116]
Here is my modified code ...
/* 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
/* TMP116 DIE Temp Result Register */
//#define TMP116_DIE_TEMP 0x0000
#define GY521_MPU6050 0x0000
/* TMP116 I2C Slave Address */
//#ifdef Board_I2C_TMP116_ADDR
//#define TMP116_ADDR Board_I2C_TMP116_ADDR
//#else
//#define TMP116_ADDR 0x48
//#endif
//static Display_Handle display;
#ifdef Board_I2C_GY521_ADDR
#define GY521_MPU6050_ADDR Board_I2C_GY521_MPU6050_ADDR
#else
#define GY521_MPU6050_ADDR 0x68 //0x69 AD=1
#endif
static Display_Handle display;
/*
* ======== mainThread ========
*/
char tmp_str[7]; // temporary variable used in convert function
char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
printf(tmp_str, "%6d", i);
return tmp_str;
}
void *mainThread(void *arg0)
{
uint16_t sample;
//uint16_t temperature;
//uint8_t txBuffer[1];
//uint8_t rxBuffer[2];
uint16_t AcX, AcY, AcZ, GyX, GyY, GyZ, TMP;
float Temperature;
uint8_t txBuffer[1];
uint8_t rxBuffer[14];
I2C_Handle i2c;
I2C_Params i2cParams;
I2C_Transaction i2cTransaction;
char x,y,z,X,Y,Z,T;
/* Call driver init functions */
Display_init();
GPIO_init();
I2C_init();
/* Configure the LED and if applicable, the TMP116_EN pin
GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
#ifdef Board_GPIO_TMP116_EN
GPIO_setConfig(Board_GPIO_TMP116_EN, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_HIGH);
/* 1.5 ms reset time for the TMP116
sleep(1);
#endif */
/* 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 i2ctmp116 example\n");
/* Create I2C for usage */
I2C_Params_init(&i2cParams);
i2cParams.bitRate = I2C_400kHz;
i2c = I2C_open(Board_I2C_TMP, &i2cParams);
//i2c = I2C_open(Board_I2C_TMP, &i2cParams);
//i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SDA0, &i2cParams);
//i2c = I2C_open(CC1310_LAUNCHXL_I2C0_SCL0 , &i2cParams);
if (i2c == NULL) {
Display_printf(display, 0, 0, "Error Initializing I2C\n");
while (1);
}
else {
Display_printf(display, 0, 0, "I2C Initialized!\n");
}
/* Point to the die tempature register and read its 2 bytes */
//txBuffer[0] = TMP116_DIE_TEMP;
//i2cTransaction.slaveAddress = TMP116_ADDR;
//i2cTransaction.writeBuf = txBuffer;
//i2cTransaction.writeCount = 1;
//i2cTransaction.readBuf = rxBuffer;
//i2cTransaction.readCount = 2;
txBuffer[0] = 0x3B;
i2cTransaction.slaveAddress = 0x68;
i2cTransaction.writeBuf = txBuffer;
i2cTransaction.writeCount = 1;
i2cTransaction.readBuf = rxBuffer;
i2cTransaction.readCount = 14;
/* Take 20 samples and print them out onto the console */
for (sample = 0; sample < 20; sample++) {
if (I2C_transfer(i2c, &i2cTransaction)) {
/* Extract degrees C from the received data; see TMP116 datasheet */
//temperature = (rxBuffer[0] << 8) | (rxBuffer[1]);
//temperature *= 0.0078125;
AcX = (rxBuffer[0] <<8) | (rxBuffer[1]);
AcY = (rxBuffer[2] <<8) | (rxBuffer[3]);
AcZ = (rxBuffer[4] <<8) | (rxBuffer[5]);
TMP = (rxBuffer[6] <<8) | (rxBuffer[7]);
GyX = (rxBuffer[8] <<8) | (rxBuffer[9]);
GyY = (rxBuffer[10] <<8) | (rxBuffer[11]);
GyZ = (rxBuffer[12] <<8) | (rxBuffer[13]);
//TMP *= 0.0078125;
Temperature =(TMP/340.00)+36.53;
Display_printf(display, 0, 0, "Temperature value is : %f \n",Temperature);
Display_printf(display, 0, 0, "Acx is : %d \n",AcX);
x = convert_int16_to_str(AcX);
y = convert_int16_to_str(AcY);
z = convert_int16_to_str(AcZ);
X = convert_int16_to_str(GyX);
Y = convert_int16_to_str(GyY);
Z = convert_int16_to_str(GyZ);
//System_printf("Acclerometer Values are %d,%d, %d \n",AcX,AcY,AcZ);
}
/*
* If the MSB is set '1', then we have a 2's complement
* negative value which needs to be sign extended
*/
/* if (rxBuffer[0] & 0x80) {
temperature |= 0xF000;
}
Display_printf(display, 0, 0, "Sample %u: %d (C)",
sample, temperature);
}
else {
Display_printf(display, 0, 0, "I2C Bus fault.");
}
/* Sleep for 1 second */
sleep(1);
}
I2C_close(i2c);
Display_printf(display, 0, 0, "I2C closed!");
return (NULL);
}
