Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
V
vSPI
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rasky
vSPI
Commits
3167ba98
Commit
3167ba98
authored
Feb 23, 2012
by
Michael J. Lyons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding script to control cheetah spi adapter and test vSPI
parent
3be23a0e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
82 additions
and
0 deletions
+82
-0
spitest.py
scripts/master/spitest.py
+82
-0
No files found.
scripts/master/spitest.py
0 → 100644
View file @
3167ba98
from
cheetah_py
import
*
from
time
import
*
def
print_usage
():
print
\
"""
usage: spitest.py PORT
"""
if
(
len
(
sys
.
argv
)
<
2
):
print_usage
()
sys
.
exit
(
1
)
port
=
int
(
sys
.
argv
[
1
])
mode
=
2
bitrate
=
40000
# kbps
byteCount
=
11
# bytes
# Open the device
handle
=
ch_open
(
port
)
if
(
handle
<=
0
):
print
"Unable to open Cheetah device on port
%
d"
%
port
print
"Error code =
%
d (
%
s)"
%
(
handle
,
ch_status_string
(
handle
))
sys
.
exit
(
1
)
print
"Opened Cheetah device on port
%
d"
%
port
ch_host_ifce_speed_string
=
""
if
(
ch_host_ifce_speed
(
handle
)):
ch_host_ifce_speed_string
=
"high speed"
else
:
ch_host_ifce_speed_string
=
"full speed"
print
"Host interface is
%
s"
%
ch_host_ifce_speed_string
# Ensure that SPI subsystem is configured
ch_spi_configure
(
handle
,
(
mode
>>
1
),
mode
&
1
,
CH_SPI_BITORDER_MSB
,
0x0
)
print
"SPI configuration set to mode
%
d, MSB shift, SS[2:0] active low"
%
mode
sys
.
stdout
.
flush
()
# Set the bitrate
bitrate
=
ch_spi_bitrate
(
handle
,
bitrate
)
print
"Bitrate set to
%
d kHz"
%
bitrate
sys
.
stdout
.
flush
()
# Create 4KB of fake data so we can exchange it for real data
data_in
=
array
(
'B'
,
[
0
for
i
in
range
(
byteCount
)])
ch_spi_queue_clear
(
handle
)
ch_spi_queue_oe
(
handle
,
1
)
#ch_spi_queue_byte(handle, 1, 0x00) # Send an empty byte, pre SS low
ch_spi_queue_ss
(
handle
,
0x1
)
#ch_spi_queue_byte(handle, 1, 0x02) # Send to MOSI buffer
#ch_spi_queue_byte(handle, 3, 0x00) # Sending 4 bytes
#ch_spi_queue_byte(handle, 1, 0x04)
#ch_spi_queue_byte(handle, 1, 0xFF) # Sending byte: 1111_1111
#ch_spi_queue_byte(handle, 1, 0xF0) # Sending byte: 1111_0000
#ch_spi_queue_byte(handle, 1, 0x33) # Sending byte: 0011_0011
ch_spi_queue_byte
(
handle
,
1
,
42
)
# Sending byte: 0101_0101
#ch_spi_queue_byte(handle, 1, 0x55) # Test byte
#ch_spi_queue_byte(handle, 1, 0x66)
ch_spi_queue_ss
(
handle
,
0
)
#ch_spi_queue_byte(handle, 1, 0x00) # Send an empty byte, SS high
(
actualByteCount
,
data_in
)
=
ch_spi_batch_shift
(
handle
,
byteCount
)
#if (actualByteCount < 0):
# print "error: %s" % ch_status_string(count)
#elif (actualByteCount != byteCount):
# print "error: read %d bytes (expected %d)" % (actualByteCount, byteCount)
#else:
for
i
in
range
(
actualByteCount
):
sys
.
stdout
.
write
(
"
%
d "
%
data_in
[
i
])
sys
.
stdout
.
write
(
"
\n
"
)
# Close and exit
ch_close
(
handle
)
sys
.
exit
(
0
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment