Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Arduino Core for SAMD21 CPU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
Arduino Core for SAMD21 CPU
Commits
eca1341c
Commit
eca1341c
authored
10 years ago
by
Cristian Maglie
Committed by
Cristian Maglie
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Limit SPI max clock speed to 12Mhz
SAMD21G18A doesn't operate correctly with clock dividers lower than 4
parent
a2940ed2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
libraries/SPI/SPI.cpp
+5
-1
5 additions, 1 deletion
libraries/SPI/SPI.cpp
libraries/SPI/SPI.h
+12
-2
12 additions, 2 deletions
libraries/SPI/SPI.h
with
17 additions
and
3 deletions
libraries/SPI/SPI.cpp
+
5
−
1
View file @
eca1341c
...
...
@@ -97,7 +97,11 @@ void SPIClass::setDataMode(uint8_t mode)
void
SPIClass
::
setClockDivider
(
uint8_t
div
)
{
_p_sercom
->
setBaudrateSPI
(
div
);
if
(
div
<
SPI_MIN_CLOCK_DIVIDER
)
{
_p_sercom
->
setBaudrateSPI
(
SPI_MIN_CLOCK_DIVIDER
);
}
else
{
_p_sercom
->
setBaudrateSPI
(
div
);
}
}
byte
SPIClass
::
transfer
(
uint8_t
data
)
...
...
This diff is collapsed.
Click to expand it.
libraries/SPI/SPI.h
+
12
−
2
View file @
eca1341c
...
...
@@ -18,6 +18,16 @@
#define SPI_MODE2 0x03
#define SPI_MODE3 0x01
#if defined(__SAMD21G18A__)
// Even if not specified on the datasheet, the SAMD21G18A MCU
// doesn't operate correctly with clock dividers lower than 4.
// This allows a theoretical maximum SPI clock speed of 12Mhz
#define SPI_MIN_CLOCK_DIVIDER 4
// Other SAMD21xxxxx MCU may be affected as well
#else
#define SPI_MIN_CLOCK_DIVIDER 2
#endif
class
SPISettings
{
public:
SPISettings
(
uint32_t
clock
,
BitOrder
bitOrder
,
uint8_t
dataMode
)
{
...
...
@@ -36,8 +46,8 @@ class SPISettings {
uint8_t
div
;
if
(
clock
<
(
F_CPU
/
255
))
{
div
=
255
;
}
else
if
(
clock
>=
(
F_CPU
/
2
))
{
div
=
2
;
}
else
if
(
clock
>=
(
F_CPU
/
SPI_MIN_CLOCK_DIVIDER
))
{
div
=
SPI_MIN_CLOCK_DIVIDER
;
}
else
{
div
=
(
F_CPU
/
(
clock
+
1
))
+
1
;
}
...
...
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