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

TWI Issue With Peripheral Sensors

I'm building some code off of the twi_master_using_app_twi example which is available in the SDK (v11.0.0).

The two peripherals I'm working on are an accelerometer (LIS3DH) and gyroscope (L3GD20H).

I'm able to read and confirm the WHOAMI registers of both sensors, but that's about it. When I check the status register, both return all zeros. When I read the XYZ data off of each sensor the output data is just a constant value for all directions of motion with no sensitivity to movement.

I've been stuck at this point for a couple days now and I feel like I must be missing something simple/obvious. Any tips on where to start?

Parents
  • Hi Martin,

    Thanks for the reply!

    It's my first time working with I2C/TWI but yea, that's what I assumed too with the WHOAMI registers. From what I understand, both sensors have start up registers and are by default in "low power" mode so I think the first thing I have to do, like you said, is set the sensor to "normal" mode.

    I'm trying to follow the init setup shown in lm75b.c. For the accelerometer (data sheet here click) I have:

        #define LIS3DH_INIT_TRANSFER_COUNT 1
        #define LIS3DH_CTRL_REG1 0x20
        #define LIS3DH_ADDR 0x18
    
        // Set default configuration of LIS3DH
        static uint8_t const default_config1[] = { LIS3DH_CTRL_REG1, 0x07 }; // Set CTRL_REG1 to 00000111 (0000 = 50 Hz, 0 = normal mode, 111 = Zen,Yen,Xen Enabled)
        
        app_twi_transfer_t_const lis3dh_init_transfers[LIS3DH_INIT_TRANSFER_COUNT] = 
        {
            APP_TWI_WRITE(LIS3DH_ADDR, default_config1, sizeof(default_config1, 0), 0);
        }
    

    This gets called in main.c to initialize the sensor with app_twi_perform. Does that seem correct?

    Also, when I read the status register (0x27 on the accelerometer) I get back a value of 0xFF but the default value is 0x00... so it makes me want to believe that the sensor is doing something.

Reply
  • Hi Martin,

    Thanks for the reply!

    It's my first time working with I2C/TWI but yea, that's what I assumed too with the WHOAMI registers. From what I understand, both sensors have start up registers and are by default in "low power" mode so I think the first thing I have to do, like you said, is set the sensor to "normal" mode.

    I'm trying to follow the init setup shown in lm75b.c. For the accelerometer (data sheet here click) I have:

        #define LIS3DH_INIT_TRANSFER_COUNT 1
        #define LIS3DH_CTRL_REG1 0x20
        #define LIS3DH_ADDR 0x18
    
        // Set default configuration of LIS3DH
        static uint8_t const default_config1[] = { LIS3DH_CTRL_REG1, 0x07 }; // Set CTRL_REG1 to 00000111 (0000 = 50 Hz, 0 = normal mode, 111 = Zen,Yen,Xen Enabled)
        
        app_twi_transfer_t_const lis3dh_init_transfers[LIS3DH_INIT_TRANSFER_COUNT] = 
        {
            APP_TWI_WRITE(LIS3DH_ADDR, default_config1, sizeof(default_config1, 0), 0);
        }
    

    This gets called in main.c to initialize the sensor with app_twi_perform. Does that seem correct?

    Also, when I read the status register (0x27 on the accelerometer) I get back a value of 0xFF but the default value is 0x00... so it makes me want to believe that the sensor is doing something.

Children
No Data
Related