I am trying to send data from Nexys 4 Artix 7 FPGA Board to PC. I using uart to send the data at 9600 baud rate. The uart takes data through the switch and I am using SW(0 to 7) for this. The data transfer takes place only when button is press(btnU). I wanted to make this transfer automatic without having the need to use the button but have not been able to get it done. I have taken the code from http://www.instructables.com/id/UART-Communication-on-Basys-3-FPGA-Dev-Board-Power/?ALLSTEPS. I have made some change to replace the btnU with "State" to initiate the the data transfer. For this purpose i have written a module where the input State determines whether to initiate the uart just like the btnU. The modules transmit and transmitter are sub-modules to the XADC module.
Please find my code below:
module transmit
(
input clk, //clock signal
input State,
output reg transmit //transmit signal
);
always @(posedge clk) begin
if (State == 1)
transmit <= 1;
else
transmit <= 0;
end
endmodule
//UART transmission logic
always @ (posedge clk)
begin
counter <= counter + 1;
if (counter >= 10415)
begin
state <= nextstate;
counter <=0;
if (load) rightshiftreg <= {1'b1,data,1'b0};
if (clear) bitcounter <=0;
if (shift)
begin
rightshiftreg <= rightshiftreg >> 1;
bitcounter <= bitcounter + 1;
end
end
end
//state machine
always @ (posedge clk)
//always @ (state or bitcounter or transmit)
begin
load <=0;
shift <=0;
clear <=0;
TxD <=1;
case (state)
0: begin
if (transmit) begin
nextstate <= 1;
load <=1;
shift <=0;
clear <=0;
end
else begin
nextstate <= 0;
TxD <= 1;
end
end
1: begin // transmit state
if (bitcounter >=10) begin // check if transmission is complete or not. If complete
nextstate <= 0; // set nextstate back to 0 to idle state
clear <=1; // set clear to 1 to clear all counters
end
else begin
nextstate <= 1; // set nextstate to 1 to stay in transmit state
TxD <= rightshiftreg[0]; // shift the bit to output TxD
shift <=1; // set shift to 1 to continue shifting the data
end
end
default: nextstate <= 0;
endcase
end
The problem is that i have not been able to implement this without making use of button to initiate the data transfer. Without the use of button the communication between Nexys 4 Board and PC doesn't take place. I can only see the RX Led blinking on FPGA board but not the data on teraterm. Could you please help me to find the solution to this issue?
Question
Manas
Hi
I am trying to send data from Nexys 4 Artix 7 FPGA Board to PC. I using uart to send the data at 9600 baud rate. The uart takes data through the switch and I am using SW(0 to 7) for this. The data transfer takes place only when button is press(btnU). I wanted to make this transfer automatic without having the need to use the button but have not been able to get it done. I have taken the code from http://www.instructables.com/id/UART-Communication-on-Basys-3-FPGA-Dev-Board-Power/?ALLSTEPS. I have made some change to replace the btnU with "State" to initiate the the data transfer. For this purpose i have written a module where the input State determines whether to initiate the uart just like the btnU. The modules transmit and transmitter are sub-modules to the XADC module.
Please find my code below:
module transmit
(
input clk, //clock signal
input State,
output reg transmit //transmit signal
);
always @(posedge clk) begin
if (State == 1)
transmit <= 1;
else
transmit <= 0;
end
endmodule
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
module transmitter(
input clk,
input transmit,
input [7:0] data,
output reg TxD
);
//internal variables
reg [3:0] bitcounter;
reg [13:0] counter;
reg state,nextstate;
reg [9:0] rightshiftreg;
reg shift;
reg load;
reg clear;
//UART transmission logic
always @ (posedge clk)
begin
counter <= counter + 1;
if (counter >= 10415)
begin
state <= nextstate;
counter <=0;
if (load) rightshiftreg <= {1'b1,data,1'b0};
if (clear) bitcounter <=0;
if (shift)
begin
rightshiftreg <= rightshiftreg >> 1;
bitcounter <= bitcounter + 1;
end
end
end
//state machine
always @ (posedge clk)
//always @ (state or bitcounter or transmit)
begin
load <=0;
shift <=0;
clear <=0;
TxD <=1;
case (state)
0: begin
if (transmit) begin
nextstate <= 1;
load <=1;
shift <=0;
clear <=0;
end
else begin
nextstate <= 0;
TxD <= 1;
end
end
1: begin // transmit state
if (bitcounter >=10) begin // check if transmission is complete or not. If complete
nextstate <= 0; // set nextstate back to 0 to idle state
clear <=1; // set clear to 1 to clear all counters
end
else begin
nextstate <= 1; // set nextstate to 1 to stay in transmit state
TxD <= rightshiftreg[0]; // shift the bit to output TxD
shift <=1; // set shift to 1 to continue shifting the data
end
end
default: nextstate <= 0;
endcase
end
endmodule
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The problem is that i have not been able to implement this without making use of button to initiate the data transfer. Without the use of button the communication between Nexys 4 Board and PC doesn't take place. I can only see the RX Led blinking on FPGA board but not the data on teraterm. Could you please help me to find the solution to this issue?
Regards
Manas
Link to comment
Share on other sites
11 answers to this question
Recommended Posts
Archived
This topic is now archived and is closed to further replies.