Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Skyward Boardcore
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Emilio Corigliano
Skyward Boardcore
Commits
c77ef23e
Commit
c77ef23e
authored
2 years ago
by
Giulia Ghirardini
Committed by
Alberto Nidasio
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[LIS2MDL] Added serial data write for Matlab
parent
c26476d2
Branches
Branches containing commit
No related tags found
Loading
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/shared/sensors/LIS2MDL/LIS2MDL.cpp
+4
-2
4 additions, 2 deletions
src/shared/sensors/LIS2MDL/LIS2MDL.cpp
src/tests/sensors/test-lis2mdl.cpp
+20
-6
20 additions, 6 deletions
src/tests/sensors/test-lis2mdl.cpp
with
24 additions
and
8 deletions
src/shared/sensors/LIS2MDL/LIS2MDL.cpp
+
4
−
2
View file @
c77ef23e
...
...
@@ -48,7 +48,7 @@ bool LIS2MDL::init()
{
// Important! It is imperative to get the 4WSPI enabled (set to the
// value of 1) due to the four-wire connection for SPI and the I2C_DIS
// must be disabled.
In addiction, self test is enabled.
// must be disabled.
SPITransaction
spi
(
mSlave
);
spi
.
writeRegister
(
CFG_REG_C
,
(
1
<<
2
)
|
(
1
<<
5
));
}
...
...
@@ -94,6 +94,7 @@ bool LIS2MDL::selfTest()
float
avgX
=
0.
f
,
avgY
=
0.
f
,
avgZ
=
0.
f
;
{
// selfTest is enabled
SPITransaction
spi
(
mSlave
);
uint16_t
temp
=
spi
.
readRegister
(
CFG_REG_C
)
|
(
1
<<
1
);
spi
.
writeRegister
(
CFG_REG_C
,
temp
);
...
...
@@ -131,6 +132,7 @@ bool LIS2MDL::selfTest()
passed
=
false
;
{
// Disable selfTest
SPITransaction
spi
(
mSlave
);
uint16_t
temp
=
spi
.
readRegister
(
CFG_REG_C
)
&
~
(
1
<<
1
);
spi
.
writeRegister
(
CFG_REG_C
,
temp
);
...
...
@@ -153,7 +155,7 @@ bool LIS2MDL::applyConfig(Config config)
SPITransaction
spi
(
mSlave
);
uint8_t
reg
=
0
;
// CFG_REG_A
// CFG_REG_A
: configuration register
reg
|=
config
.
odr
<<
2
;
reg
|=
config
.
deviceMode
;
reg
|=
(
1
<<
7
);
...
...
This diff is collapsed.
Click to expand it.
src/tests/sensors/test-lis2mdl.cpp
+
20
−
6
View file @
c77ef23e
...
...
@@ -21,6 +21,7 @@
*/
#include
<drivers/spi/SPIDriver.h>
#include
<drivers/usart/USART.h>
#include
<miosix.h>
#include
<sensors/LIS2MDL/LIS2MDL.h>
#include
<utils/Debug.h>
...
...
@@ -31,7 +32,7 @@ using namespace miosix;
int
main
()
{
GpioPin
cs
(
GPIOA_BASE
,
15
),
miso
(
GPIOA_BASE
,
6
),
mosi
(
GPIOA_BASE
,
7
),
clk
(
GPIOA_BASE
,
5
);
clk
(
GPIOA_BASE
,
5
)
,
tx
(
GPIOA_BASE
,
2
),
rx
(
GPIOA_BASE
,
3
)
;
cs
.
mode
(
Mode
::
OUTPUT
);
cs
.
high
();
...
...
@@ -46,7 +47,16 @@ int main()
mosi
.
mode
(
Mode
::
ALTERNATE
);
mosi
.
alternateFunction
(
5
);
// Serial data write on Matlab
rx
.
mode
(
Mode
::
ALTERNATE
);
rx
.
alternateFunction
(
7
);
tx
.
mode
(
Mode
::
ALTERNATE
);
tx
.
alternateFunction
(
7
);
SPIBus
bus
(
SPI1
);
USART
usart
(
USART2
,
USARTInterface
::
Baudrate
::
B115200
);
usart
.
init
();
SPIBusConfig
busConfig
;
busConfig
.
clockDivider
=
SPI
::
ClockDivider
::
DIV_256
;
...
...
@@ -55,7 +65,6 @@ int main()
LIS2MDL
::
Config
config
;
config
.
odr
=
LIS2MDL
::
ODR_10_HZ
;
config
.
deviceMode
=
LIS2MDL
::
MD_CONTINUOUS
;
// config.scale = LIS2MDL::FS_16_GAUSS;
config
.
temperatureDivider
=
5
;
LIS2MDL
sensor
(
bus
,
cs
,
busConfig
,
config
);
...
...
@@ -74,7 +83,8 @@ int main()
}
TRACE
(
"selfTest returned true
\n
"
);
TRACE
(
"Now printing some sensor data:
\n
"
);
Thread
::
sleep
(
100
);
Thread
::
sleep
(
3000
);
float
sensorData
[
3
];
while
(
true
)
{
...
...
@@ -82,6 +92,10 @@ int main()
LIS2MDLData
data
=
sensor
.
getLastSample
();
TRACE
(
"%f C | x: %f | y: %f | z: %f
\n
"
,
data
.
temperature
,
data
.
magneticFieldX
,
data
.
magneticFieldY
,
data
.
magneticFieldZ
);
miosix
::
Thread
::
sleep
(
100
);
sensorData
[
0
]
=
data
.
magneticFieldX
;
sensorData
[
1
]
=
data
.
magneticFieldY
;
sensorData
[
2
]
=
data
.
magneticFieldZ
;
usart
.
write
(
sensorData
,
3
*
sizeof
(
float
));
miosix
::
Thread
::
sleep
(
10
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment