Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
ch32v003fun
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
Andreas Horn
ch32v003fun
Commits
221d1d54
Commit
221d1d54
authored
2 years ago
by
Eric Brombaugh
Browse files
Options
Downloads
Patches
Plain Diff
Updated with selectable I2C prescaler.
parent
4917d9d4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/i2c_oled/README.md
+6
-1
6 additions, 1 deletion
examples/i2c_oled/README.md
examples/i2c_oled/i2c.h
+6
-3
6 additions, 3 deletions
examples/i2c_oled/i2c.h
with
12 additions
and
4 deletions
examples/i2c_oled/README.md
+
6
−
1
View file @
221d1d54
...
...
@@ -12,7 +12,12 @@ https://user-images.githubusercontent.com/1132011/230734071-dee305de-5aad-4ca0-a
## Build options
There are a few build-time options in the i2c.h source:
*
I2C_CLKRATE - defines the I2C bus clock rate. Both 100kHz and 400kHz are supported.
800kHz has been seen to work but 1MHz did not.
800kHz has been seen to work when I2C_PRERATE is 1000000, but 1MHz did not. To
use higher bus rates you must increase I2C_PRERATE at the expense of higher power
consumption.
*
I2C_PRERATE - defines the I2C logic clock rate. Must be higher than I2C_CLKRATE.
Keep this value as low as possible (but not lower than 1000000) to ensure low power
operaton.
*
I2C_DUTY - for I2C_CLKRATE > 100kHz this specifies the duty cycle, either 33% or 36%.
*
TIMEOUT_MAX - the amount of tries in busy-wait loops before giving up. This value
depends on the I2C_CLKRATE and should not affect normal operation.
...
...
This diff is collapsed.
Click to expand it.
examples/i2c_oled/i2c.h
+
6
−
3
View file @
221d1d54
...
...
@@ -6,8 +6,11 @@
#ifndef _I2C_H
#define _I2C_H
// I2C clock rate
#define I2C_CLKRATE 800000
// I2C Bus clock rate - must be lower the Logic clock rate
#define I2C_CLKRATE 1000000
// I2C Logic clock rate - must be higher than Bus clock rate
#define I2C_PRERATE 2000000
// uncomment this for high-speed 36% duty cycle, otherwise 33%
#define I2C_DUTY
...
...
@@ -40,7 +43,7 @@ void i2c_setup(void)
// set freq
tempreg
=
I2C1
->
CTLR2
;
tempreg
&=
~
I2C_CTLR2_FREQ
;
tempreg
|=
(
APB_CLOCK
/
1000000
)
&
I2C_CTLR2_FREQ
;
tempreg
|=
(
APB_CLOCK
/
I2C_PRERATE
)
&
I2C_CTLR2_FREQ
;
I2C1
->
CTLR2
=
tempreg
;
// Set clock config
...
...
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