SPI接口的verilog实现 项目中使用的许多器件需要SPI接口进行配置,比如PLL:ADF4350,AD:AD9627,VGA:AD8372等,根据SPI协议,站长编写了一个简单的SPI读写程序,可以进行32为数据的读写(读者可以修改程序中数字使其变成16位或8位读写,也可以将读写位数参数化),可以设置SPI SCLK相对于主时钟的分频比。
【SPI程序】
/* SPI interface module V1.0 一些语句做了简单的英文注释*/
module spi_master(addr, in_data, out_data, rd, wr, cs, clk, miso, mosi, sclk); input wire [1:0] addr;
input wire [31:0] in_data;
output reg [31:0] out_data;
input wire rd;
input wire wr;
input wire cs;
input wire clk;
inout miso;
inout mosi;
inout sclk;
reg sclk_buffer = 0;
reg mosi_buffer = 0;
reg busy = 0;
reg [31:0] in_buffer = 0;
reg [31:0] out_buffer = 0;
reg [7:0] clkcount = 0;
reg [7:0] clkdiv = 0;
reg [6:0] count = 0;
always@(cs or rd or addr or out_buffer or busy or clkdiv)
begin
out_data = 32'bx;
if(cs && rd)//selected and read
begin
case(addr)
2'b00:
begin
out_data = out_buffer;
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余3页未读,立即下载
- 1
- 2
- 3
- 4
- 5
前往页