I am using adxl345 with ESP32 in MDF for update value every 1 second of x, y, z axis in xmin, xmax, ymin, ymax, zmin, zm

dipaknagvadia
Posts: 2
Joined: Fri Jan 03, 2020 6:13 am

I am using adxl345 with ESP32 in MDF for update value every 1 second of x, y, z axis in xmin, xmax, ymin, ymax, zmin, zm

Postby dipaknagvadia » Mon Jan 25, 2021 1:29 pm

//I am using adxl345 with ESP32 in MDF for update value every 1 second of x, y, z axis in xmin, xmax, ymin, ymax, zmin, zmax and //send data after 5 minutes. so when I read data for x, y, z it is fine but when I want to compare and update the value in xmin and //xmax is not update properly. my code snippet is below kindly help me with this. thanks in advance.

Code: Untitled.asm Select all



// Read data of x, y and z with this code
//Read ADXL345 DATA
#define ADXL345_CAL_AX 0x32
#define ADXL345_CAL_AY 0x34
#define ADXL345_CAL_AZ 0x36

move r1,AX
ld r0,r1,0
move r1,AX
push r1
move r1,0x53
push r1
move r1,ADXL345_CAL_AX
push r1
read_cal:
psr
jump read16
or r2,r2,0 // test error
jump readok,eq
jump fail
readok:
ld r1,r3,12
st r0,r1,0
add r1,r1,1
st r1,r3,12 // next cal parameter address
ld r0,r3,4
add r0,r0,2 // next register
st r0,r3,4
jumpr read_cal,ADXL345_CAL_AZ+2,lt
add r3,r3,3

// Update value in xmin, xmax, ymin, ymax, zmin and zmax.
// got problem in below code
move r1, AXmin
ld r0, r1, 0
//and r0, r0, 0xFFFF
jumpr AX_max_load,AX,gt
jumpr AX_min_load,AX,lt

Yload:
move r1, AYmin
ld r0, r1, 0
jumpr AY_max_load,AY,gt
jumpr AY_min_load,AY,lt

Zload:
move r1, AZmin
ld r0, r1, 0
jumpr AZ_max_load,AZ,gt
jumpr AZ_min_load,AZ,lt
Xload:

stage_rst
MS3:
wait 1000
stage_inc 1
jumps MS3, 10, lt

//OFF ADXL Sensor
move r1,0x53
push r1
move r1,0x2D
push r1
move r1,0x04
push r1
psr
jump write8
add r3,r3,3 // remove 3 arguments from stack
move r0,r2 // test for error in r2
jumpr fail,1,ge

ret

AX_min_load:
move r1, AX
ld r0, r1, 0
move r1, AXmin
st r0, r1, 0
jump Yload

AX_max_load:
move r1, AX
ld r0, r1, 0
move r1, AXmax
st r0, r1, 0
jump Yload

AY_min_load:
move r1, AY
ld r0, r1, 0
move r1, AYmin
st r0, r1, 0
jump Zload

AY_max_load:
move r1, AY
ld r0, r1, 0
move r1, AYmax
st r0, r1, 0
jump Zload

AZ_min_load:
move r1, AZ
ld r0, r1, 0
move r1, AZmin
st r0, r1, 0
jump Xload

AZ_max_load:
move r1, AZ
ld r0, r1, 0
move r1, AZmax
st r0, r1, 0
jump Xload

fail:
move r1,temp
move r0,0 // 0 signals error
st r0,r1,0
ret

Who is online

Users browsing this forum: No registered users and 1 guest