This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

ble app uart + I2C + LIS3DH Acc Output X,Y,Z values always remain 0 even if I have moved the BEACON .

  

values returned by ACC is always 0  !!

i2c_write && i2c_read

le_nus_data_send via uart  &&   printf( "A: %.1f; %.1f; %.1f \n", LIS3DH_Acc[0], LIS3DH_Acc[1], LIS3DH_Acc[2]);

shema hardware LIS3DH :

shema hardware NRF52805 && LIS3DH :

twi initi:

#define PIN_SCL             NRF_GPIO_PIN_MAP(0, 16) // SCL signal pin
#define PIN_SDA             NRF_GPIO_PIN_MAP(0, 18) // SDA signal pin

void LIS3DH_Init(void)
{
uint8_t chipid = 0;
uint8_t tmp = 0;

for(int i=0; i<30000; i++){__ASM("nop");}

//read chip id
for (int i = 0; i < 10 ; i++ )
{
for(int j = 0 ; j < 1000 ; j++ ) {__asm("NOP");}
i2c_read(LIS3DH_I2C_ADDRESS ,LIS3DH_REGISTER_WHO_AM_I, &chipid, 0x01);
//printf("LIS3DH_REGISTER_WHO_AM_I %d",LIS3DH_REGISTER_WHO_AM_I);
if ( chipid == 0x33 ) {
break;
}
}

//reboot sensor
tmp = (LIS3DH_CTRL_REG5_REBOOT);
i2c_write(LIS3DH_I2C_ADDRESS ,LIS3DH_REGISTER_CTRL_REG5, &tmp, 0x01);

//delay some time
for(int i=0; i<30000; i++){__ASM("nop");}
for(int i=0; i<30000; i++){__ASM("nop");}
for(int i=0; i<30000; i++){__ASM("nop");}
for(int i=0; i<30000; i++){__ASM("nop");}
for(int i=0; i<30000; i++){__ASM("nop");}

//report rate = 200Hz, x/y/z axis enable
tmp = (LIS3DH_CTRL_REG1_DATARATE_200HZ | LIS3DH_CTRL_REG1_XYZEN);
i2c_write(LIS3DH_I2C_ADDRESS ,LIS3DH_REGISTER_CTRL_REG1, &tmp, 0x01);

//delay some time
for(int i=0; i<30000; i++){__ASM("nop");}
for(int i=0; i<30000; i++){__ASM("nop");}
for(int i=0; i<30000; i++){__ASM("nop");}
for(int i=0; i<30000; i++){__ASM("nop");}

//enable block data update, full-scale = +-8g
tmp = (LIS3DH_CTRL_REG4_BLOCKDATAUPDATE | LIS3DH_CTRL_REG4_SCALE_8G);
i2c_write(LIS3DH_I2C_ADDRESS ,LIS3DH_REGISTER_CTRL_REG4, &tmp, 0x01);
}

void LIS3DH_GetAccData(float *acc)
{
uint8_t tmp[6] = {0};
int16_t tmp_int16[3] = {0};
uint8_t status = 0;

//check data ready?
i2c_read(LIS3DH_I2C_ADDRESS ,(LIS3DH_REGISTER_STATUS_REG2), &status, 0x01);
if(status & LIS3DH_STATUS_REG_ZYXDA)
{
i2c_read(LIS3DH_I2C_ADDRESS ,(LIS3DH_REGISTER_OUT_X_L | LIS3DH_READ_MULTI_BYTES), tmp, 0x06);
tmp_int16[0] = (int16_t)((tmp[1]<< 8) | tmp[0]);
tmp_int16[1] = (int16_t)((tmp[3]<< 8) | tmp[2]);
tmp_int16[2] = (int16_t)((tmp[5]<< 8) | tmp[4]);

acc[0] = (float)(tmp_int16[0]) * LIS3DH_ACC_CONVERT_8G;
acc[1] = (float)(tmp_int16[1]) * LIS3DH_ACC_CONVERT_8G;
acc[2] = (float)(tmp_int16[2]) * LIS3DH_ACC_CONVERT_8G;
}
}

-NRF52805 pca10040e

-SDK 15.00

-ble app uart 

-s112_nrf52_6.0.0_softdevice.hex 

I moved the device  but the values still remain x =0.0 y=0.0 z=0.0!!

Please help me to fix this. Also, If you think any other approach is simple and efficient, please let me know. Im open to suggestions. 

Parents Reply Children
No Data
Related