-
Notifications
You must be signed in to change notification settings - Fork 5
/
spi.txt
66 lines (52 loc) · 4.74 KB
/
spi.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
CLK25 \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/∫ ∫\/\/\/\/\/\/\/\/\/\/∫ ∫\/\/\/\/\/\/\/\/\/\/\/\
🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑
CPU ⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\∫ ∫_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\∫ ∫_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
CS ⎺⎺⎺⎺⎺\____________________________________∫ ∫____________________∫ ∫_______________/⎺⎺⎺⎺⎺⎺⎺
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
SCLK ⎺⎺⎺⎺⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\_/⎺\∫ ∫_/⎺\_/⎺⎺⎺⎺⎺\_/⎺\_/⎺\∫ ∫_/⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
MOSI ⎺⎺⎺⎺⎺{ 7}{ 6}{ 5}{ 4}{ 3}{ 2}{ 1}{ 0}{ 7}{∫ ∫ 1}{ 0}----{ 7}{ 6}{∫ ∫ 0}------------'⎺⎺⎺⎺⎺⎺⎺
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
MISO ⎺⎺⎺⎺⎺--7---6---5---4---3---2---1---0------∫ ∫--------------------∫ ∫---------------'⎺⎺⎺⎺⎺⎺⎺
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
SPI_W ---X-----------X--------------------------∫ ∫---------X----------∫ ∫-----------------------
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
tx_data ...W...........W..........................∫ ∫.........W..........∫ ∫.......................
tx_hold ___/⎺\_________/⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺\____∫ ∫_________/⎺\________∫ ∫_______________________
tx_shfit .....W...............................W....∫ ∫...........W........∫ ∫.......................
tx_bit .....7...6...5...4...3...2...1...0...7...6∫ ∫1..0...0...7...6...5∫ ∫0......................
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
SPI_R ------------------------------------------∫ ∫-----------------X--∫ ∫----------X------------
rx_shfit .......1...2...3...4...5...6...7...8...1..∫ ∫.7...8.......1...2..∫ ∫.8.....................
rx_data ...................................X......∫ ∫.......O............∫ ∫...X...................
rx_valid ___________________________________/⎺⎺⎺⎺⎺⎺∫ ∫⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺\__∫ ∫___/⎺⎺⎺⎺⎺⎺\____________
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
SPI_A .................................................................................X.........
⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙ ⦙
🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑 🡓 🡑
tx_clk * _____/⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺∫ ∫⎺⎺⎺⎺⎺⎺⎺\___/⎺⎺⎺⎺⎺⎺⎺⎺∫ ∫⎺⎺⎺\___________________
*: not needed
always:
MOSI = tx_sft(7)
posedge CLK25:
if (SCLK == 0)
rx_shift <= {rx_shift[6:0], MISO}
SCLK <= 1
if( tx_bit == 0 )
rx_data <= {rx_shift[6:0], MISO}
rx_valid <= 1
else // SCLK == 1
if ( tx_hold )
CS <= 0
if ( tx_hold || (tx_bit != 0) )
SCLK <= 0
if ( tx_bit == 0 )
tx_hold <= 0
tx_shift <= tx_data
tx_bit <= 7
else
tx_bit <= tx_bit - 1
tx_shit <= {tx_shift[6:0], 0}