Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
grabor
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
grabor
Commits
338c6b7e
Commit
338c6b7e
authored
Apr 24, 2013
by
Upi Tamminen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused spihandler.v
parent
30e75da9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
100 deletions
+0
-100
spihandler.v
verilog/spihandler.v
+0
-100
No files found.
verilog/spihandler.v
deleted
100644 → 0
View file @
30e75da9
/* Based on the fpga4fun SPI tutorial */
/*
Since the SPI bus is typically much slower than the FPGA operating clock
speed, we choose to over-sample the SPI bus using the FPGA clock. That makes
the slave code slightly more complicated, but has the advantage of having the
SPI logic run in the FPGA clock domain, which will make things easier
afterwards.
*/
/* 16bit spi here */
module
spihandler
(
clk
,
SCK
,
MOSI
,
MISO
,
SSEL
,
sendme
,
byte_received
,
byte_data_received
)
;
input
clk
;
input
SCK
,
SSEL
,
MOSI
;
output
MISO
;
input
[
15
:
0
]
sendme
;
output
reg
byte_received
;
output
reg
[
15
:
0
]
byte_data_received
;
//output byte_received; // high when a byte has been received
//output [15:0] byte_data_received;
// sync SCK to the FPGA clock using a 3-bits shift register
reg
[
2
:
0
]
SCKr
;
always
@
(
posedge
clk
)
SCKr
<=
{
SCKr
[
1
:
0
]
,
SCK
};
// now we can detect SCK rising and falling edges
wire
SCK_risingedge
=
(
SCKr
[
2
:
1
]
==
2'b01
)
;
wire
SCK_fallingedge
=
(
SCKr
[
2
:
1
]
==
2'b10
)
;
// same thing for SSEL
reg
[
2
:
0
]
SSELr
;
always
@
(
posedge
clk
)
SSELr
<=
{
SSELr
[
1
:
0
]
,
SSEL
};
wire
SSEL_active
=
~
SSELr
[
1
]
;
// SSEL is active low
// message starts at falling edge and stops at rising edge
wire
SSEL_startmessage
=
(
SSELr
[
2
:
1
]
==
2'b10
)
;
wire
SSEL_endmessage
=
(
SSELr
[
2
:
1
]
==
2'b01
)
;
// and for MOSI
reg
[
1
:
0
]
MOSIr
;
always
@
(
posedge
clk
)
MOSIr
<=
{
MOSIr
[
0
]
,
MOSI
};
wire
MOSI_data
=
MOSIr
[
1
]
;
/* Now receiving data from the SPI bus is easy. */
reg
[
4
:
0
]
bitcnt
;
// 4 bits to count 16 bits
//reg byte_received; // high when a byte has been received
//reg [15:0] byte_data_received;
always
@
(
posedge
clk
)
begin
if
(
~
SSEL_active
)
bitcnt
<=
4'b0000
;
else
if
(
SCK_risingedge
)
begin
bitcnt
<=
bitcnt
+
4'b0001
;
// implement a shift-left register (since we receive the data MSB first)
byte_data_received
<=
{
byte_data_received
[
14
:
0
]
,
MOSI_data
};
end
end
always
@
(
posedge
clk
)
begin
byte_received
<=
SSEL_active
&&
SCK_risingedge
&&
(
bitcnt
==
4'b1111
)
;
end
/* Finally the transmission part. */
reg
[
15
:
0
]
byte_data_sent
;
//reg [15:0] cnt;
//always @(posedge clk) cnt <= 43690; /* test data to be sent out */
//always @(posedge clk) if (SSEL_startmessage) cnt<=cnt+8'h1; // count the messages
always
@
(
posedge
clk
)
if
(
SSEL_active
)
begin
if
(
SSEL_startmessage
)
byte_data_sent
<=
sendme
;
else
if
(
SCK_fallingedge
)
begin
if
(
bitcnt
==
4'b0000
)
byte_data_sent
<=
8'h0000
;
// after that, we send 0s
else
byte_data_sent
<=
{
byte_data_sent
[
14
:
0
]
,
1'b0
};
end
end
assign
MISO
=
byte_data_sent
[
15
]
;
// send MSB first
// we assume that there is only one slave on the SPI bus
// so we don't bother with a tri-state buffer for MISO
// otherwise we would need to tri-state MISO when SSEL is inactive
endmodule
/* vim: set sw=4 et: */
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