Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
embedded-rust-michael-david
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
david.dasilvam2
embedded-rust-michael-david
Commits
70decd77
Commit
70decd77
authored
1 year ago
by
michael.divia
Browse files
Options
Downloads
Patches
Plain Diff
Start I2C
parent
1be943e9
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
src/i2c.rs
+69
-0
69 additions, 0 deletions
src/i2c.rs
with
69 additions
and
0 deletions
src/i2c.rs
0 → 100644
+
69
−
0
View file @
70decd77
#![no_std]
#![no_main]
extern
crate
panic_halt
;
use
cortex_m_rt
::
entry
;
use
cortex_m_semihosting
::
hprintln
;
use
stm32l4xx_hal
as
hal
;
use
crate
::
hal
::
i2c
;
use
crate
::
hal
::
i2c
::
I2c
;
use
crate
::
hal
::
prelude
::
*
;
#[entry]
fn
main
()
->
!
{
hprintln!
{
"Nucleo-l476RG is alive !"
};
/*
setup peripherals
*/
let
periphs
=
hal
::
stm32
::
Peripherals
::
take
()
.unwrap
();
let
mut
flash
=
periphs
.FLASH
.constrain
();
// .constrain();
let
mut
rcc
=
periphs
.RCC
.constrain
();
let
mut
pwr
=
periphs
.PWR
.constrain
(
&
mut
rcc
.apb1r1
);
// let mut gpioa = periphs.GPIOA.split(&mut rcc.ahb2);
let
mut
gpiob
=
periphs
.GPIOB
.split
(
&
mut
rcc
.ahb2
);
let
clocks
=
rcc
.cfgr
.freeze
(
&
mut
flash
.acr
,
&
mut
pwr
);
/*
setup i2c
*/
let
mut
scl
=
gpiob
.pb13.into_alternate_open_drain
::
<
4
>
(
&
mut
gpiob
.moder
,
&
mut
gpiob
.otyper
,
&
mut
gpiob
.afrh
,
);
scl
.internal_pull_up
(
&
mut
gpiob
.pupdr
,
true
);
let
mut
sda
=
gpiob
.pb14.into_alternate_open_drain
::
<
4
>
(
&
mut
gpiob
.moder
,
&
mut
gpiob
.otyper
,
&
mut
gpiob
.afrh
,
);
sda
.internal_pull_up
(
&
mut
gpiob
.pupdr
,
true
);
let
mut
i2c
=
I2c
::
i2c2
(
periphs
.I2C2
,
(
scl
,
sda
),
i2c
::
Config
::
new
(
100
.kHz
(),
clocks
),
&
mut
rcc
.apb1r1
,
);
let
mut
buffer
=
[
0u8
;
4
];
const
MPL115A2_ADDR_WRITE
:
u8
=
0xC0
;
const
MPL115A2_ADDR_READ
:
u8
=
0xC1
;
i2c
.write_read
(
MPL115A2_ADDR_WRITE
,
&
[
0x04
],
&
mut
buffer
)
.unwrap
();
hprintln!
(
"TEST: {}"
,
buffer
[
0
]);
loop
{
continue
;
}
}
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