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. 

  • Hi

    Is the device running normally except the incorrect TWI values? Please note that v7.0.1 and v7.2.0 are the SoftDevice versions that have been tested with the nRF52805. How are you powering the board and set it up? Have you checked out the LIS3DH application note here? I'm not able to see any issue in your code by looking at it. Can you confirm what lines of code are returning/printing these zeroes?

    Best regards,

    Simon

  • thank you so much for helping me Simon

    Is the device running normally except the incorrect TWI values? 

    no does not work, I tested it with TWI, because in the hardware shema the LIS3DH is connected with SDA and SCL.

    Please note that v7.0.1 and v7.2.0 are the SoftDevice versions that have been tested with the nRF52805

    ok I will create another project which is based on SDK17.02 which contains SDv7.2.0

    How are you powering the board and set it up? 

    1.I am using J-link and IDE SEGGER

    Can you confirm what lines of code are returning/printing these zeroes?
    2.I am using UART BLE to retrieve values
    3.BEACON has:
    -NRF52805
    -BUZZER (works)
    -LED (works)
    -BUTTON (works)
    -LIS3DH (does not work)
    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;
    }
    }
    you can understand me how i2c works and how to read the bits in the registers ??????????????
    i2c_write()
    i2c_read()

    Best regards,

    Amine

  • Hi

    Is there a battery in the device you're using powering the device? The J-Link will not be sufficient to power the nRF by itself, so if not it won't be running properly. And are you sure the LIS3DH is powered properly, as I'd imagine only printing 0's would point to the device not being powered.

    Best regards,

    Simon

  • Hi Simon

    Is there a battery in the device you're using powering the device?

    I'm sure the device is powered by a button battery.

    Best regards,

Related