28 lines
855 B
Verilog
28 lines
855 B
Verilog
// Simple test of the UART pins and clock, no CPU needed
|
|
|
|
module top(input clk, output ser_tx, input ser_rx);
|
|
//assign ser_tx = test_chars; // uncomment for a bunch of ASCII "U" characters
|
|
assign ser_tx = ser_rx; // uncomment first for serial echo
|
|
|
|
wire serclk;
|
|
reg test_chars;
|
|
|
|
clkdiv clock_generator (clk, serclk);
|
|
|
|
always @(posedge serclk) begin
|
|
test_chars = !test_chars;
|
|
end
|
|
endmodule
|
|
|
|
module clkdiv(input clock_in, output reg clock_out);
|
|
reg[15:0] counter=16'd0;
|
|
parameter DIVISOR = 16'd104; //set according to desired baudrate for test characters (e.g. 12,000,000 Hz / 115200 baud ~= clock divider 104)
|
|
|
|
always @(posedge clock_in) begin
|
|
counter <= counter + 16'd1;
|
|
if(counter>=(DIVISOR-1))
|
|
counter <= 16'd0;
|
|
|
|
clock_out <= (counter<DIVISOR/2)?1'b1:1'b0;
|
|
end
|
|
endmodule |