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.

  1.  
  2. // Read data of x, y and z with this code
  3. //Read ADXL345 DATA
  4. #define ADXL345_CAL_AX 0x32
  5. #define ADXL345_CAL_AY 0x34
  6. #define ADXL345_CAL_AZ 0x36
  7.  
  8. move r1,AX
  9. ld r0,r1,0
  10. move r1,AX
  11. push r1
  12. move r1,0x53
  13. push r1
  14. move r1,ADXL345_CAL_AX
  15. push r1
  16. read_cal:
  17. psr
  18. jump read16
  19. or r2,r2,0 // test error
  20. jump readok,eq
  21. jump fail
  22. readok:
  23. ld r1,r3,12
  24. st r0,r1,0
  25. add r1,r1,1
  26. st r1,r3,12 // next cal parameter address
  27. ld r0,r3,4
  28. add r0,r0,2 // next register
  29. st r0,r3,4
  30. jumpr read_cal,ADXL345_CAL_AZ+2,lt
  31. add r3,r3,3
  32.  
  33. // Update value in xmin, xmax, ymin, ymax, zmin and zmax.
  34. // got problem in below code
  35. move r1, AXmin
  36. ld r0, r1, 0
  37. //and r0, r0, 0xFFFF
  38. jumpr AX_max_load,AX,gt
  39. jumpr AX_min_load,AX,lt
  40.  
  41. Yload:
  42. move r1, AYmin
  43. ld r0, r1, 0
  44. jumpr AY_max_load,AY,gt
  45. jumpr AY_min_load,AY,lt
  46.  
  47. Zload:
  48. move r1, AZmin
  49. ld r0, r1, 0
  50. jumpr AZ_max_load,AZ,gt
  51. jumpr AZ_min_load,AZ,lt
  52. Xload:
  53.  
  54. stage_rst
  55. MS3:
  56. wait 1000
  57. stage_inc 1
  58. jumps MS3, 10, lt
  59.  
  60. //OFF ADXL Sensor
  61. move r1,0x53
  62. push r1
  63. move r1,0x2D
  64. push r1
  65. move r1,0x04
  66. push r1
  67. psr
  68. jump write8
  69. add r3,r3,3 // remove 3 arguments from stack
  70. move r0,r2 // test for error in r2
  71. jumpr fail,1,ge
  72.  
  73. ret
  74.  
  75. AX_min_load:
  76. move r1, AX
  77. ld r0, r1, 0
  78. move r1, AXmin
  79. st r0, r1, 0
  80. jump Yload
  81.  
  82. AX_max_load:
  83. move r1, AX
  84. ld r0, r1, 0
  85. move r1, AXmax
  86. st r0, r1, 0
  87. jump Yload
  88.  
  89. AY_min_load:
  90. move r1, AY
  91. ld r0, r1, 0
  92. move r1, AYmin
  93. st r0, r1, 0
  94. jump Zload
  95.  
  96. AY_max_load:
  97. move r1, AY
  98. ld r0, r1, 0
  99. move r1, AYmax
  100. st r0, r1, 0
  101. jump Zload
  102.  
  103. AZ_min_load:
  104. move r1, AZ
  105. ld r0, r1, 0
  106. move r1, AZmin
  107. st r0, r1, 0
  108. jump Xload
  109.  
  110. AZ_max_load:
  111. move r1, AZ
  112. ld r0, r1, 0
  113. move r1, AZmax
  114. st r0, r1, 0
  115. jump Xload
  116.  
  117. fail:
  118. move r1,temp
  119. move r0,0 // 0 signals error
  120. st r0,r1,0
  121. ret
  122.  

Who is online

Users browsing this forum: No registered users and 28 guests