Hi everyone! I am trying to write a fsm, that sends 3 bytes to uart transmitter, so that transmitter can send it to PC. I did this task with one byte, however 3 bytes pose a difficult task for me.
here is my fsm code:
// fsm has 4 states. When 'reset' is high, fsm should transfer from IDLE state to state byte1. After that,
// check the 'busy' signal, that comes from uart tx. Busy is high when uart tx module is in the process of sending data/
// ready_2 signal is a signal, that tells uart tx to lock the incoming data
reset in my case is a signal from uart receiver, that asserts 1, when i send one byte from PC to to fpga via UART receiver. Basically, it is a signal, that tells us, that uart receiver finished receiving byte from pc.
if (!reset)
begin
state <= IDLE;
ready_2 <= 1'b0; // signal for UART transmitter to start sending data
data_store<= 1'b0; // register for 8-bit data
end
else
case (state)
IDLE: begin
if (reset)
state<=byte1;
else
state<=IDLE;
end
byte1: begin
ready_2<=1'b0;
if (~busy) begin
ready_2<=1'b1;
data_store<=8'b00110101;
state<=byte2;
end
else
state<=byte1;
end
byte2: begin
ready_2<=1'b0;
if (~busy) begin
ready_2<=1'b1;
data_store<=8'b10101010;
state<=byte3;
end
else
state<=byte2;
end
byte3: begin
ready_2<=1'b0;
if (~busy) begin
ready_2<=1'b1;
data_store<=8'b01110111;
state<=IDLE;
end
else
state<=byte3;
end
Question
salamus
Hi everyone! I am trying to write a fsm, that sends 3 bytes to uart transmitter, so that transmitter can send it to PC. I did this task with one byte, however 3 bytes pose a difficult task for me.
here is my fsm code:
// fsm has 4 states. When 'reset' is high, fsm should transfer from IDLE state to state byte1. After that,
// check the 'busy' signal, that comes from uart tx. Busy is high when uart tx module is in the process of sending data/
// ready_2 signal is a signal, that tells uart tx to lock the incoming data
reset in my case is a signal from uart receiver, that asserts 1, when i send one byte from PC to to fpga via UART receiver. Basically, it is a signal, that tells us, that uart receiver finished receiving byte from pc.
============================================================
always @(posedge clk)
begin
if (!reset)
begin
state <= IDLE;
ready_2 <= 1'b0; // signal for UART transmitter to start sending data
data_store<= 1'b0; // register for 8-bit data
end
else
case (state)
IDLE: begin
if (reset)
state<=byte1;
else
state<=IDLE;
end
byte1: begin
ready_2<=1'b0;
if (~busy) begin
ready_2<=1'b1;
data_store<=8'b00110101;
state<=byte2;
end
else
state<=byte1;
end
byte2: begin
ready_2<=1'b0;
if (~busy) begin
ready_2<=1'b1;
data_store<=8'b10101010;
state<=byte3;
end
else
state<=byte2;
end
byte3: begin
ready_2<=1'b0;
if (~busy) begin
ready_2<=1'b1;
data_store<=8'b01110111;
state<=IDLE;
end
else
state<=byte3;
end
endcase
end
==============================================================
Code for UART tx is taken from here https://nandland.com/uart-serial-port-module/ and works just fine.
Can anyone, please, tell me, what am i doing wrong with fsm? I tried various methods, but the best i accomplished was to send one first byte
Link to comment
Share on other sites
5 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now