-
Notifications
You must be signed in to change notification settings - Fork 0
/
FXOS8700-IntDemo.spin2
126 lines (90 loc) · 3.96 KB
/
FXOS8700-IntDemo.spin2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
----------------------------------------------------------------------------------------------------
Filename: FXOS8700-IntDemo.spin2
Description: Demo of the FXOS8700 driver
* Interrupt functionality
Author: Jesse Burt
Started: Sep 26, 2020
Updated: Jul 10, 2024
Copyright (c) 2024 - See end of file for terms of use.
----------------------------------------------------------------------------------------------------
}
CON
_clkfreq = cfg._clkfreq_def
_xtlfreq = cfg._xtlfreq
#include "core.con.click.spin2"
' -- User-modifiable constants
CLICK_BASE = 16 ' MikroE Click board base I/O pin (multiple of 16)
'--
' Temperature scales
C = 0
F = 1
OBJ
cfg: "boardcfg.p2eval"
{ MikroE Click boards (change CLICK_BASE above) }
'sensor: "sensor.imu.6dof.fxos8700" | SCL=SCL_PIN, SDA=SDA_PIN, I2C_FREQ=400_000, I2C_ADDR=%11
{ custom I/O settings }
sensor: "sensor.imu.6dof.fxos8700" | SCL=0, SDA=1, I2C_FREQ=400_000, I2C_ADDR=%11, RST_PIN=-1
ser: "com.serial.terminal.ansi" | SER_BAUD=2_000_000
PUB main() | i
setup()
sensor.preset_active()
sensor.temp_scale(C)
sensor.accel_scale(2) ' 2, 4, 8 (g's)
sensor.accel_data_rate(50) ' 1, 6, 12, 50, 100, 200, 400, 800
sensor.accel_int_mask(%11111111)
{ set up magnetometer interrupts; 0..32_767000 microGauss thresholds }
{ *NOTE: The chip doesn't account for bias offsets when comparing the set thresholds to the
measurement data. They are compared to the uncorrected data only. }
sensor.mag_int_duration()
sensor.mag_int_set_thresh_x(1_000000)
sensor.mag_int_set_thresh_y(1_000000)
sensor.mag_int_set_thresh_z(1_000000)
sensor.mag_int_ena(true)
sensor.mag_int_mask(%111)
ser.pos_xy(0, 3)
repeat i from 0 to 2
ser.pos_x(12+(16*i))
ser.putchar(i+"X")
repeat
if ( ser.getchar_noblock() == "c" )
cal_accel()
cal_mag()
ser.pos_xy(0, 4)
show_accel_data()
ser.printf(@"Accel int: %08.8b\n\r\n\r", sensor.accel_int())
show_mag_data()
ser.printf(@"Mag int: %03.3b\n\r\n\r", sensor.mag_int())
show_temp_data()
PUB show_temp_data() | temp, tscl
' Show temperature data
temp := sensor.temperature()
tscl := lookupz(sensor.temp_scale(): "C", "F")
ser.printf(@"Temp. (deg %c): %3.3d.%02.2d\n\r", tscl, (temp / 100), abs(temp // 100))
PUB setup()
ser.start()
ser.clear()
ser.strln(@"Serial terminal started")
if ( sensor.start() )
ser.strln(@"FXOS8700 driver started")
else
ser.strln(@"FXOS8700 driver failed to start - halting")
repeat
#include "acceldemo.common.spin2h" ' Use code common to all accelerometer
#include "magdemo.common.spin2h" ' and magnetometer demos
DAT
{
Copyright 2024 Jesse Burt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}