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

    You might have to write something to the sensor in order to get anything back. Are you sure you're following the TWI communication protocol described in the datasheet of the device? It seems to me like your nRF device is able to operate over BLE and UART as intended, and that only the TWI is problematic on your end.

    Do you have a logic analyzer so you can see whether there's any activity on the TWI lines at all?

    Best regards,

    Simon

  • Salut Simon

    You might have to write something to the sensor in order to get anything back. 

    how can I validate the functioning of LIS3DH ??

    Êtes-vous sûr de suivre le protocole de communication TWI décrit dans la fiche technique de l'appareil ? 

    Oui je suis sûr

    Avez-vous un analyseur logique pour voir s'il y a une quelconque activité sur les lignes TWI ?

    je n'ai pas

    Pouvez-vous m'expliquer pourquoi les trois variables suivantes renvoient toujours 0

    tmp_int16[ 0] = (int16_t)((tmp[1]<< 8) | tmp[0]); 0
    tmp_int16 [1] = (int16_t)((tmp[3]<< 8) | tmp[2]);

    tmp_int16 [2] = (int16_t)((tmp[5]<< 8) | tmp[4]); 0

    si   tmp_int16 [ 0] est toujours  0  

    donc  acc[0] 0

    voici ma fonction

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

    //vérification des données prêtes ?
    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;


    }

    Meilleures salutations,

  • Hi

    My French is rather rusty, so I'm sorry if something was lost in translation. I'd appreciate it if you would keep replies on DevZone to English.

    1. Check out the Startup sequence and the control registers (CTRL_REG) in the LIS3DH app note to make sure your device is configured correctly. You could also use a multimeter to measure if there's any activity on the lines between the nRF52 and the LIS3DH.

    2. Okay, good.

    3. I think the reason that you're only seeing 0s from the accelerometer is that it isn't configured correctly, and thus doesn't actually send data to the nRF52. The only way to be certain is to check the TWI lines whether there is any activity there.

    Best regards,

    Simon

Related