Examples Operation codes for commands for LS3DSH
Hi,
I can't find any examples of using commands in the statemachines.
I want to create a tilt sensor, by using 2 statemachines, 1 is monitoring x axis, the other z axis.
To keep it simple i will add the code for the x axis only .
This statemachine setup should do the same as this equivalent in c :
If ((x<THRS1) || (x>THRS1)) -> trigger the interrupt pin
This does not seem to work, what do i overlook?
Triggerlevel goes from 1 to 255, i use this to set the sensitivity of the detection
// 1 get the current x, y , z values to determine how the PCB is fixed in the cabinet
lis3dsh_update_xyz();
triggerlevel = MAX_SENSITIVITY/sensitivity;
buf[0] = CTRL_REG3;
buf[1] = 0x48; // INT1 pin active '1'
if(! lis3dsh_write(buf,2)) return false;
buf[0] = THRS2_1;
buf[1] = (lis3dsh.xyz.raw.x/256) + triggerlevel; //threshold to identify angle
if(! lis3dsh_write(buf,2)) return false;
buf[0] = THRS1_1;
buf[1] = (lis3dsh.xyz.raw.x/256) - triggerlevel; //threshold to identify angle in the other direction
if(! lis3dsh_write(buf,2)) return false;
buf[0] = MASK1_A;
buf[1] = 0xC0; //positive and negative axis enabled X as only
if(! lis3dsh_write(buf,2)) return false;
buf[0] = SETT1;
buf[1] = 0x21; //CONT can generate interrupt
if(! lis3dsh_write(buf,2)) return false;
// state machine
buf[0] = ST1_1;
buf[1] = JMP;
if(! lis3dsh_write(buf,2)) return false;
buf[0] = ST1_2;
buf[1] = RESET(GNTH2)|NEXT(LNTH1); // RESET = Shift left 4, NEXT = AND low nibble
if(! lis3dsh_write(buf,2)) return false; // if x greater then THRS2, jump to state4 - if x smaller then THRS1, jump to state4 , if none of the conditions are met -> retry next sample
buf[0] = ST1_3;
buf[1] = 0x44; // one of the conditions where fine , jump to ST1_4
if(! lis3dsh_write(buf,2)) return false;
buf[0] = ST1_4;
buf[1] = CONT;
if(! lis3dsh_write(buf,2)) return false;
buf[0] = CTRL_REG1; // Status machine 1 enabled
buf[1] = 0x01;
if(! lis3dsh_write(buf,2)) return false;