Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
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
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
cm-projects
RIOT
Commits
7aec98c5
Commit
7aec98c5
authored
10 years ago
by
Peter Kietzmann
Browse files
Options
Downloads
Patches
Plain Diff
Added a function for the slave to print received data.
parent
9b819c4d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/periph_spi/main.c
+22
-0
22 additions, 0 deletions
tests/periph_spi/main.c
with
22 additions
and
0 deletions
tests/periph_spi/main.c
+
22
−
0
View file @
7aec98c5
...
...
@@ -44,6 +44,8 @@ static int spi_speed = -1;
static
int
spi_master
=
-
1
;
/* 0 for slave, 1 for master, -1 for not initialized */
static
char
buffer
[
256
];
/* temporary buffer */
static
char
rx_buffer
[
256
];
/* global receive buffer */
static
int
rx_counter
=
0
;
static
volatile
int
state
;
static
char
*
mem
=
"Hello Master! abcdefghijklmnopqrstuvwxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"
;
...
...
@@ -140,6 +142,12 @@ void slave_on_cs(void *arg)
char
slave_on_data
(
char
data
)
{
rx_buffer
[
rx_counter
]
=
data
;
rx_counter
++
;
if
(
rx_counter
>=
256
)
{
rx_counter
=
0
;
}
switch
(
rw
)
{
case
READ
:
return
mem
[
state
++
];
...
...
@@ -239,6 +247,19 @@ void cmd_transfer(int argc, char **argv)
}
}
void
cmd_print
(
int
argc
,
char
**
argv
)
{
if
(
spi_master
!=
0
)
{
puts
(
"error: node is not initialized as slave"
);
}
else
{
printf
(
"Received %i bytes:
\n
"
,
rx_counter
);
print_bytes
(
"MOSI"
,
rx_buffer
,
rx_counter
);
}
rx_counter
=
0
;
memset
(
&
rx_buffer
,
0
,
256
);
}
int
shell_getchar
(
void
)
{
return
(
int
)
getchar
();
...
...
@@ -253,6 +274,7 @@ static const shell_command_t shell_commands[] = {
{
"init_master"
,
"Initialize node as SPI master"
,
cmd_init_master
},
{
"init_slave"
,
"Initialize node as SPI slave"
,
cmd_init_slave
},
{
"send"
,
"Transfer string to slave (only in master mode)"
,
cmd_transfer
},
{
"print_rx"
,
"Print the received string (only in slave mode)"
,
cmd_print
},
{
NULL
,
NULL
,
NULL
}
};
...
...
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