Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 9 months ago.
AUX i2c Connection with the MPU-3050
Hey everyone,
I am using this accelerometer with an MPU-3050 and trying to get the external connection to work.
http://www.seeedstudio.com/depot/Grove-3Axis-Digital-Accelerometer400g-p-1897.html
It seems like I am able to read and write to/from the registers based on the output I'm getting, but the acceleration values make no sense.
Assume that includes and initializations have been made. & paddr = (0x18 << 1)
void InitializeAccelerometer() { char value[5]; value[0] = 0x7F; I2C_Write(paddr, H3LIS331DL_CTRL_REG1, value[0], 1); #ifdef OUTPUT_SERIAL I2C_Read(paddr, H3LIS331DL_CTRL_REG1, data, 1); sc.printf("Written Result: %i\nTemperature: %i\n\n\n", data[0], data[1]); #endif data[0] = data[1] = 0; #ifdef OUTPUT_SERIAL I2C_Read(paddr, H3LIS331DL_WHO_AM_I, data, 1); sc.printf("Peripheral Accelerometer Who Am I Test\nI Am: %x\n", data[0]); #endif } void SetupAccelerometer ( ) { char value[6]; value[0] = 0x7F; I2C_Write(paddr, H3LIS331DL_CTRL_REG1, value[0], 1); #ifdef OUTPUT_SERIAL I2C_Read(paddr, H3LIS331DL_CTRL_REG1, value+1, 1); sc.printf("Accel CTRL Register: %x\n\n", value[1]); #endif while (1) { I2C_Read(paddr, H3LIS331DL_OUT_X_L, value, 1); I2C_Read(paddr, H3LIS331DL_OUT_Y_L, value+1, 1); I2C_Read(paddr, H3LIS331DL_OUT_Z_L, value+2, 1); #ifdef OUTPUT_SERIAL sc.printf("X_L: %i\nY_L: %i\nZ_L: %i\n\n", value[0], value[1], value[2]); #endif wait(3); } } void I2C_Write ( int addr, char cmd, char value, int length ) { i2c.start(); i2c.write(addr); i2c.write(cmd); i2c.write(value); i2c.stop(); } void I2C_Read ( int addr, char cmd, char *data, int length ) { int result; result = i2c.write(addr, &cmd, length, true); #ifdef OUTPUT_READ sc.printf("I2C Write Result: %i\n", result); #endif result = i2c.read(addr, data, length); #ifdef OUTPUT_READ sc.printf("I2C Read Result: %i\n", result); sc.printf("Test: %i\n\r", data[0]); #endif }
The output reads like....
.. Who Am I? I2C Write Result: 0 I2C Read Result: 0 Test: 105 ...... Temperature ....... I2C Write Result: 0 I2C Read Result: 0 Test: 188 MPU Initialized I2C Write Result: 0 I2C Read Result: 0 Test: 127 Written Result: 127 Temperature: 188 I2C Write Result: 0 I2C Read Result: 0 Test: 50 Peripheral Accelerometer Who Am I Test I Am: 32 I2C Write Result: 0 I2C Read Result: 0 Test: 255 Accel CTRL Register: ff Starting Read Routine I2C Write Result: 0 I2C Read Result: 0 Test: 176 I2C Write Result: 0 I2C Read Result: 0 Test: 160 I2C Write Result: 0 I2C Read Result: 0 Test: 96 X_L: 176 Y_L: 160 Z_L: 96
The X_L, Y_L & Z_L seem to just be gibberish, though.
Please help!
Thanks in advance, Frank