Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2021
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
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
Samuel Gradén
e7020e_2021
Commits
ca1431d1
Commit
ca1431d1
authored
4 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
test of i2c->spi wip2, id works
parent
0be6acd8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/rtt_rtic_i2c.rs
+22
-5
22 additions, 5 deletions
examples/rtt_rtic_i2c.rs
with
22 additions
and
5 deletions
examples/rtt_rtic_i2c.rs
+
22
−
5
View file @
ca1431d1
...
...
@@ -5,6 +5,7 @@
#![no_main]
#![no_std]
use
cortex_m
::
asm
::
delay
;
use
panic_halt
as
_
;
use
rtt_target
::{
rprintln
,
rtt_init_print
};
...
...
@@ -67,18 +68,34 @@ const APP: () = {
let
i2c_command_conf
=
0xF0
;
let
i2c_conf_reg
=
(
0b0
<<
5
)
/* MSB First */
|
(
0b1
0
<<
2
)
/* Mode 3 */
|
(
0b1
1
<<
2
)
/* Mode 3 */
|
(
0b00
<<
0
)
/* 1843 kHz */
;
// (0b01 << 0) /* 461 kHz */;
let
x
=
i2c
.write
(
i2c_addr
,
&
[
i2c_command_conf
,
i2c_conf_reg
]);
rprintln!
(
"configure {:?}"
,
x
);
cortex_m
::
asm
::
delay
(
100_000
);
// write to spi with CS0 (command 01..0f)
let
i2c_command_cs0
=
0x01
;
// bit 0 set
loop
{
let
x
=
i2c
.write
(
i2c_addr
,
&
[
i2c_command_cs0
,
0x00
,
0xFF
,
0xFF
,
0xFF
]);
rprintln!
(
"data {:?}"
,
x
);
}
let
pmw_command_product_id
=
0x00
;
let
x
=
i2c
.write
(
i2c_addr
,
&
[
i2c_command_cs0
,
pmw_command_product_id
]);
rprintln!
(
"request product_id {:?}"
,
x
);
cortex_m
::
asm
::
delay
(
10000
);
// send an extra byte, to actually read (data can be 0)
let
x
=
i2c
.write
(
i2c_addr
,
&
[
i2c_command_cs0
,
0x00u8
]);
// read the buffer
cortex_m
::
asm
::
delay
(
10000
);
// read the result
let
mut
buff
=
[
0u8
,
1
];
let
x
=
i2c
.read
(
i2c_addr
,
&
mut
buff
);
// read the buffer
cortex_m
::
asm
::
delay
(
10000
);
rprintln!
(
"data received {:?}"
,
x
);
rprintln!
(
"data received {:?}"
,
buff
);
}
#[idle]
...
...
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