2020-07-03 07:13 AM
Hello,
I am using LIS2DH12 with SPI connection.
I am able to read back Device ID which is 51. Also, I can write a to the reference register and read back successfully.
However, I cannot set registers. I am writing value on it and read back. The value on the register does not change.
uint8_t dev_id;
ret = lis2dh12_device_id_get(&dev_id);
printf("Device ID %d\n", dev_id);
uint8_t data= 0xAA;
uint8_t data2=0;
lis2dh12_filter_reference_set(&data);
TMR_Delay(MXC_TMR0, MSEC(10));
lis2dh12_filter_reference_get(&data2);
int result = 0;
result = 0;
lis2dh12_op_md_t op;
lis2dh12_op_md_t op_set = LIS2DH12_NM_10bit;
result = lis2dh12_operating_mode_get(&op);
printf("GET| Func result %d Mode %d\n", result, op);
result = lis2dh12_operating_mode_set(op_set);
TMR_Delay(MXC_TMR0, MSEC(10));
printf("SET| Func result %d Mode %d\n", result, op_set);
result = lis2dh12_operating_mode_get(&op);
printf("GET| Func result %d Mode %d\n", result, op);
result = 0;
lis2dh12_odr_t odr;
lis2dh12_odr_t odr_set = LIS2DH12_ODR_400Hz;
result = lis2dh12_data_rate_get(&odr);
printf("GET| Func result %d ODR %d\n", result, odr);
result = lis2dh12_data_rate_set(odr_set);
TMR_Delay(MXC_TMR0, MSEC(10));
printf("SET| Func result %d ODR %d\n", result, odr_set);
result = lis2dh12_data_rate_get(&odr);
printf("GET| Func result %d ODR %d\n", result, odr);
lis2dh12_fs_t fs;
lis2dh12_fs_t fs_set = LIS2DH12_2g;
result = lis2dh12_full_scale_get(&fs);
printf("GET| Func result %d Full Scale %d\n", result, fs);
result = lis2dh12_full_scale_set(fs_set);
TMR_Delay(MXC_TMR0, MSEC(10));
printf("SET| Func result %d Full Scale %d\n", result, fs_set);
result = lis2dh12_full_scale_get(&fs);
printf("GET| Func result %d Full Scale %d\n", result, fs);
uint8_t buff[6] = {0};
int16_t acc_x, acc_y, acc_z;
uint8_t new_data;
uint8_t reg_val;
result = lis2dh12_read_reg_st(0x20, ®_val);
printf("Result %d CTRL_REG1 %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x21, ®_val);
printf("Result %d CTRL_REG2 %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x23, ®_val);
printf("Result %d CTRL_REG4 %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x28, ®_val);
printf("Result %d XL %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x29, ®_val);
printf("Result %d XH %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x2A, ®_val);
printf("Result %d YL %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x2B, ®_val);
printf("Result %d YH %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x2C, ®_val);
printf("Result %d ZL %x \n", result, reg_val);
result = lis2dh12_read_reg_st(0x2D, ®_val);
printf("Result %d ZH %x \n", result, reg_val);
The output of the program is like
I am running SPI with the following configurations;
1MHz Clock speed,
SPI Clock polarity active low, Sampling rising edge.
Could you help please to figure out my problem ?
Also , why I am receiving same ACC value ?
Best regards
2020-07-17 06:09 AM
Hi @ESims.2 , can you please explain me the initial part of your code, for my better understanding?
uint8_t data= 0xAA;
uint8_t data2=0;
lis2dh12_filter_reference_set(&data);
TMR_Delay(MXC_TMR0, MSEC(10));
lis2dh12_filter_reference_get(&data2);
Which LIS2DH12 register are you reading?
Regards