2022-07-21 02:37:22 -04:00
|
|
|
/* (c) Peter McGoron 2022
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v.2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
module spi_write_read
|
|
|
|
#(
|
|
|
|
parameter POLARITY = 0,
|
|
|
|
parameter PHASE = 0
|
|
|
|
)
|
2022-07-20 19:41:54 -04:00
|
|
|
(
|
|
|
|
input clk,
|
|
|
|
input [23:0] data_ctrl,
|
|
|
|
input activate,
|
|
|
|
input ss,
|
2022-07-21 01:53:38 -04:00
|
|
|
input rdy,
|
2022-07-21 02:37:22 -04:00
|
|
|
output master_finished
|
2022-07-20 19:41:54 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
wire miso;
|
|
|
|
wire mosi;
|
|
|
|
wire sck;
|
|
|
|
wire ss_L = !ss;
|
|
|
|
|
|
|
|
reg [23:0] from_slave_data;
|
2022-07-21 02:37:22 -04:00
|
|
|
reg slave_finished;
|
|
|
|
reg slave_error;
|
2022-07-20 19:41:54 -04:00
|
|
|
|
2022-07-21 03:01:58 -04:00
|
|
|
spi_master
|
|
|
|
#(
|
|
|
|
.POLARITY(POLARITY),
|
|
|
|
.PHASE(PHASE)
|
|
|
|
) master (
|
2022-07-20 19:41:54 -04:00
|
|
|
.clk(clk),
|
|
|
|
.to_slave(data_ctrl),
|
|
|
|
.from_slave(from_slave_data),
|
|
|
|
.miso(miso),
|
|
|
|
.mosi(mosi),
|
|
|
|
.sck_wire(sck),
|
|
|
|
.finished(master_finished),
|
|
|
|
.arm(activate)
|
|
|
|
);
|
|
|
|
|
|
|
|
reg [23:0] data_from_master;
|
|
|
|
reg [23:0] data_to_master = 24'b111011011100010101010101;
|
|
|
|
|
2022-07-21 03:01:58 -04:00
|
|
|
spi_slave #(
|
|
|
|
.POLARITY(POLARITY),
|
|
|
|
.PHASE(PHASE)
|
|
|
|
) slave (
|
2022-07-20 19:41:54 -04:00
|
|
|
.clk(clk),
|
|
|
|
.sck(sck),
|
|
|
|
.ss_L(ss_L),
|
|
|
|
.from_master(data_from_master),
|
|
|
|
.to_master(data_to_master),
|
|
|
|
.mosi(mosi),
|
|
|
|
.miso(miso),
|
|
|
|
.finished(slave_finished),
|
2022-07-21 01:53:38 -04:00
|
|
|
.rdy(rdy),
|
2022-07-20 19:41:54 -04:00
|
|
|
.err(slave_error)
|
|
|
|
);
|
|
|
|
|
|
|
|
always @ (posedge clk) begin
|
|
|
|
if (slave_finished) begin
|
|
|
|
data_to_master <= data_from_master;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
endmodule
|